From 99969a6812304c92ef4f0554f854a688095ea723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Sat, 20 Jul 2024 21:38:14 +0200 Subject: [PATCH] Set theme from toggle buttons --- crates/egui/src/widgets/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/mod.rs b/crates/egui/src/widgets/mod.rs index 9900117062e..c5ab155e25e 100644 --- a/crates/egui/src/widgets/mod.rs +++ b/crates/egui/src/widgets/mod.rs @@ -137,7 +137,11 @@ pub fn global_dark_light_mode_switch(ui: &mut Ui) { let style: crate::Style = (*ui.ctx().style()).clone(); let new_visuals = style.visuals.light_dark_small_toggle_button(ui); if let Some(visuals) = new_visuals { - ui.ctx().set_visuals(visuals); + if visuals.dark_mode { + ui.ctx().set_theme(Theme::Dark) + } else { + ui.ctx().set_theme(Theme::Light) + } } } @@ -145,5 +149,9 @@ pub fn global_dark_light_mode_switch(ui: &mut Ui) { pub fn global_dark_light_mode_buttons(ui: &mut Ui) { let mut visuals = ui.ctx().style().visuals.clone(); visuals.light_dark_radio_buttons(ui); - ui.ctx().set_visuals(visuals); + if visuals.dark_mode { + ui.ctx().set_theme(Theme::Dark) + } else { + ui.ctx().set_theme(Theme::Light) + } }