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
This commit is contained in:
2 files changed
+242
-92
No files matched your search
@@ -1,95 +1,13 @@
|
||||
// Semantic color tokens — the contract every component consumes.
|
||||
//
|
||||
// `Theme` is the surface that swaps palettes: every token is conditional on
|
||||
// ThemeState.mode (0 = Dark, 1 = OLED Black, 2 = Tokyo Night, 3 = System).
|
||||
// The System mode sources colors from the std-widgets Palette, which follows
|
||||
// the OS light/dark scheme. Token names stay stable so components never
|
||||
// change. The fixed values mirror src/app.css.
|
||||
// The implementation moved to `theme.slint` (a Rust-driven dumb sink: one
|
||||
// `ThemeColors` struct pushed in per theme change, instead of per-token
|
||||
// ternaries on `ThemeState.mode`). This file is kept as the stable public
|
||||
// import path: the ~150 components that `import { Theme } from
|
||||
// "semantic-colors.slint"` keep working unchanged. New code may import from
|
||||
// either path.
|
||||
//
|
||||
// Token names are identical to before; System mode still follows the OS
|
||||
// std-widgets Palette (handled inside `theme.slint` via `Theme.is-system`).
|
||||
|
||||
import { Palette } from "palette.slint";
|
||||
import { Palette as StdPalette } from "std-widgets.slint";
|
||||
import { ThemeState } from "theme-state.slint";
|
||||
|
||||
export global Theme {
|
||||
// Surfaces (--bg-primary / --bg-secondary / --bg-tertiary)
|
||||
out property <color> surface-main:
|
||||
ThemeState.mode == 1 ? #000000
|
||||
: ThemeState.mode == 2 ? #1a1b26
|
||||
: ThemeState.mode == 3 ? StdPalette.background
|
||||
: Palette.black-0;
|
||||
out property <color> surface-card:
|
||||
ThemeState.mode == 1 ? #0a0a0a
|
||||
: ThemeState.mode == 2 ? #16161e
|
||||
: ThemeState.mode == 3 ? StdPalette.alternate-background
|
||||
: Palette.black-1;
|
||||
out property <color> surface-elevated:
|
||||
ThemeState.mode == 1 ? #1a1a1a
|
||||
: ThemeState.mode == 2 ? #1c1d29
|
||||
: ThemeState.mode == 3 ? StdPalette.control-background
|
||||
: Palette.black-2;
|
||||
|
||||
// Text (Tokyo Night recolors; OLED keeps the default dark text; System
|
||||
// derives muted tiers from the OS foreground via alpha)
|
||||
out property <color> text-primary:
|
||||
ThemeState.mode == 2 ? #a9b1d6
|
||||
: ThemeState.mode == 3 ? StdPalette.foreground
|
||||
: Palette.white;
|
||||
out property <color> text-secondary:
|
||||
ThemeState.mode == 2 ? #787c99
|
||||
: ThemeState.mode == 3 ? StdPalette.foreground.with-alpha(0.78)
|
||||
: Palette.gray-c;
|
||||
out property <color> text-muted:
|
||||
ThemeState.mode == 2 ? #545c7e
|
||||
: ThemeState.mode == 3 ? StdPalette.foreground.with-alpha(0.55)
|
||||
: Palette.gray-8;
|
||||
out property <color> text-disabled:
|
||||
ThemeState.mode == 2 ? #3d425e
|
||||
: ThemeState.mode == 3 ? StdPalette.foreground.with-alpha(0.35)
|
||||
: Palette.gray-5;
|
||||
|
||||
// Accent (--accent-primary / hover / active / btn-primary-text)
|
||||
out property <color> accent:
|
||||
ThemeState.mode == 2 ? #7aa2f7
|
||||
: ThemeState.mode == 3 ? StdPalette.accent-background
|
||||
: Palette.blue;
|
||||
out property <color> accent-hover:
|
||||
ThemeState.mode == 2 ? #7dcfff
|
||||
: ThemeState.mode == 3 ? StdPalette.accent-background.brighter(0.15)
|
||||
: Palette.blue-hover;
|
||||
out property <color> accent-pressed:
|
||||
ThemeState.mode == 2 ? #bb9af7
|
||||
: ThemeState.mode == 3 ? StdPalette.accent-background.darker(0.15)
|
||||
: Palette.blue-active;
|
||||
out property <color> accent-text:
|
||||
ThemeState.mode == 2 ? #1a1b26
|
||||
: ThemeState.mode == 3 ? StdPalette.accent-foreground
|
||||
: Palette.white;
|
||||
|
||||
// Favorite (heart) — the active "loved" state.
|
||||
out property <color> favorite: Palette.danger;
|
||||
|
||||
// Surfaces — interaction
|
||||
out property <color> surface-hover: Palette.alpha-6;
|
||||
|
||||
// Borders
|
||||
out property <color> border-subtle: Palette.alpha-8;
|
||||
// A more defined border for surfaces that share the content
|
||||
// background and need a visible edge (popover menus, dropdowns).
|
||||
out property <color> border-muted: Palette.alpha-strong;
|
||||
|
||||
// Effects
|
||||
out property <color> card-shadow: Palette.shadow;
|
||||
|
||||
// Alpha-white overlay tiers — mirror the --alpha-* CSS vars in src/app.css.
|
||||
// Fixed white (NOT mode-conditional) to stay 1:1 with the Tauri miniplayer,
|
||||
// which uses fixed white alphas regardless of theme. Consumed by the mini
|
||||
// surfaces/footer/capsule for hover fills, hairlines, and muted glyphs.
|
||||
out property <color> alpha-08: #ffffff14; // 8%
|
||||
out property <color> alpha-10: #ffffff1a; // 10%
|
||||
out property <color> alpha-12: #ffffff1f; // 12%
|
||||
out property <color> alpha-18: #ffffff2e; // 18%
|
||||
out property <color> alpha-55: #ffffff8c; // 55%
|
||||
out property <color> alpha-65: #ffffffa6; // 65%
|
||||
out property <color> alpha-70: #ffffffb3; // 70%
|
||||
out property <color> alpha-75: #ffffffbf; // 75%
|
||||
}
|
||||
export { Theme, ThemeColors } from "theme.slint";
|
||||
@@ -0,0 +1,232 @@
|
||||
// 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;
|
||||
}
|
||||
Reference in new issue
Block a user