From 3dad91bef32cddab53592df658bc33a1cbeb46f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Wed, 7 Aug 2024 12:11:51 +0200 Subject: [PATCH 01/20] Theme Preference --- crates/egui/src/context.rs | 18 ++++++++++++++++++ crates/egui/src/lib.rs | 2 +- crates/egui/src/memory/mod.rs | 23 ++++++++++++++++------- crates/egui/src/memory/theme.rs | 23 +++++++++++++++++++++++ 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 162ff4a739e..1bd581df7ad 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1612,6 +1612,24 @@ impl Context { } } + /// The [`crate::Theme`] used to select the appropriate [`Style`] (dark or light) + /// used by all subsequent windows, panels etc. + pub fn theme(&self) -> crate::Theme { + self.options(|opt| opt.theme()) + } + + /// The [`Theme`] used to select between [`Self::dark_style()`] and [`Self::light_style()`] + /// as the active style used by all subsequent windows, panels etc. + /// + /// Example: + /// ``` + /// # let mut ctx = egui::Context::default(); + /// ctx.set_theme(egui::Theme::Light); // Switch to light mode + /// ``` + pub fn set_theme(&self, theme_preference: impl Into) { + self.options_mut(|opt| opt.theme_preference = theme_preference.into()); + } + /// The [`Style`] used by all subsequent windows, panels etc. pub fn style(&self) -> Arc