Skip to content

Commit b63d488

Browse files
committed
move gui options somewhere more reasonable
1 parent 938f984 commit b63d488

3 files changed

Lines changed: 52 additions & 46 deletions

File tree

src/gui_egui/gui.rs

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::common::{ComponentStore, Components, Simulator};
22
use crate::gui_egui::editor::EditorMode;
33
use crate::gui_egui::{
44
editor::{Editor, Library},
5+
gui_options::GuiOptions,
56
keymap,
67
keymap::Shortcuts,
78
menu::Menu,
@@ -38,22 +39,6 @@ pub struct Gui {
3839
pub gui_options: GuiOptions,
3940
}
4041

41-
#[derive(Clone, Debug)]
42-
pub struct GuiOptions {
43-
// This is added/subtracted to/from the view scale when zoomed.
44-
pub view_scaling_val: f32,
45-
pub window_visible: bool,
46-
}
47-
48-
impl Default for GuiOptions {
49-
fn default() -> GuiOptions {
50-
GuiOptions {
51-
view_scaling_val: 0.03,
52-
window_visible: false,
53-
}
54-
}
55-
}
56-
5742
#[derive(Clone, Debug)]
5843
pub struct EguiExtra {
5944
pub properties_window: bool,
@@ -92,12 +77,16 @@ pub fn gui(cs: ComponentStore, path: &PathBuf, library: Library) -> Result<(), e
9277
}
9378

9479
impl Gui {
95-
pub fn new(cs: ComponentStore, path: &PathBuf, library: Library) -> Result<Self, Box<dyn Error>> {
80+
pub fn new(
81+
cs: ComponentStore,
82+
path: &PathBuf,
83+
library: Library,
84+
) -> Result<Self, Box<dyn Error>> {
9685
let contexts = create_contexts(&cs.store);
9786
let simulator = Simulator::new(cs)?;
9887
let path = path.to_owned();
9988
// simulator.save_dot(&path);
100-
89+
10190
Ok(Gui {
10291
path,
10392
simulator: Some(simulator),
@@ -256,30 +245,3 @@ pub fn create_contexts(components: &Components) -> HashMap<crate::common::Id, Eg
256245
}
257246
contexts
258247
}
259-
260-
261-
use egui::{ViewportBuilder, ViewportId};
262-
/// This should be somewhere else but put it here for experiments
263-
// It makes more sense to have a GuiOptionsWindow having render but let's see how this works
264-
impl GuiOptions {
265-
pub fn render(&mut self, ctx: &egui::Context) {
266-
ctx.show_viewport_immediate(
267-
ViewportId::from_hash_of("Preferences"),
268-
ViewportBuilder {
269-
title: Some("Preferences".to_string()),
270-
position: Some(Pos2::new(ctx.screen_rect().max.x/2.0, ctx.screen_rect().max.y/2.0)),
271-
inner_size: Some((500.0, 200.0).into()),
272-
..ViewportBuilder::default()
273-
},
274-
|ctx, _class| {
275-
if ctx.input(|i| i.viewport().close_requested()) {
276-
self.window_visible = false
277-
}
278-
egui::CentralPanel::default().show(ctx, |ui| {
279-
ui.label("Zoom Scaling");
280-
let response = ui.add(egui::Slider::new(&mut self.view_scaling_val, 0.0..=0.1));
281-
response.on_hover_text("Adjusts the step size by which zooming zooms.");
282-
});
283-
});
284-
}
285-
}

src/gui_egui/gui_options.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use egui::{ViewportBuilder, ViewportId, Pos2};
2+
3+
#[derive(Clone, Debug)]
4+
pub struct GuiOptions {
5+
// This is added/subtracted to/from the view scale when zoomed.
6+
pub view_scaling_val: f32,
7+
pub window_visible: bool,
8+
}
9+
10+
impl Default for GuiOptions {
11+
fn default() -> GuiOptions {
12+
GuiOptions {
13+
view_scaling_val: 0.03,
14+
window_visible: false,
15+
}
16+
}
17+
}
18+
19+
20+
impl GuiOptions {
21+
// Naming would make more sense if it was a GuiOptionsWindow being rendered, then again i see
22+
// no point in adding more structs for the sake of naming (maybe the point will become apparent
23+
// down the line).
24+
pub fn render(&mut self, ctx: &egui::Context) {
25+
ctx.show_viewport_immediate(
26+
ViewportId::from_hash_of("Preferences"),
27+
ViewportBuilder {
28+
title: Some("Preferences".to_string()),
29+
position: Some(Pos2::new(ctx.screen_rect().max.x/2.0, ctx.screen_rect().max.y/2.0)),
30+
inner_size: Some((500.0, 200.0).into()),
31+
..ViewportBuilder::default()
32+
},
33+
|ctx, _class| {
34+
if ctx.input(|i| i.viewport().close_requested()) {
35+
self.window_visible = false
36+
}
37+
egui::CentralPanel::default().show(ctx, |ui| {
38+
ui.label("Zoom Scaling");
39+
let response = ui.add(egui::Slider::new(&mut self.view_scaling_val, 0.0..=0.1));
40+
response.on_hover_text("Adjusts the step size by which zooming zooms.");
41+
});
42+
});
43+
}
44+
}

src/gui_egui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod helper;
66
mod keymap;
77
mod library;
88
mod menu;
9-
9+
mod gui_options;
1010
#[cfg(feature = "components")]
1111
pub mod components;
1212

0 commit comments

Comments
 (0)