diff --git a/crates/qbz-slint/src/theme.rs b/crates/qbz-slint/src/theme.rs index 1ff306d98..586ab098d 100644 --- a/crates/qbz-slint/src/theme.rs +++ b/crates/qbz-slint/src/theme.rs @@ -97,6 +97,7 @@ pub fn apply_theme(window: &AppWindow, id: ThemeId) { let theme = window.global::(); 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()); } diff --git a/crates/qbz-slint/ui/foundation/theme.slint b/crates/qbz-slint/ui/foundation/theme.slint index b09148fb5..d1e6bc94f 100644 --- a/crates/qbz-slint/ui/foundation/theme.slint +++ b/crates/qbz-slint/ui/foundation/theme.slint @@ -151,6 +151,26 @@ export global Theme { // 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; diff --git a/crates/qbz-theme/src/lib.rs b/crates/qbz-theme/src/lib.rs index af0534c9e..daf8511bb 100644 --- a/crates/qbz-theme/src/lib.rs +++ b/crates/qbz-theme/src/lib.rs @@ -54,6 +54,14 @@ pub fn is_light(id: ThemeId) -> bool { relative_luminance(palette(id).surface_main) >= 0.5 } +/// Whether a theme is one of the two High-Contrast accessibility themes. +/// Drives the Slint `Theme.is-high-contrast` flag, which gates HC-only +/// redundant-encoding affordances (1px control borders, slider-thumb borders) +/// so they never leak into the polished normal themes (P4 a11y pass). +pub fn is_high_contrast(id: ThemeId) -> bool { + matches!(id, ThemeId::HighContrast | ThemeId::HighContrastLight) +} + /// Build the full Settings theme list in display order. The frontend filters by /// `is_light` and may hide `!implemented` rows during P1/P2. pub fn theme_list() -> Vec { @@ -145,4 +153,20 @@ mod tests { fn full_list_has_all_entries() { assert_eq!(theme_list().len(), ALL.len()); } + + #[test] + fn high_contrast_flag_only_for_hc_themes() { + // True for exactly the two High-Contrast themes. + assert!(is_high_contrast(ThemeId::HighContrast)); + assert!(is_high_contrast(ThemeId::HighContrastLight)); + // False for everything else, including the other a11y themes. + assert!(!is_high_contrast(ThemeId::WcagLight)); + assert!(!is_high_contrast(ThemeId::WcagDark)); + assert!(!is_high_contrast(ThemeId::Colorblind)); + assert!(!is_high_contrast(ThemeId::Dark)); + assert!(!is_high_contrast(ThemeId::Oled)); + assert!(!is_high_contrast(ThemeId::System)); + // Exactly two themes in ALL are high-contrast. + assert_eq!(ALL.iter().filter(|&&id| is_high_contrast(id)).count(), 2); + } }