From a028f5375f868206f3a97d84e389633bc2c59137 Mon Sep 17 00:00:00 2001 From: Filip Binkiewicz Date: Mon, 19 Feb 2024 19:20:19 +0000 Subject: [PATCH] Reintroduce persistent dark/light mode --- CHANGELOG.md | 2 ++ rog-control-center/src/widgets/top_bar.rs | 32 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9c6bfb..d4382f08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Reintroduce persisting dark/light mode in config file ## [v5.0.7] ### Changed diff --git a/rog-control-center/src/widgets/top_bar.rs b/rog-control-center/src/widgets/top_bar.rs index 72b2fff3..344942cf 100644 --- a/rog-control-center/src/widgets/top_bar.rs +++ b/rog-control-center/src/widgets/top_bar.rs @@ -8,7 +8,7 @@ impl RogApp { // The top panel is often a good place for a menu bar: egui::menu::bar(ui, |ui| { ui.horizontal(|ui| { - egui::global_dark_light_mode_buttons(ui); + self.dark_light_mode_buttons(ui); egui::warn_if_debug_build(ui); }); @@ -44,4 +44,34 @@ impl RogApp { }); }); } + + fn dark_light_mode_buttons(&mut self, ui: &mut egui::Ui) { + let load_from_cfg = self.config.dark_mode != ui.ctx().style().visuals.dark_mode; + + if ui + .add(egui::SelectableLabel::new( + !self.config.dark_mode, + "☀ Light", + )) + .clicked() + || (load_from_cfg && !self.config.dark_mode) + { + ui.ctx().set_visuals(egui::Visuals::light()); + } + if ui + .add(egui::SelectableLabel::new(self.config.dark_mode, "🌙 Dark")) + .clicked() + || (load_from_cfg && self.config.dark_mode) + { + ui.ctx().set_visuals(egui::Visuals::dark()); + } + + let applied_dark_mode = ui.ctx().style().visuals.dark_mode; + + if self.config.dark_mode != applied_dark_mode { + self.config.dark_mode = applied_dark_mode; + let tmp = self.config.enabled_notifications.clone(); + self.config.save(&tmp).ok(); + } + } }