Skip to content

Commit da6f63c

Browse files
committed
fix: follow system appearance by default
1 parent f8d54d7 commit da6f63c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎crates/ui-egui/src/lib.rs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ pub struct SlideApp {
200200
pending_shots: Vec<(u64, Option<String>, Sender<ControlResponse>, f64)>,
201201
styled: bool,
202202
restyle: bool,
203+
last_system_theme: Option<egui::Theme>,
203204
fonts_ready: bool,
204205
last_time: f64,
205206
/// When AutoRecover data was last written (seconds, egui time).
@@ -238,6 +239,7 @@ impl SlideApp {
238239
pending_shots: vec![],
239240
styled: false,
240241
restyle: true,
242+
last_system_theme: None,
241243
fonts_ready: false,
242244
last_time: 0.0,
243245
last_recovery: 0.0,
@@ -325,7 +327,7 @@ impl SlideApp {
325327
}
326328
"view.collapseRibbon" => self.ui.ribbon_collapsed = !self.ui.ribbon_collapsed,
327329
"view.dark" => {
328-
let on = self.flag(p, self.ui.brightness == theme::Brightness::Dark);
330+
let on = self.flag(p, self.ui.brightness != theme::Brightness::Dark);
329331
self.ui.brightness = if on { theme::Brightness::Dark } else { theme::Brightness::Light };
330332
self.restyle = true;
331333
}
@@ -530,6 +532,11 @@ impl SlideApp {
530532

531533
/// Per-frame logic before layout: styles, control requests, screenshots, shortcuts.
532534
pub fn logic(&mut self, ctx: &egui::Context) {
535+
let system_theme = ctx.system_theme();
536+
if self.ui.brightness == theme::Brightness::System && system_theme != self.last_system_theme {
537+
self.restyle = true;
538+
}
539+
self.last_system_theme = system_theme;
533540
let scale = self.ui.ui_scale.clamp(0.5, 3.0);
534541
if (ctx.zoom_factor() - scale).abs() > 1e-3 {
535542
ctx.set_zoom_factor(scale);
@@ -542,7 +549,14 @@ impl SlideApp {
542549
self.fonts_ready = true;
543550
}
544551
if self.restyle {
545-
theme::apply(ctx, &theme::Tokens::for_brightness(self.ui.brightness));
552+
let brightness = match self.ui.brightness {
553+
theme::Brightness::System => match system_theme {
554+
Some(egui::Theme::Dark) => theme::Brightness::Dark,
555+
Some(egui::Theme::Light) | None => theme::Brightness::Light,
556+
},
557+
brightness => brightness,
558+
};
559+
theme::apply(ctx, &theme::Tokens::for_brightness(brightness));
546560
self.restyle = false;
547561
}
548562
let now = ctx.input(|i| i.time);

‎crates/ui-egui/src/theme.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
77
#[serde(rename_all = "camelCase")]
88
pub enum Brightness {
99
#[default]
10+
System,
1011
Light,
1112
Dark,
1213
}
@@ -103,6 +104,7 @@ impl Tokens {
103104
}
104105
pub fn for_brightness(b: Brightness) -> Self {
105106
match b {
107+
Brightness::System => Self::light(),
106108
Brightness::Light => Self::light(),
107109
Brightness::Dark => Self::dark(),
108110
}

0 commit comments

Comments
 (0)