diff --git a/egui_demo_lib/src/apps/demo/demo_windows.rs b/egui_demo_lib/src/apps/demo/demo_windows.rs index c1f0f79df..33bcf0f33 100644 --- a/egui_demo_lib/src/apps/demo/demo_windows.rs +++ b/egui_demo_lib/src/apps/demo/demo_windows.rs @@ -18,6 +18,7 @@ impl Default for Demos { (false, Box::new(super::DancingStrings::default())), (false, Box::new(super::DragAndDropDemo::default())), (false, Box::new(super::Tests::default())), + (false, Box::new(super::WindowOptions::default())), ], } } @@ -54,7 +55,7 @@ impl DemoWindows { /// Show the app ui (menu bar and windows). /// `sidebar_ui` can be used to optionally show some things in the sidebar pub fn ui(&mut self, ctx: &CtxRef) { - egui::SidePanel::left("side_panel", 190.0).show(ctx, |ui| { + egui::SidePanel::left("side_panel", 200.0).show(ctx, |ui| { ui.heading("✒ Egui Demo"); ui.separator(); diff --git a/egui_demo_lib/src/apps/demo/mod.rs b/egui_demo_lib/src/apps/demo/mod.rs index 4045a3d05..60466886a 100644 --- a/egui_demo_lib/src/apps/demo/mod.rs +++ b/egui_demo_lib/src/apps/demo/mod.rs @@ -18,11 +18,12 @@ mod sliders; mod tests; pub mod toggle_switch; mod widgets; +mod window_options; pub use { app::*, dancing_strings::DancingStrings, demo_window::DemoWindow, demo_windows::*, drag_and_drop::*, font_book::FontBook, painting::Painting, scrolls::Scrolls, sliders::Sliders, - tests::Tests, widgets::Widgets, + tests::Tests, widgets::Widgets, window_options::WindowOptions, }; // ---------------------------------------------------------------------------- diff --git a/egui_demo_lib/src/apps/demo/window_options.rs b/egui_demo_lib/src/apps/demo/window_options.rs new file mode 100644 index 000000000..b33d2efe4 --- /dev/null +++ b/egui_demo_lib/src/apps/demo/window_options.rs @@ -0,0 +1,73 @@ +use crate::__egui_github_link_file; + +#[derive(Clone, PartialEq, serde::Deserialize, serde::Serialize)] +pub struct WindowOptions { + title: String, + title_bar: bool, + collapsible: bool, + resizable: bool, + scroll: bool, +} + +impl Default for WindowOptions { + fn default() -> Self { + Self { + title: "🗖 Window Options".to_owned(), + title_bar: true, + collapsible: true, + resizable: true, + scroll: false, + } + } +} + +impl super::Demo for WindowOptions { + fn name(&self) -> &str { + // "🗖 Window Options" + &self.title + } + + fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) { + let Self { + title, + title_bar, + collapsible, + resizable, + scroll, + } = self.clone(); + + use super::View; + egui::Window::new(title) + .id(egui::Id::new("demo_window_options")) // required since we change the title + .open(open) + .resizable(resizable) + .collapsible(collapsible) + .title_bar(title_bar) + .scroll(scroll) + .show(ctx, |ui| self.ui(ui)); + } +} + +impl super::View for WindowOptions { + fn ui(&mut self, ui: &mut egui::Ui) { + egui::reset_button(ui, self); + + let Self { + title, + title_bar, + collapsible, + resizable, + scroll, + } = self; + + ui.horizontal(|ui| { + ui.label("title:"); + ui.text_edit_singleline(title); + }); + ui.checkbox(title_bar, "title_bar"); + ui.checkbox(collapsible, "collapsible"); + ui.checkbox(resizable, "resizable"); + ui.checkbox(scroll, "scroll"); + ui.add(__egui_github_link_file!()); + } +}