Skip to content

Commit

Permalink
Add options to the backend panel ui
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 1, 2024
1 parent af9aa56 commit 8779025
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
23 changes: 6 additions & 17 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2348,25 +2348,14 @@ impl Context {
impl Context {
/// Show a ui for settings (style and tessellation options).
pub fn settings_ui(&self, ui: &mut Ui) {
use crate::containers::*;
let prev_options = self.options(|o| o.clone());
let mut options = prev_options.clone();

CollapsingHeader::new("🎑 Style")
.default_open(true)
.show(ui, |ui| {
self.style_ui(ui);
});
options.ui(ui);

CollapsingHeader::new("✒ Painting")
.default_open(true)
.show(ui, |ui| {
let prev_tessellation_options = self.tessellation_options(|o| *o);
let mut tessellation_options = prev_tessellation_options;
tessellation_options.ui(ui);
ui.vertical_centered(|ui| reset_button(ui, &mut tessellation_options));
if tessellation_options != prev_tessellation_options {
self.tessellation_options_mut(move |o| *o = tessellation_options);
}
});
if options != prev_options {
self.options_mut(move |o| *o = options);
}
}

/// Show the state of egui, including its input and output.
Expand Down
50 changes: 50 additions & 0 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,56 @@ impl Default for Options {
}
}

impl Options {
/// Show the options in the ui.
pub fn ui(&mut self, ui: &mut crate::Ui) {
let Self {
style, // covered above
zoom_factor: _, // TODO
zoom_with_keyboard,
tessellation_options,
repaint_on_widget_change,
screen_reader: _, // needs to come from the integration
preload_font_glyphs: _,
warn_on_id_clash,
} = self;

use crate::Widget as _;

CollapsingHeader::new("⚙ Options")
.default_open(false)
.show(ui, |ui| {
ui.checkbox(
repaint_on_widget_change,
"Repaint if any widget moves or changes id",
);

ui.checkbox(
zoom_with_keyboard,
"Zoom with keyboard (Cmd +, Cmd -, Cmd 0)",
);

ui.checkbox(warn_on_id_clash, "Warn if two widgets have the same Id");
});

use crate::containers::*;
CollapsingHeader::new("🎑 Style")
.default_open(true)
.show(ui, |ui| {
std::sync::Arc::make_mut(style).ui(ui);
});

CollapsingHeader::new("✒ Painting")
.default_open(true)
.show(ui, |ui| {
tessellation_options.ui(ui);
ui.vertical_centered(|ui| crate::reset_button(ui, tessellation_options));
});

ui.vertical_centered(|ui| crate::reset_button(ui, self));
}
}

// ----------------------------------------------------------------------------

/// Say there is a button in a scroll area.
Expand Down

0 comments on commit 8779025

Please sign in to comment.