From a22dc2e2fa4b91283c68dae901c8fa9dacbf18d1 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/eframe/src/epi.rs | 2 +- crates/egui/src/context.rs | 100 +++++++++++++++++---- crates/egui/src/memory.rs | 46 +++++----- crates/egui/src/memory/theme.rs | 40 +++++++++ crates/egui/src/style.rs | 25 ++---- crates/egui/src/ui.rs | 6 +- 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 +- 11 files changed, 173 insertions(+), 77 deletions(-) diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index 3b303dce1ee..a8108db3f2c 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -53,7 +53,7 @@ pub struct CreationContext<'s> { /// The egui Context. /// /// You can use this to customize the look of egui, e.g to call [`egui::Context::set_fonts`], - /// [`egui::Context::set_visuals`] etc. + /// [`egui::Context::set_dark_visuals`] etc. pub egui_ctx: egui::Context, /// Information about the surrounding environment. diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index d9f107c6d6f..2b3e2930779 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1625,7 +1625,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: /// ``` @@ -1634,30 +1634,93 @@ 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