diff --git a/src/settings.rs b/src/settings.rs index 89e9490b..4051f1e6 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -13,6 +13,7 @@ pub const DEFAULT_MAX_FPS: u32 = 30; pub const DEFAULT_FEED_RECOMPUTE_INTERVAL_MS: u32 = 2000; pub const DEFAULT_POW: u8 = 0; pub const DEFAULT_OFFLINE: bool = false; +pub const DEFAULT_LIGHT_MODE: bool = true; // true = light false = dark #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Settings { @@ -28,6 +29,7 @@ pub struct Settings { pub feed_recompute_interval_ms: u32, pub pow: u8, pub offline: bool, + pub light_mode: bool, } impl Default for Settings { @@ -45,6 +47,7 @@ impl Default for Settings { feed_recompute_interval_ms: DEFAULT_FEED_RECOMPUTE_INTERVAL_MS, pow: DEFAULT_POW, offline: DEFAULT_OFFLINE, + light_mode: DEFAULT_LIGHT_MODE, } } } @@ -101,6 +104,7 @@ impl Settings { } "pow" => settings.pow = row.1.parse::().unwrap_or(DEFAULT_POW), "offline" => settings.offline = numstr_to_bool(row.1), + "light_mode" => settings.light_mode = numstr_to_bool(row.1), _ => {} } } @@ -131,6 +135,7 @@ impl Settings { ('max_fps', ?),\ ('feed_recompute_interval_ms', ?),\ ('pow', ?),\ + ('light_mode', ?),\ ('offline', ?)", )?; stmt.execute(( @@ -143,6 +148,7 @@ impl Settings { self.max_fps, self.feed_recompute_interval_ms, self.pow, + bool_to_numstr(self.light_mode), bool_to_numstr(self.offline), ))?; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 8a8a3e8d..120c2494 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -100,7 +100,10 @@ impl Drop for GossipUi { impl GossipUi { fn new(cctx: &eframe::CreationContext<'_>) -> Self { - if cctx.egui_ctx.style().visuals.dark_mode { + // grab settings to determine whether to render dark_mode or light_mode + let settings = GLOBALS.settings.blocking_read().clone(); + + if ! settings.light_mode { cctx.egui_ctx.set_visuals(style::dark_mode_visuals()); } else { cctx.egui_ctx.set_visuals(style::light_mode_visuals()); @@ -138,8 +141,6 @@ impl GossipUi { ) }; - let settings = GLOBALS.settings.blocking_read().clone(); - GossipUi { next_frame: Instant::now(), page: Page::FeedGeneral, @@ -183,8 +184,6 @@ impl eframe::App for GossipUi { frame.close(); } - let darkmode: bool = ctx.style().visuals.dark_mode; - egui::TopBottomPanel::top("menu").show(ctx, |ui| { ui.horizontal(|ui| { if ui @@ -275,7 +274,7 @@ impl eframe::App for GossipUi { } Page::You => you::update(self, ctx, frame, ui), Page::Relays => relays::update(self, ctx, frame, ui), - Page::Settings => settings::update(self, ctx, frame, ui, darkmode), + Page::Settings => settings::update(self, ctx, frame, ui), Page::HelpHelp | Page::HelpStats | Page::HelpAbout => { help::update(self, ctx, frame, ui) } diff --git a/src/ui/settings.rs b/src/ui/settings.rs index 6214af53..2d405c6d 100644 --- a/src/ui/settings.rs +++ b/src/ui/settings.rs @@ -10,7 +10,6 @@ pub(super) fn update( _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui, - darkmode: bool, ) { ui.heading("Settings"); @@ -111,23 +110,24 @@ pub(super) fn update( ui.horizontal(|ui| { ui.label("Switch to"); - #[allow(clippy::collapsible_else_if)] - if darkmode { - if ui - .add(Button::new("☀ Light")) - .on_hover_text("Switch to light mode") - .clicked() - { - ui.ctx().set_visuals(super::style::light_mode_visuals()); - } - } else { + if app.settings.light_mode { if ui .add(Button::new("🌙 Dark")) .on_hover_text("Switch to dark mode") .clicked() { ui.ctx().set_visuals(super::style::dark_mode_visuals()); + app.settings.light_mode = false; + } + } else { + if ui + .add(Button::new("☀ Light")) + .on_hover_text("Switch to light mode") + .clicked() + { + ui.ctx().set_visuals(super::style::light_mode_visuals()); + app.settings.light_mode = true; } } }); diff --git a/src/ui/style.rs b/src/ui/style.rs index ea51b8bf..e7ee0781 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -17,15 +17,15 @@ pub(super) fn dark_mode_visuals() -> Visuals { code_bg_color: Color32::from_gray(64), // Foreground colors - window_stroke: Stroke::new(1.0, Color32::from_rgb(0x37, 0x96, 0x83)), // DONE - override_text_color: None, + window_stroke: Stroke::new(1.0, Color32::from_rgb(0x37, 0x96, 0x83)), + override_text_color: Some(Color32::from_gray(190)), warn_fg_color: Color32::from_rgb(255, 143, 0), // orange error_fg_color: Color32::from_rgb(255, 0, 0), // red - hyperlink_color: Color32::from_rgb(0x73, 0x95, 0xae), // DONE + hyperlink_color: Color32::from_rgb(0x73, 0x95, 0xae), selection: Selection { - bg_fill: Color32::from_rgb(0xb1, 0xa2, 0x96), // DONE - stroke: Stroke::new(1.0, Color32::from_rgb(0x37, 0x96, 0x83)), // DONE + bg_fill: Color32::from_rgb(0x57, 0x4a, 0x40), + stroke: Stroke::new(1.0, Color32::from_rgb(0x37, 0x96, 0x83)), }, window_shadow: Shadow::big_dark(),