voelin-ui: standard widgets follow the app theme
Scroll bars and context menus come from the standard widgets, which follow Palette.color-scheme. The window now sets it from ui.theme: dark or light explicitly, and in "system" mode it leaves the palette tracking the system (or, after an explicit mode, uses the scheme seen at start, since the tracking binding cannot be restored). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
2 files changed
+30
-5
No files matched your search
@@ -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 <length> 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 <length> keyboard-inset: 0;
|
||||
@@ -55,6 +59,23 @@ export component MainWindow inherits Window {
|
||||
// The viewer takes the whole window in full screen.
|
||||
property <bool> 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 <string> theme-mode: Theme.mode;
|
||||
property <bool> 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 <string> status: Bridge.status-text;
|
||||
changed status => { toast.shown = status != ""; }
|
||||
|
||||
@@ -10,11 +10,15 @@
|
||||
import { Palette } from "std-widgets.slint";
|
||||
|
||||
export global Theme {
|
||||
// "dark", "light" or "system" (the setting `ui.theme`).
|
||||
in-out property <string> mode: "dark";
|
||||
// "dark", "light" or "system" (the setting `ui.theme`; Rust sets it
|
||||
// right after the window is created, "" until then).
|
||||
in-out property <string> mode: "";
|
||||
// The system's scheme when the window was created (see MainWindow).
|
||||
in-out property <bool> system-dark: true;
|
||||
// Dark or light colours. The standard widgets (scroll bars, context
|
||||
// menus) follow the system's scheme.
|
||||
out property <bool> dark: mode == "system" ? Palette.color-scheme != ColorScheme.light : mode != "light";
|
||||
// menus) follow through `Palette.color-scheme`, set by MainWindow.
|
||||
out property <bool> 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 <float> font-scale: 1.0;
|
||||
|
||||
|
||||
Reference in new issue
Block a user