diff --git a/crates/voelin-ui/ui/app.slint b/crates/voelin-ui/ui/app.slint index 39729ae..60c278d 100644 --- a/crates/voelin-ui/ui/app.slint +++ b/crates/voelin-ui/ui/app.slint @@ -8,6 +8,7 @@ import "assets/fonts/Inter-SemiBold.ttf"; import "assets/fonts/Inter-Bold.ttf"; import "assets/fonts/Inter-Italic.ttf"; +import { Palette } from "std-widgets.slint"; import { Theme } from "theme.slint"; import { Icons } from "icons.slint"; import { Bridge } from "bridge.slint"; @@ -44,7 +45,10 @@ export component MainWindow inherits Window { property breakpoint: Nav.narrow-breakpoint; changed width => { Nav.narrow = self.width < Nav.narrow-breakpoint; } changed breakpoint => { Nav.narrow = self.width < Nav.narrow-breakpoint; } - init => { Nav.narrow = self.width < Nav.narrow-breakpoint; } + init => { + Nav.narrow = self.width < Nav.narrow-breakpoint; + Theme.system-dark = Palette.color-scheme != ColorScheme.light; + } // Android: the space under the on-screen keyboard (the window is not // resized for it). Zero on desktop. property keyboard-inset: 0; @@ -55,6 +59,23 @@ export component MainWindow inherits Window { // The viewer takes the whole window in full screen. property chrome: !(Bridge.viewer-open && Bridge.viewer-fullscreen); + // The standard widgets follow the theme. In "system" mode the palette + // is left alone (it tracks the system) unless an explicit mode was + // set before; then the scheme seen at start is used. + property theme-mode: Theme.mode; + property scheme-set; + changed theme-mode => { apply-color-scheme(); } + function apply-color-scheme() { + if Theme.mode == "dark" { + Palette.color-scheme = ColorScheme.dark; + } else if Theme.mode == "light" { + Palette.color-scheme = ColorScheme.light; + } else if Theme.mode == "system" && scheme-set { + Palette.color-scheme = Theme.system-dark ? ColorScheme.dark : ColorScheme.light; + } + scheme-set = scheme-set || Theme.mode == "dark" || Theme.mode == "light"; + } + // Status messages show as a toast. property status: Bridge.status-text; changed status => { toast.shown = status != ""; } diff --git a/crates/voelin-ui/ui/theme.slint b/crates/voelin-ui/ui/theme.slint index 32f0409..5f2a372 100644 --- a/crates/voelin-ui/ui/theme.slint +++ b/crates/voelin-ui/ui/theme.slint @@ -10,11 +10,15 @@ import { Palette } from "std-widgets.slint"; export global Theme { - // "dark", "light" or "system" (the setting `ui.theme`). - in-out property mode: "dark"; + // "dark", "light" or "system" (the setting `ui.theme`; Rust sets it + // right after the window is created, "" until then). + in-out property mode: ""; + // The system's scheme when the window was created (see MainWindow). + in-out property system-dark: true; // Dark or light colours. The standard widgets (scroll bars, context - // menus) follow the system's scheme. - out property dark: mode == "system" ? Palette.color-scheme != ColorScheme.light : mode != "light"; + // menus) follow through `Palette.color-scheme`, set by MainWindow. + out property dark: mode == "system" ? Palette.color-scheme == ColorScheme.dark || (Palette.color-scheme == ColorScheme.unknown && system-dark) : mode != "light"; + // Multiplies every type size (and the sizes that follow text). in-out property font-scale: 1.0;