1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Add Ui::set_visible as a way to hide widgets

Closes https://github.com/emilk/egui/issues/460
This commit is contained in:
Emil Ernerfeldt
2021-06-07 22:12:49 +02:00
parent 3c603c55b8
commit ece25ee7f3
4 changed files with 79 additions and 21 deletions

View File

@@ -9,6 +9,7 @@ enum Enum {
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct WidgetGallery {
enabled: bool,
visible: bool,
boolean: bool,
radio: Enum,
scalar: f32,
@@ -20,6 +21,7 @@ impl Default for WidgetGallery {
fn default() -> Self {
Self {
enabled: true,
visible: true,
boolean: false,
radio: Enum::First,
scalar: 42.0,
@@ -47,13 +49,27 @@ impl super::Demo for WidgetGallery {
impl super::View for WidgetGallery {
fn ui(&mut self, ui: &mut egui::Ui) {
self.gallery(ui);
ui.scope(|ui| {
ui.set_visible(self.visible);
ui.set_enabled(self.enabled);
egui::Grid::new("my_grid")
.striped(true)
.spacing([40.0, 4.0])
.show(ui, |ui| {
self.gallery_grid_contents(ui);
});
});
ui.separator();
ui.vertical_centered(|ui| {
ui.checkbox(&mut self.enabled, "Interactive")
.on_hover_text("Convenient way to inspect how the widgets look when disabled.");
ui.horizontal(|ui| {
ui.checkbox(&mut self.visible, "Visible")
.on_hover_text("Uncheck to hide all the widgets.");
if self.visible {
ui.checkbox(&mut self.enabled, "Interactive")
.on_hover_text("Uncheck to inspect how the widgets look when disabled.");
}
});
ui.separator();
@@ -69,18 +85,10 @@ impl super::View for WidgetGallery {
}
impl WidgetGallery {
fn gallery(&mut self, ui: &mut egui::Ui) {
egui::Grid::new("my_grid")
.striped(true)
.spacing([40.0, 4.0])
.show(ui, |ui| {
self.gallery_grid_contents(ui);
});
}
fn gallery_grid_contents(&mut self, ui: &mut egui::Ui) {
let Self {
enabled,
enabled: _,
visible: _,
boolean,
radio,
scalar,
@@ -88,8 +96,6 @@ impl WidgetGallery {
color,
} = self;
ui.set_enabled(*enabled);
ui.add(doc_link_label("Label", "label,heading"));
ui.label("Welcome to the widget gallery!");
ui.end_row();