Skip to content

Commit

Permalink
Save settings button (#187)
Browse files Browse the repository at this point in the history
* Show warning in images ui when invalid settings
  • Loading branch information
PhilipK authored Jul 18, 2022
1 parent 4c6c92d commit 6f1ffdf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Binary file added resources/save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/ui/defines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ pub mod ui_images {
use egui::{ColorImage, ImageData};

pub const IMPORT_GAMES_IMAGE: &[u8] = include_bytes!("../../resources/import_games_button.png");
pub const SAVE_IMAGE: &[u8] = include_bytes!("../../resources/save.png");
pub const LOGO_32: &[u8] = include_bytes!("../../resources/logo32.png");
pub const LOGO_ICON: &[u8] = include_bytes!("../../resources/logo_small.png");

pub fn get_import_image() -> ImageData {
ImageData::Color(load_image_from_memory(IMPORT_GAMES_IMAGE).unwrap())
}

pub fn get_save_image() -> ImageData {
ImageData::Color(load_image_from_memory(SAVE_IMAGE).unwrap())
}

pub fn get_logo() -> ImageData {
ImageData::Color(load_image_from_memory(LOGO_32).unwrap())
}
Expand Down
26 changes: 24 additions & 2 deletions src/ui/uiapp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env::Args, error::Error};

use eframe::{egui, App, Frame};
use egui::{ImageButton, Rounding, Stroke, TextureHandle};
use egui::{Button, ImageButton, Rounding, Stroke, TextureHandle};
use steam_shortcuts_util::shortcut::ShortcutOwned;
use tokio::{
runtime::Runtime,
Expand All @@ -20,7 +20,7 @@ use super::{
BACKGROUND_COLOR, BG_STROKE_COLOR, EXTRA_BACKGROUND_COLOR, LIGHT_ORANGE, ORANGE, PURLPLE,
TEXT_COLOR,
},
ui_images::{get_import_image, get_logo, get_logo_icon},
ui_images::{get_import_image, get_logo, get_logo_icon, get_save_image},
ui_import_games::FetcStatus,
BackupState, DiconnectState, ImageSelectState,
};
Expand All @@ -30,6 +30,7 @@ const SECTION_SPACING: f32 = 25.0;
#[derive(Default)]
struct UiImages {
import_button: Option<egui::TextureHandle>,
save_button: Option<egui::TextureHandle>,
logo_32: Option<egui::TextureHandle>,
}

Expand Down Expand Up @@ -127,6 +128,20 @@ impl App for MyEguiApp {
self.games_to_sync = watch::channel(FetcStatus::NeedsFetched).1;
}
});

if self.selected_menu == Menues::Settings {
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "Bottom Panel")
.frame(frame)
.show(ctx, |ui| {
let texture = self.get_save_image(ui);
let size = texture.size_vec2();
let save_button = ImageButton::new(texture, size * 0.5);

if ui.add(save_button).on_hover_text("Save settings").clicked() {
MyEguiApp::save_settings_to_file(&self.settings.clone());
}
});
}
if self.games_to_sync.borrow().is_some() {
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "Bottom Panel")
.frame(frame)
Expand Down Expand Up @@ -232,6 +247,13 @@ impl MyEguiApp {
})
}

fn get_save_image(&mut self, ui: &mut egui::Ui) -> &mut TextureHandle {
self.ui_images.save_button.get_or_insert_with(|| {
// Load the texture only once.
ui.ctx().load_texture("save_image", get_save_image())
})
}

fn get_logo_image(&mut self, ui: &mut egui::Ui) -> &mut TextureHandle {
self.ui_images.logo_32.get_or_insert_with(|| {
// Load the texture only once.
Expand Down

0 comments on commit 6f1ffdf

Please sign in to comment.