// Theme — the single semantic-color sink the whole UI consumes. // // This SUPERSEDES the old per-token ternary system. Instead of computing each // token from `ThemeState.mode`, Rust builds one `ThemeColors` struct from the // frontend-agnostic `qbz-theme` registry and pushes it in via `Theme.c` on // every theme change (and at startup). The ~1900 `Theme.` call sites are // unchanged: they read the thin aliases below. // // SYSTEM MODE is the one dynamic case. For "System" the app follows the OS // light/dark scheme through the std-widgets `Palette`. When `ThemeState.is-system` // is true, the tokens that System overrode historically fall back to the std // Palette (exactly as the old `mode == 3` branch did); every other token reads // the pushed struct. Non-System themes ignore the flag entirely. import { Palette as StdPalette } from "std-widgets.slint"; import { ThemeState } from "theme-state.slint"; // The Slint mirror of `qbz_theme::ThemeColors`. Field names are kebab-case and // MUST stay in lockstep with the Rust `set_c` population order/names. export struct ThemeColors { // surfaces surface-main: color, surface-card: color, surface-elevated: color, surface-hover: color, bg-hover: color, // text text-primary: color, text-secondary: color, text-muted: color, text-disabled: color, // accent accent: color, accent-hover: color, accent-pressed: color, accent-text: color, // danger family danger: color, danger-bg: color, danger-border: color, danger-hover: color, // warning family warning: color, warning-bg: color, warning-border: color, warning-hover: color, // success family (NEW) success: color, success-bg: color, success-border: color, success-hover: color, // borders border-subtle: color, border-muted: color, border-strong: color, // focus (NEW) focus-ring: color, // extras favorite: color, card-shadow: color, // alpha scale 4..95 (polarity baked in by Rust: white on dark, black on light) alpha-4: color, alpha-5: color, alpha-6: color, alpha-8: color, alpha-10: color, alpha-12: color, alpha-15: color, alpha-18: color, alpha-20: color, alpha-25: color, alpha-30: color, alpha-35: color, alpha-40: color, alpha-45: color, alpha-50: color, alpha-55: color, alpha-60: color, alpha-65: color, alpha-70: color, alpha-75: color, alpha-80: color, alpha-85: color, alpha-90: color, alpha-95: color, } export global Theme { // The single pushed struct. Seeded with the Dark palette so the live // `.slint` preview (which has no Rust feeding it) renders a sane default; // Rust overwrites it at startup from the persisted theme. in-out property c: { surface-main: #0f0f0f, surface-card: #1a1a1a, surface-elevated: #2a2a2a, surface-hover: #ffffff10, bg-hover: #1f1f1f, text-primary: #ffffff, text-secondary: #cccccc, text-muted: #888888, text-disabled: #555555, accent: #4285f4, accent-hover: #5a9bf4, accent-pressed: #3275e4, accent-text: #ffffff, danger: #ef4444, danger-bg: #ef44441a, danger-border: #ef44444d, danger-hover: #ef444433, warning: #fbbf24, warning-bg: #fbbf241a, warning-border: #fbbf244d, warning-hover: #fbbf2433, success: #3fae6a, success-bg: #3fae6a1a, success-border: #3fae6a4d, success-hover: #3fae6a33, border-subtle: #ffffff14, border-muted: #ffffff38, border-strong: #3a3a3a, focus-ring: #4285f4, favorite: #ef4444, card-shadow: #00000066, alpha-4: #ffffff0a, alpha-5: #ffffff0d, alpha-6: #ffffff0f, alpha-8: #ffffff14, alpha-10: #ffffff1a, alpha-12: #ffffff1f, alpha-15: #ffffff26, alpha-18: #ffffff2e, alpha-20: #ffffff33, alpha-25: #ffffff40, alpha-30: #ffffff4d, alpha-35: #ffffff59, alpha-40: #ffffff66, alpha-45: #ffffff73, alpha-50: #ffffff80, alpha-55: #ffffff8c, alpha-60: #ffffff99, alpha-65: #ffffffa6, alpha-70: #ffffffb3, alpha-75: #ffffffbf, alpha-80: #ffffffcc, alpha-85: #ffffffd9, alpha-90: #ffffffe6, alpha-95: #fffffff2, }; // True only for the "System" theme. Set by Rust alongside `c`. Drives the // std-Palette fallback for the System-overridden tokens below. in-out property is-system: false; // True only for the two High-Contrast themes (HighContrast/HighContrastLight). // Set by Rust alongside `c`. Gates HC-ONLY redundant-encoding affordances // (1px control borders, slider-thumb borders) so they never leak into the // polished normal themes. Components read it via the re-exported Theme global. // // Canonical HC border gate (copy verbatim in components): // border-width: Theme.is-high-contrast ? 1px : 0px; // border-color: Theme.border-strong; // // Canonical NON-LAYOUT focus ring (copy verbatim; draw as a sibling/overlay // Rectangle so focus never reflows the control): // Rectangle { // x: 0; y: 0; width: parent.width; height: parent.height; // border-width: 2px; // border-color: root.has-focus ? Theme.focus-ring : transparent; // border-radius: parent.border-radius; // background: transparent; // } in-out property is-high-contrast: false; // --- Surfaces: System follows the OS palette (was `mode == 3`) ----------- out property surface-main: is-system ? StdPalette.background : c.surface-main; out property surface-card: is-system ? StdPalette.alternate-background : c.surface-card; out property surface-elevated: is-system ? StdPalette.control-background : c.surface-elevated; // surface-hover/bg-hover were never System-conditional historically. out property surface-hover: c.surface-hover; out property bg-hover: c.bg-hover; // --- Text: System derives muted tiers from the OS foreground via alpha ---- out property text-primary: is-system ? StdPalette.foreground : c.text-primary; out property text-secondary: is-system ? StdPalette.foreground.with-alpha(0.78) : c.text-secondary; out property text-muted: is-system ? StdPalette.foreground.with-alpha(0.55) : c.text-muted; out property text-disabled: is-system ? StdPalette.foreground.with-alpha(0.35) : c.text-disabled; // --- Accent: System uses the OS accent ------------------------------------ out property accent: is-system ? StdPalette.accent-background : c.accent; out property accent-hover: is-system ? StdPalette.accent-background.brighter(0.15) : c.accent-hover; out property accent-pressed: is-system ? StdPalette.accent-background.darker(0.15) : c.accent-pressed; out property accent-text: is-system ? StdPalette.accent-foreground : c.accent-text; // --- Danger family -------------------------------------------------------- out property danger: c.danger; out property danger-bg: c.danger-bg; out property danger-border: c.danger-border; out property danger-hover: c.danger-hover; // --- Warning family ------------------------------------------------------- out property warning: c.warning; out property warning-bg: c.warning-bg; out property warning-border: c.warning-border; out property warning-hover: c.warning-hover; // --- Success family (NEW) ------------------------------------------------- out property success: c.success; out property success-bg: c.success-bg; out property success-border: c.success-border; out property success-hover: c.success-hover; // --- Borders -------------------------------------------------------------- out property border-subtle: c.border-subtle; out property border-muted: c.border-muted; out property border-strong: c.border-strong; // --- Focus (NEW) ---------------------------------------------------------- out property focus-ring: c.focus-ring; // --- Extras --------------------------------------------------------------- out property favorite: c.favorite; out property card-shadow: c.card-shadow; // --- Alpha overlays (legacy names preserved) ------------------------------ // The historical call sites use `alpha-08` (zero-padded). Keep that exact // name as an alias of the 8% tier; expose the rest of the superset too. out property alpha-4: c.alpha-4; out property alpha-5: c.alpha-5; out property alpha-6: c.alpha-6; out property alpha-08: c.alpha-8; out property alpha-8: c.alpha-8; out property alpha-10: c.alpha-10; out property alpha-12: c.alpha-12; out property alpha-15: c.alpha-15; out property alpha-18: c.alpha-18; out property alpha-20: c.alpha-20; out property alpha-25: c.alpha-25; out property alpha-30: c.alpha-30; out property alpha-35: c.alpha-35; out property alpha-40: c.alpha-40; out property alpha-45: c.alpha-45; out property alpha-50: c.alpha-50; out property alpha-55: c.alpha-55; out property alpha-60: c.alpha-60; out property alpha-65: c.alpha-65; out property alpha-70: c.alpha-70; out property alpha-75: c.alpha-75; out property alpha-80: c.alpha-80; out property alpha-85: c.alpha-85; out property alpha-90: c.alpha-90; out property alpha-95: c.alpha-95; }