51 lines
2 KiB
Rust
51 lines
2 KiB
Rust
#[derive(Default)]
|
|
pub struct Tests {}
|
|
|
|
impl super::Demo for Tests {
|
|
fn name(&self) -> &str {
|
|
"📋 Tests"
|
|
}
|
|
|
|
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
|
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
|
use super::View;
|
|
self.ui(ui);
|
|
});
|
|
}
|
|
}
|
|
|
|
impl super::View for Tests {
|
|
fn ui(&mut self, ui: &mut egui::Ui) {
|
|
ui.heading("Name collision example");
|
|
|
|
ui.label("\
|
|
Widgets that store state require unique and persisting identifiers so we can track their state between frames.\n\
|
|
For instance, collapsable headers needs to store wether or not they are open. \
|
|
Their Id:s are derived from their names. \
|
|
If you fail to give them unique names then clicking one will open both. \
|
|
To help you debug this, an error message is printed on screen:");
|
|
|
|
ui.collapsing("Collapsing header", |ui| {
|
|
ui.label("Contents of first foldable ui");
|
|
});
|
|
ui.collapsing("Collapsing header", |ui| {
|
|
ui.label("Contents of second foldable ui");
|
|
});
|
|
|
|
ui.label("\
|
|
Any widget that can be interacted with also need a unique Id. \
|
|
For most widgets the Id is generated by a running counter. \
|
|
As long as elements are not added or removed, the Id stays the same. \
|
|
This is fine, because during interaction (i.e. while dragging a slider), \
|
|
the number of widgets previously in the same window is most likely not changing \
|
|
(and if it is, the window will have a new layout, and the slider will endup somewhere else, and so aborthing the interaction probably makes sense).");
|
|
|
|
ui.label("So these buttons have automatic Id:s, and therefore there is no name clash:");
|
|
let _ = ui.button("Button");
|
|
let _ = ui.button("Button");
|
|
|
|
ui.vertical_centered(|ui| {
|
|
ui.add(crate::__egui_github_link_file!());
|
|
});
|
|
}
|
|
}
|