-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
window_options.rs
141 lines (131 loc) · 4.33 KB
/
window_options.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct WindowOptions {
title: String,
title_bar: bool,
closable: bool,
collapsible: bool,
resizable: bool,
scroll2: [bool; 2],
disabled_time: f64,
anchored: bool,
anchor: egui::Align2,
anchor_offset: egui::Vec2,
}
impl Default for WindowOptions {
fn default() -> Self {
Self {
title: "🗖 Window Options".to_owned(),
title_bar: true,
closable: true,
collapsible: true,
resizable: true,
scroll2: [true; 2],
disabled_time: f64::NEG_INFINITY,
anchored: false,
anchor: egui::Align2::RIGHT_TOP,
anchor_offset: egui::Vec2::ZERO,
}
}
}
impl super::Demo for WindowOptions {
fn name(&self) -> &'static str {
"🗖 Window Options"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
let Self {
title,
title_bar,
closable,
collapsible,
resizable,
scroll2,
disabled_time,
anchored,
anchor,
anchor_offset,
} = self.clone();
let enabled = ctx.input().time - disabled_time > 2.0;
if !enabled {
ctx.request_repaint();
}
use super::View as _;
let mut window = egui::Window::new(title)
.id(egui::Id::new("demo_window_options")) // required since we change the title
.resizable(resizable)
.collapsible(collapsible)
.title_bar(title_bar)
.scroll2(scroll2)
.enabled(enabled);
if closable {
window = window.open(open);
}
if anchored {
window = window.anchor(anchor, anchor_offset);
}
window.show(ctx, |ui| self.ui(ui));
}
}
impl super::View for WindowOptions {
fn ui(&mut self, ui: &mut egui::Ui) {
let Self {
title,
title_bar,
closable,
collapsible,
resizable,
scroll2,
disabled_time: _,
anchored,
anchor,
anchor_offset,
} = self;
ui.horizontal(|ui| {
ui.label("title:");
ui.text_edit_singleline(title);
});
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");
ui.checkbox(&mut scroll2[0], "hscroll");
ui.checkbox(&mut scroll2[1], "vscroll");
});
});
ui.group(|ui| {
ui.vertical(|ui| {
ui.checkbox(anchored, "anchored");
ui.set_enabled(*anchored);
ui.horizontal(|ui| {
ui.label("x:");
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");
});
ui.horizontal(|ui| {
ui.label("y:");
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");
});
ui.horizontal(|ui| {
ui.label("Offset:");
ui.add(egui::DragValue::new(&mut anchor_offset.x));
ui.add(egui::DragValue::new(&mut anchor_offset.y));
});
});
});
});
ui.separator();
ui.horizontal(|ui| {
if ui.button("Disable for 2 seconds").clicked() {
self.disabled_time = ui.input().time;
}
egui::reset_button(ui, self);
ui.add(crate::egui_github_link_file!());
});
}
}