2021-01-04 00:44:02 +00:00
|
|
|
#[derive(Clone, PartialEq)]
|
2021-09-29 06:45:13 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
2021-01-02 23:12:54 +00:00
|
|
|
pub struct WindowOptions {
|
|
|
|
title: String,
|
|
|
|
title_bar: bool,
|
2021-01-10 09:41:46 +00:00
|
|
|
closable: bool,
|
2021-01-02 23:12:54 +00:00
|
|
|
collapsible: bool,
|
|
|
|
resizable: bool,
|
2021-08-28 11:18:21 +00:00
|
|
|
scroll2: [bool; 2],
|
2021-02-07 09:55:45 +00:00
|
|
|
disabled_time: f64,
|
2021-04-18 08:01:41 +00:00
|
|
|
|
|
|
|
anchored: bool,
|
|
|
|
anchor: egui::Align2,
|
|
|
|
anchor_offset: egui::Vec2,
|
2021-01-02 23:12:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for WindowOptions {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
title: "🗖 Window Options".to_owned(),
|
|
|
|
title_bar: true,
|
2021-01-10 09:41:46 +00:00
|
|
|
closable: true,
|
2021-01-02 23:12:54 +00:00
|
|
|
collapsible: true,
|
2021-08-28 11:18:21 +00:00
|
|
|
resizable: true,
|
|
|
|
scroll2: [true; 2],
|
2021-02-07 09:55:45 +00:00
|
|
|
disabled_time: f64::NEG_INFINITY,
|
2021-04-18 08:01:41 +00:00
|
|
|
anchored: false,
|
|
|
|
anchor: egui::Align2::RIGHT_TOP,
|
|
|
|
anchor_offset: egui::Vec2::ZERO,
|
2021-01-02 23:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::Demo for WindowOptions {
|
2021-02-20 08:18:23 +00:00
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"🗖 Window Options"
|
2021-01-02 23:12:54 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
|
2021-01-02 23:12:54 +00:00
|
|
|
let Self {
|
|
|
|
title,
|
|
|
|
title_bar,
|
2021-01-10 09:41:46 +00:00
|
|
|
closable,
|
2021-01-02 23:12:54 +00:00
|
|
|
collapsible,
|
|
|
|
resizable,
|
2021-08-28 11:18:21 +00:00
|
|
|
scroll2,
|
2021-02-07 09:55:45 +00:00
|
|
|
disabled_time,
|
2021-04-18 08:01:41 +00:00
|
|
|
anchored,
|
|
|
|
anchor,
|
|
|
|
anchor_offset,
|
2021-01-02 23:12:54 +00:00
|
|
|
} = self.clone();
|
|
|
|
|
2021-02-07 09:55:45 +00:00
|
|
|
let enabled = ctx.input().time - disabled_time > 2.0;
|
|
|
|
if !enabled {
|
|
|
|
ctx.request_repaint();
|
|
|
|
}
|
|
|
|
|
2021-10-07 19:39:04 +00:00
|
|
|
use super::View as _;
|
2021-01-10 09:41:46 +00:00
|
|
|
let mut window = egui::Window::new(title)
|
2021-01-02 23:12:54 +00:00
|
|
|
.id(egui::Id::new("demo_window_options")) // required since we change the title
|
|
|
|
.resizable(resizable)
|
|
|
|
.collapsible(collapsible)
|
|
|
|
.title_bar(title_bar)
|
2021-08-28 11:18:21 +00:00
|
|
|
.scroll2(scroll2)
|
2021-02-07 09:55:45 +00:00
|
|
|
.enabled(enabled);
|
2021-01-10 09:41:46 +00:00
|
|
|
if closable {
|
|
|
|
window = window.open(open);
|
|
|
|
}
|
2021-04-18 08:01:41 +00:00
|
|
|
if anchored {
|
|
|
|
window = window.anchor(anchor, anchor_offset);
|
|
|
|
}
|
2021-01-10 09:41:46 +00:00
|
|
|
window.show(ctx, |ui| self.ui(ui));
|
2021-01-02 23:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl super::View for WindowOptions {
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
|
|
|
let Self {
|
|
|
|
title,
|
|
|
|
title_bar,
|
2021-01-10 09:41:46 +00:00
|
|
|
closable,
|
2021-01-02 23:12:54 +00:00
|
|
|
collapsible,
|
|
|
|
resizable,
|
2021-08-28 11:18:21 +00:00
|
|
|
scroll2,
|
2021-08-23 19:28:06 +00:00
|
|
|
disabled_time: _,
|
2021-04-18 08:01:41 +00:00
|
|
|
anchored,
|
|
|
|
anchor,
|
|
|
|
anchor_offset,
|
2021-01-02 23:12:54 +00:00
|
|
|
} = self;
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.label("title:");
|
|
|
|
ui.text_edit_singleline(title);
|
|
|
|
});
|
2021-02-07 09:55:45 +00:00
|
|
|
|
2021-08-23 19:28:06 +00:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.group(|ui| {
|
|
|
|
ui.vertical(|ui| {
|
|
|
|
ui.checkbox(title_bar, "title_bar");
|
|
|
|
ui.checkbox(closable, "closable");
|
|
|
|
ui.checkbox(collapsible, "collapsible");
|
|
|
|
ui.checkbox(resizable, "resizable");
|
2021-08-28 11:18:21 +00:00
|
|
|
ui.checkbox(&mut scroll2[0], "hscroll");
|
|
|
|
ui.checkbox(&mut scroll2[1], "vscroll");
|
2021-08-23 19:28:06 +00:00
|
|
|
});
|
2021-04-18 08:01:41 +00:00
|
|
|
});
|
2021-08-23 19:28:06 +00:00
|
|
|
ui.group(|ui| {
|
|
|
|
ui.vertical(|ui| {
|
|
|
|
ui.checkbox(anchored, "anchored");
|
|
|
|
ui.set_enabled(*anchored);
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.label("x:");
|
2021-08-28 11:18:21 +00:00
|
|
|
ui.selectable_value(&mut anchor[0], egui::Align::LEFT, "Left");
|
|
|
|
ui.selectable_value(&mut anchor[0], egui::Align::Center, "Center");
|
|
|
|
ui.selectable_value(&mut anchor[0], egui::Align::RIGHT, "Right");
|
2021-08-23 19:28:06 +00:00
|
|
|
});
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.label("y:");
|
2021-08-28 11:18:21 +00:00
|
|
|
ui.selectable_value(&mut anchor[1], egui::Align::TOP, "Top");
|
|
|
|
ui.selectable_value(&mut anchor[1], egui::Align::Center, "Center");
|
|
|
|
ui.selectable_value(&mut anchor[1], egui::Align::BOTTOM, "Bottom");
|
2021-08-23 19:28:06 +00:00
|
|
|
});
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
ui.label("Offset:");
|
|
|
|
ui.add(egui::DragValue::new(&mut anchor_offset.x));
|
|
|
|
ui.add(egui::DragValue::new(&mut anchor_offset.y));
|
|
|
|
});
|
|
|
|
});
|
2021-04-18 08:01:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-08-23 19:28:06 +00:00
|
|
|
ui.separator();
|
2021-02-07 13:46:53 +00:00
|
|
|
|
2021-08-23 19:28:06 +00:00
|
|
|
ui.horizontal(|ui| {
|
|
|
|
if ui.button("Disable for 2 seconds").clicked() {
|
|
|
|
self.disabled_time = ui.input().time;
|
|
|
|
}
|
2021-02-07 13:46:53 +00:00
|
|
|
egui::reset_button(ui, self);
|
|
|
|
ui.add(crate::__egui_github_link_file!());
|
|
|
|
});
|
2021-01-02 23:12:54 +00:00
|
|
|
}
|
|
|
|
}
|