Add a window options demo
This commit is contained in:
parent
25b8a8ebfd
commit
cbe0de83ee
3 changed files with 77 additions and 2 deletions
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
73
egui_demo_lib/src/apps/demo/window_options.rs
Normal file
73
egui_demo_lib/src/apps/demo/window_options.rs
Normal file
|
@ -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!());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue