From 8fae8392f69c914a0b6b14a9c1273a52d0f3b57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Wed, 7 Aug 2024 16:21:01 +0200 Subject: [PATCH] Add separate light and dark styles --- crates/egui/src/context.rs | 76 +++++++++++++++++----- crates/egui/src/memory.rs | 46 ++++++------- crates/egui/src/memory/theme.rs | 40 ++++++++++++ crates/egui/src/style.rs | 10 --- crates/egui/src/widgets/mod.rs | 12 ++-- crates/egui_demo_lib/src/demo/scrolling.rs | 7 +- examples/custom_font_style/src/main.rs | 6 +- examples/custom_keypad/src/main.rs | 2 +- examples/screenshot/src/main.rs | 4 +- 9 files changed, 136 insertions(+), 67 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 9a748b78a39..5fb2d729b72 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1619,7 +1619,7 @@ impl Context { self.options(|opt| opt.style().clone()) } - /// Mutate the [`Style`] used by all subsequent windows, panels etc. + /// Mutate the [`Style`]s used by all subsequent windows, panels etc in both dark and light mode. /// /// Example: /// ``` @@ -1628,30 +1628,65 @@ impl Context { /// style.spacing.item_spacing = egui::vec2(10.0, 20.0); /// }); /// ``` - pub fn style_mut(&self, mutate_style: impl FnOnce(&mut Style)) { - self.options_mut(|opt| mutate_style(std::sync::Arc::make_mut(&mut opt.style))); + pub fn style_mut(&self, mut mutate_style: impl FnMut(&mut Style)) { + self.options_mut(|opt| { + mutate_style(std::sync::Arc::make_mut(&mut opt.dark_style)); + mutate_style(std::sync::Arc::make_mut(&mut opt.light_style)); + }); + } + + /// The [`Style`] used by all subsequent windows, panels etc in dark mode. + pub fn dark_style(&self) -> Arc