diff --git a/src/gui_egui/gui.rs b/src/gui_egui/gui.rs index 4ce9315..6055cc5 100644 --- a/src/gui_egui/gui.rs +++ b/src/gui_egui/gui.rs @@ -2,6 +2,7 @@ use crate::common::{ComponentStore, Components, Simulator}; use crate::gui_egui::editor::EditorMode; use crate::gui_egui::{ editor::{Editor, Library}, + gui_options::GuiOptions, keymap, keymap::Shortcuts, menu::Menu, @@ -34,6 +35,8 @@ pub struct Gui { pub in_built_models: Vec<(String, String)>, pub contexts: HashMap, pub library: Library, + + pub gui_options: GuiOptions, } #[derive(Clone, Debug)] @@ -67,18 +70,23 @@ pub fn gui(cs: ComponentStore, path: &PathBuf, library: Library) -> Result<(), e contexts, library, in_built_models: Vec::default(), + gui_options: GuiOptions::default(), }; eframe::run_native("SyncRim", options, Box::new(|_cc| Ok(Box::new(gui)))) } impl Gui { - pub fn new(cs: ComponentStore, path: &PathBuf, library: Library) -> Result> { + pub fn new( + cs: ComponentStore, + path: &PathBuf, + library: Library, + ) -> Result> { let contexts = create_contexts(&cs.store); let simulator = Simulator::new(cs)?; let path = path.to_owned(); // simulator.save_dot(&path); - + Ok(Gui { path, simulator: Some(simulator), @@ -95,6 +103,7 @@ impl Gui { contexts, library, in_built_models: Vec::default(), + gui_options: GuiOptions::default(), }) } @@ -116,6 +125,9 @@ impl Gui { impl eframe::App for Gui { fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) { self.shortcuts.inputs(ctx, self); + if self.gui_options.window_visible { + self.gui_options.render(ctx); + } if self.editor_use { crate::gui_egui::editor::Editor::update(ctx, frame, self); return; diff --git a/src/gui_egui/gui_options.rs b/src/gui_egui/gui_options.rs new file mode 100644 index 0000000..37e2373 --- /dev/null +++ b/src/gui_egui/gui_options.rs @@ -0,0 +1,44 @@ +use egui::{ViewportBuilder, ViewportId, Pos2}; + +#[derive(Clone, Debug)] +pub struct GuiOptions { + // This is added/subtracted to/from the view scale when zoomed. + pub view_scaling_val: f32, + pub window_visible: bool, +} + +impl Default for GuiOptions { + fn default() -> GuiOptions { + GuiOptions { + view_scaling_val: 0.03, + window_visible: false, + } + } +} + + +impl GuiOptions { + // Naming would make more sense if it was a GuiOptionsWindow being rendered, then again i see + // no point in adding more structs for the sake of naming (maybe the point will become apparent + // down the line). + pub fn render(&mut self, ctx: &egui::Context) { + ctx.show_viewport_immediate( + ViewportId::from_hash_of("Preferences"), + ViewportBuilder { + title: Some("Preferences".to_string()), + position: Some(Pos2::new(ctx.screen_rect().max.x/2.0, ctx.screen_rect().max.y/2.0)), + inner_size: Some((500.0, 200.0).into()), + ..ViewportBuilder::default() + }, + |ctx, _class| { + if ctx.input(|i| i.viewport().close_requested()) { + self.window_visible = false + } + egui::CentralPanel::default().show(ctx, |ui| { + ui.label("Zoom Scaling"); + let response = ui.add(egui::Slider::new(&mut self.view_scaling_val, 0.0..=0.1)); + response.on_hover_text("Adjusts the step size by which zooming zooms."); + }); + }); + } +} diff --git a/src/gui_egui/keymap.rs b/src/gui_egui/keymap.rs index e2b44a7..6d4c340 100644 --- a/src/gui_egui/keymap.rs +++ b/src/gui_egui/keymap.rs @@ -364,7 +364,10 @@ pub fn file_editor_toggle_fn(gui: &mut Gui) { } } } -pub fn file_preferences_fn(_gui: &mut Gui) {} + +pub fn file_preferences_fn(gui: &mut Gui) { + gui.gui_options.window_visible = true; +} pub fn file_quit_fn(_gui: &mut Gui) {} pub fn edit_cut_fn(_gui: &mut Gui) {} pub fn edit_copy_fn(_gui: &mut Gui) {} @@ -374,13 +377,8 @@ pub fn view_zoom_in_fn(gui: &mut Gui) { true => &mut gui.editor.as_mut().unwrap().scale, false => &mut gui.scale, }; - match *scale { - x if (0.0f32..0.2f32).contains(&x) => *scale = 0.25f32, - x if (0.2f32..0.4f32).contains(&x) => *scale = 0.5f32, - x if (0.4f32..0.6f32).contains(&x) => *scale = 1f32, - x if (0.9f32..1.1f32).contains(&x) => *scale = 1.5f32, - x if (1.4f32..1.6f32).contains(&x) => *scale = 2f32, - _ => *scale = 2f32, + if *scale < 2f32 { + *scale += gui.gui_options.view_scaling_val; } } pub fn view_zoom_out_fn(gui: &mut Gui) { @@ -388,13 +386,8 @@ pub fn view_zoom_out_fn(gui: &mut Gui) { true => &mut gui.editor.as_mut().unwrap().scale, false => &mut gui.scale, }; - match *scale { - x if (0.2f32..0.4f32).contains(&x) => *scale = 0.1f32, - x if (0.4f32..0.6f32).contains(&x) => *scale = 0.25f32, - x if (0.9f32..1.1f32).contains(&x) => *scale = 0.5f32, - x if (1.4f32..1.6f32).contains(&x) => *scale = 1f32, - x if (1.9f32..2.1f32).contains(&x) => *scale = 1.5f32, - _ => *scale = 0.1f32, + if *scale > 0.1 { + *scale -= gui.gui_options.view_scaling_val; } } pub fn view_grid_toggle_fn(gui: &mut Gui) { diff --git a/src/gui_egui/mod.rs b/src/gui_egui/mod.rs index 0d59050..2c855ff 100644 --- a/src/gui_egui/mod.rs +++ b/src/gui_egui/mod.rs @@ -6,7 +6,7 @@ pub mod helper; mod keymap; mod library; mod menu; - +mod gui_options; #[cfg(feature = "components")] pub mod components;