feat(a11y): add Theme.is-high-contrast flag to gate HC-only borders
P4 foundation for the redundant-encoding accessibility pass. Adds a single flag that High-Contrast-only affordances (1px control borders, slider-thumb borders) read so they never leak into the polished normal themes, mirroring the existing is-system wiring. - qbz-theme: `pub fn is_high_contrast(id)` at the crate root next to `is_light` (true for HighContrast + HighContrastLight), with a unit test `high_contrast_flag_only_for_hc_themes` asserting exactly the two HC themes. - qbz-slint theme.slint: `in-out property <bool> is-high-contrast: false;` beside is-system; re-exported via semantic-colors.slint so all ~145 components get `Theme.is-high-contrast` with no per-file import change. Embedded the canonical HC border gate and the non-layout focus-ring snippet as a comment for the cluster agents to copy verbatim. - qbz-slint theme.rs: apply_theme sets it via `qbz_theme::is_high_contrast(id)`. cc
This commit is contained in:
3 files changed
+45
No files matched your search
@@ -97,6 +97,7 @@ pub fn apply_theme(window: &AppWindow, id: ThemeId) {
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,26 @@ export global Theme {
|
||||
// std-Palette fallback for the System-overridden tokens below.
|
||||
in-out property <bool> 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 <bool> is-high-contrast: 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;
|
||||
|
||||
@@ -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<ThemeListEntry> {
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user