Files
qbz/crates/qbz-slint/ui/foundation/theme.slint
T
vicrodh 8c8871be2a feat(qbz-slint): add Rust-driven Theme global (dumb sink)
Replace the per-token `ThemeState.mode` ternary system with a single
`ThemeColors` struct (`Theme.c`) that Rust pushes from the qbz-theme registry.

- New `foundation/theme.slint`: `ThemeColors` struct (kebab-case fields in
  lockstep with `qbz_theme::ThemeColors`) + `Theme` global of thin aliases.
  Every existing token name is preserved (surface-*, text-*, accent-*,
  border-subtle/muted, favorite, card-shadow, alpha-08/10/12/18/55/65/70/75)
  so the ~1900 call sites compile verbatim; the danger/warning/success
  families, border-strong, bg-hover, focus-ring and the full 24-tier alpha
  superset are added.
- System mode preserved: `Theme.is-system` (set by Rust) falls the
  System-overridden tokens back to the std-widgets Palette exactly as the old
  `mode == 3` branch did; all other themes read `c.*`.
- `semantic-colors.slint` becomes a re-export of `Theme`/`ThemeColors` from
  `theme.slint`, so the 146 existing imports keep resolving.
- The `Theme.c` default is seeded with the Dark palette so the live `.slint`
  preview renders without a Rust feed.

cc
2026-06-20 14:51:18 -06:00

233 lines
8.9 KiB
Plaintext

// 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.<token>` 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 <ThemeColors> 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 <bool> is-system: false;
// --- Surfaces: System follows the OS palette (was `mode == 3`) -----------
out property <color> surface-main: is-system ? StdPalette.background : c.surface-main;
out property <color> surface-card: is-system ? StdPalette.alternate-background : c.surface-card;
out property <color> surface-elevated: is-system ? StdPalette.control-background : c.surface-elevated;
// surface-hover/bg-hover were never System-conditional historically.
out property <color> surface-hover: c.surface-hover;
out property <color> bg-hover: c.bg-hover;
// --- Text: System derives muted tiers from the OS foreground via alpha ----
out property <color> text-primary: is-system ? StdPalette.foreground : c.text-primary;
out property <color> text-secondary: is-system ? StdPalette.foreground.with-alpha(0.78) : c.text-secondary;
out property <color> text-muted: is-system ? StdPalette.foreground.with-alpha(0.55) : c.text-muted;
out property <color> text-disabled: is-system ? StdPalette.foreground.with-alpha(0.35) : c.text-disabled;
// --- Accent: System uses the OS accent ------------------------------------
out property <color> accent: is-system ? StdPalette.accent-background : c.accent;
out property <color> accent-hover: is-system ? StdPalette.accent-background.brighter(0.15) : c.accent-hover;
out property <color> accent-pressed: is-system ? StdPalette.accent-background.darker(0.15) : c.accent-pressed;
out property <color> accent-text: is-system ? StdPalette.accent-foreground : c.accent-text;
// --- Danger family --------------------------------------------------------
out property <color> danger: c.danger;
out property <color> danger-bg: c.danger-bg;
out property <color> danger-border: c.danger-border;
out property <color> danger-hover: c.danger-hover;
// --- Warning family -------------------------------------------------------
out property <color> warning: c.warning;
out property <color> warning-bg: c.warning-bg;
out property <color> warning-border: c.warning-border;
out property <color> warning-hover: c.warning-hover;
// --- Success family (NEW) -------------------------------------------------
out property <color> success: c.success;
out property <color> success-bg: c.success-bg;
out property <color> success-border: c.success-border;
out property <color> success-hover: c.success-hover;
// --- Borders --------------------------------------------------------------
out property <color> border-subtle: c.border-subtle;
out property <color> border-muted: c.border-muted;
out property <color> border-strong: c.border-strong;
// --- Focus (NEW) ----------------------------------------------------------
out property <color> focus-ring: c.focus-ring;
// --- Extras ---------------------------------------------------------------
out property <color> favorite: c.favorite;
out property <color> 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 <color> alpha-4: c.alpha-4;
out property <color> alpha-5: c.alpha-5;
out property <color> alpha-6: c.alpha-6;
out property <color> alpha-08: c.alpha-8;
out property <color> alpha-8: c.alpha-8;
out property <color> alpha-10: c.alpha-10;
out property <color> alpha-12: c.alpha-12;
out property <color> alpha-15: c.alpha-15;
out property <color> alpha-18: c.alpha-18;
out property <color> alpha-20: c.alpha-20;
out property <color> alpha-25: c.alpha-25;
out property <color> alpha-30: c.alpha-30;
out property <color> alpha-35: c.alpha-35;
out property <color> alpha-40: c.alpha-40;
out property <color> alpha-45: c.alpha-45;
out property <color> alpha-50: c.alpha-50;
out property <color> alpha-55: c.alpha-55;
out property <color> alpha-60: c.alpha-60;
out property <color> alpha-65: c.alpha-65;
out property <color> alpha-70: c.alpha-70;
out property <color> alpha-75: c.alpha-75;
out property <color> alpha-80: c.alpha-80;
out property <color> alpha-85: c.alpha-85;
out property <color> alpha-90: c.alpha-90;
out property <color> alpha-95: c.alpha-95;
}