From 8779025e0968787c7908f77a266ee53cdb561037 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 1 Feb 2024 10:48:42 +0100 Subject: [PATCH] Add options to the backend panel ui --- crates/egui/src/context.rs | 23 +++++------------- crates/egui/src/memory.rs | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 97fdd8112c1..8ba379e9979 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -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. diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 39966374f11..8f4c8b169b8 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -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.