merge: integrate Tauri->Slint theme migration + a11y redesign

33 themes via Rust-driven qbz-theme registry, theme persistence + OLED
default, 6 redesigned accessibility themes (WCAG AAA, High Contrast x2,
Okabe-Ito colorblind) with contrast unit tests, and the P4
redundant-encoding pass (focus rings, HC-gated borders, tokenized status
colors). Branch feature/slint-themes-a11y.

cc

# Conflicts:
#	crates/qbz-slint/src/main.rs
#	crates/qbz-slint/src/ui_prefs.rs
This commit is contained in:
vicrodh committed 2026-06-20 17:47:06 -06:00
commit d0deeb7044
41 files changed
+3427 -150

No files matched your search

+37 -1
View File
@@ -103,6 +103,7 @@ mod settings;
mod share;
mod sidebar;
mod suggestions;
mod theme;
mod toast;
mod tray;
mod tray_settings;
@@ -4445,6 +4446,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
),
);
// Theme: seed the dropdown list from the Rust registry, then restore the
// persisted theme (slug is the source of truth; the dropdown index is
// derived). Fresh profiles default to OLED Dark (owner decision). This must
// run before the shell renders so the first paint is the right palette.
{
let appearance = window.global::<AppearanceState>();
let labels: Vec<slint::SharedString> = crate::theme::dropdown_labels()
.into_iter()
.map(slint::SharedString::from)
.collect();
appearance.set_themes(slint::ModelRc::new(slint::VecModel::from(labels)));
let id = crate::theme::id_for_slug(&crate::ui_prefs::load().theme);
appearance.set_theme_index(crate::theme::index_for_id(id));
appearance.set_theme_is_system(id == qbz_theme::ThemeId::System);
// Keep the legacy ThemeState.mode in sync with the dropdown index for
// any residual reads; the palette itself is driven by apply_theme.
window
.global::<ThemeState>()
.set_mode(crate::theme::index_for_id(id));
crate::theme::apply_theme(&window, id);
}
// Tell the tray settings UI which platform it's on so it can show the
// macOS-only controls ("Menu Bar" header, hide-Dock toggle) and hide the
// Linux/Windows-only minimize-to-tray row.
@@ -6163,7 +6187,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"tray-mac-hide-dock" => tray_settings::set_mac_hide_dock(value),
other => log::debug!("[qbz-slint] unhandled appearance-bool '{other}'"),
});
appearance.on_appearance_select(|key, index| match key.as_str() {
let theme_weak = window.as_weak();
appearance.on_appearance_select(move |key, index| match key.as_str() {
"tray-icon-theme" => {
tray_settings::set_icon_theme_index(index);
// Re-theme the running tray icon live (no restart).
@@ -6178,6 +6203,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
crate::ui_prefs::immersive_search_action_for_index(index).to_string();
crate::ui_prefs::save(&prefs);
}
"theme" => {
// Slug is the source of truth: map the dropdown index -> stable
// id, persist the slug, then hot-switch the live palette.
let id = crate::theme::id_for_index(index);
let mut prefs = crate::ui_prefs::load();
prefs.theme = id.slug().to_string();
crate::ui_prefs::save(&prefs);
if let Some(w) = theme_weak.upgrade() {
crate::theme::apply_theme(&w, id);
}
}
other => log::debug!("[qbz-slint] unhandled appearance-select '{other}'"),
});
}
+171
View File
@@ -0,0 +1,171 @@
//! Theme application: bridge the frontend-agnostic `qbz-theme` registry to the
//! Slint `Theme` global.
//!
//! `qbz-theme` owns all palette data (ADR-006). This module is the only place
//! that knows about both `qbz_theme::Rgba` and the generated Slint `ThemeColors`
//! struct: it converts one to the other and pushes it into `Theme.c`, plus sets
//! the `Theme.is-system` flag so the System theme keeps following the OS.
//!
//! The dropdown shows a filtered/ordered list of themes; the stable slug is the
//! source of truth (persisted in `ui_prefs.theme`), and the dropdown index is
//! DERIVED from it — never the reverse.
use crate::{AppWindow, Theme as SlintTheme, ThemeColors as SlintThemeColors};
use qbz_theme::{Rgba, ThemeId};
use slint::{Color, ComponentHandle};
/// Convert a registry `Rgba` to a Slint `Color` (straight alpha).
fn to_color(c: Rgba) -> Color {
Color::from_argb_u8(c.a, c.r, c.g, c.b)
}
/// Build the generated Slint `ThemeColors` from a registry `ThemeColors`.
fn to_slint(c: &qbz_theme::ThemeColors) -> SlintThemeColors {
SlintThemeColors {
surface_main: to_color(c.surface_main),
surface_card: to_color(c.surface_card),
surface_elevated: to_color(c.surface_elevated),
surface_hover: to_color(c.surface_hover),
bg_hover: to_color(c.bg_hover),
text_primary: to_color(c.text_primary),
text_secondary: to_color(c.text_secondary),
text_muted: to_color(c.text_muted),
text_disabled: to_color(c.text_disabled),
accent: to_color(c.accent),
accent_hover: to_color(c.accent_hover),
accent_pressed: to_color(c.accent_pressed),
accent_text: to_color(c.accent_text),
danger: to_color(c.danger),
danger_bg: to_color(c.danger_bg),
danger_border: to_color(c.danger_border),
danger_hover: to_color(c.danger_hover),
warning: to_color(c.warning),
warning_bg: to_color(c.warning_bg),
warning_border: to_color(c.warning_border),
warning_hover: to_color(c.warning_hover),
success: to_color(c.success),
success_bg: to_color(c.success_bg),
success_border: to_color(c.success_border),
success_hover: to_color(c.success_hover),
border_subtle: to_color(c.border_subtle),
border_muted: to_color(c.border_muted),
border_strong: to_color(c.border_strong),
focus_ring: to_color(c.focus_ring),
favorite: to_color(c.favorite),
card_shadow: to_color(c.card_shadow),
alpha_4: to_color(c.alpha_pct(4)),
alpha_5: to_color(c.alpha_pct(5)),
alpha_6: to_color(c.alpha_pct(6)),
alpha_8: to_color(c.alpha_pct(8)),
alpha_10: to_color(c.alpha_pct(10)),
alpha_12: to_color(c.alpha_pct(12)),
alpha_15: to_color(c.alpha_pct(15)),
alpha_18: to_color(c.alpha_pct(18)),
alpha_20: to_color(c.alpha_pct(20)),
alpha_25: to_color(c.alpha_pct(25)),
alpha_30: to_color(c.alpha_pct(30)),
alpha_35: to_color(c.alpha_pct(35)),
alpha_40: to_color(c.alpha_pct(40)),
alpha_45: to_color(c.alpha_pct(45)),
alpha_50: to_color(c.alpha_pct(50)),
alpha_55: to_color(c.alpha_pct(55)),
alpha_60: to_color(c.alpha_pct(60)),
alpha_65: to_color(c.alpha_pct(65)),
alpha_70: to_color(c.alpha_pct(70)),
alpha_75: to_color(c.alpha_pct(75)),
alpha_80: to_color(c.alpha_pct(80)),
alpha_85: to_color(c.alpha_pct(85)),
alpha_90: to_color(c.alpha_pct(90)),
alpha_95: to_color(c.alpha_pct(95)),
}
}
/// Push the palette for `id` into the running window's `Theme` global. Sets
/// `is-system` so the System theme follows the OS (the struct is still pushed as
/// a sane fallback for any non-System-overridden tokens).
pub fn apply_theme(window: &AppWindow, id: ThemeId) {
let colors = qbz_theme::palette(id);
let theme = window.global::<SlintTheme>();
theme.set_c(to_slint(&colors));
theme.set_is_system(id == ThemeId::System);
theme.set_is_high_contrast(qbz_theme::is_high_contrast(id));
log::info!("[qbz-slint] applied theme '{}'", id.slug());
}
/// The themes shown in the Settings dropdown, in display order. P1 exposes only
/// the implemented rows. The dropdown index is just a position in THIS list.
pub fn dropdown_themes() -> Vec<ThemeId> {
qbz_theme::implemented_theme_list()
.into_iter()
.map(|e| e.id)
.collect()
}
/// Display names for the dropdown, matching [`dropdown_themes`] order.
pub fn dropdown_labels() -> Vec<String> {
dropdown_themes()
.into_iter()
.map(|id| id.display_name().to_string())
.collect()
}
/// Map a persisted slug to a `ThemeId`, falling back to the default (OLED) when
/// the slug is unknown or absent.
pub fn id_for_slug(slug: &str) -> ThemeId {
ThemeId::from_slug(slug).unwrap_or_else(qbz_theme::default_theme_id)
}
/// Map a dropdown index to a `ThemeId`. Out-of-range indices fall back to the
/// default theme.
pub fn id_for_index(index: i32) -> ThemeId {
let list = dropdown_themes();
list.get(index as usize)
.copied()
.unwrap_or_else(qbz_theme::default_theme_id)
}
/// Derive the dropdown index for a `ThemeId` (position in [`dropdown_themes`]).
/// Returns `0` if the id is not in the dropdown list (e.g. a P2/P3 theme not yet
/// exposed) — the caller should treat that as "no explicit selection".
pub fn index_for_id(id: ThemeId) -> i32 {
dropdown_themes()
.iter()
.position(|&t| t == id)
.map(|p| p as i32)
.unwrap_or(0)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn slug_index_roundtrip_for_p1() {
for (i, id) in dropdown_themes().into_iter().enumerate() {
assert_eq!(index_for_id(id), i as i32);
assert_eq!(id_for_index(i as i32), id);
assert_eq!(id_for_slug(id.slug()), id);
}
}
#[test]
fn unknown_slug_falls_back_to_oled() {
assert_eq!(id_for_slug("nope"), ThemeId::Oled);
assert_eq!(id_for_slug(""), ThemeId::Oled);
}
#[test]
fn out_of_range_index_falls_back_to_default() {
assert_eq!(id_for_index(9999), qbz_theme::default_theme_id());
assert_eq!(id_for_index(-1), qbz_theme::default_theme_id());
}
}
+21
View File
@@ -96,6 +96,11 @@ pub struct UiPrefs {
/// inert). See [`DEFAULT_IMMERSIVE_SEARCH_ACTION`].
#[serde(default = "default_immersive_search_action")]
pub immersive_search_action: String,
/// Active theme — a stable `qbz_theme::ThemeId` slug ("oled", "dark",
/// "tokyo-night", "system", ...). Stored as a slug (not an index) so it is
/// order-independent and stable across releases. Owner default: OLED Dark.
#[serde(default = "default_theme")]
pub theme: String,
// ---- Miniplayer ----------------------------------------------------
/// Last miniplayer surface: 0 micro · 1 compact · 2 artwork · 3 queue · 4 lyrics.
@@ -147,6 +152,13 @@ fn default_immersive_search_action() -> String {
DEFAULT_IMMERSIVE_SEARCH_ACTION.to_string()
}
/// Default theme slug. Owner decision 2026-06-20: OLED Dark is the default for
/// fresh installs and any profile without a persisted theme. Sourced from the
/// `qbz-theme` registry so the default stays single-sourced.
fn default_theme() -> String {
qbz_theme::default_slug().to_string()
}
impl Default for UiPrefs {
fn default() -> Self {
Self {
@@ -155,6 +167,7 @@ impl Default for UiPrefs {
album_header_gradient: default_album_header_gradient(),
intelligent_search: default_intelligent_search(),
immersive_search_action: default_immersive_search_action(),
theme: default_theme(),
mini_surface: default_mini_surface(),
mini_width: default_mini_width(),
mini_height: default_mini_height(),
@@ -254,5 +267,13 @@ mod tests {
let prefs: UiPrefs = serde_json::from_str("{}").expect("empty object deserializes");
assert_eq!(prefs.streaming_quality, "hires_plus");
assert!(prefs.album_header_gradient);
// A profile that predates the theme field falls back to OLED.
assert_eq!(prefs.theme, "oled");
}
#[test]
fn default_theme_is_oled() {
assert_eq!(UiPrefs::default().theme, "oled");
assert_eq!(default_theme(), "oled");
}
}