a11y: a skip link, color-blind safe charts
i18n::SkipLink holds a Tab stop in flow at zero size, first where it sits, and while focused raises a pill over the page; Enter, Space or a press hands focus to its target. gpui orders stops by tab_index before paint and registers none for an invisible element, so the stop stays in flow and only the pill is raised. Theme::set_color_blind_safe swaps Ely's chart hues for a set fitted to stay apart under Machado's protanopia, deuteranopia and tritanopia; a test holds every pair 0.10 apart in Oklab and each hue 3:1 on its page, and red against green shows the measure bites. KeyboardNavigationHelper points to interaction::RovingFocus. The announcer, labels and screen-reader text stay blocked: gpui 0.2.2 has no accessibility tree, and nothing here is trusted to observe VoiceOver. The i18n tests move under src/i18n/tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff8f4ba84f
commit
6265afbb01
10 files changed
+463
-7
No files matched your search
+19
-2
@@ -62,6 +62,7 @@ impl From<WindowAppearance> for Mode {
|
||||
pub struct Theme {
|
||||
mode: Mode,
|
||||
high_contrast: bool,
|
||||
color_blind_safe: bool,
|
||||
transition: u64,
|
||||
custom: [Option<Palette>; 2],
|
||||
pub colors: Palette,
|
||||
@@ -91,6 +92,7 @@ impl Theme {
|
||||
cx.set_global(Theme {
|
||||
mode: Mode::Light,
|
||||
high_contrast: false,
|
||||
color_blind_safe: false,
|
||||
transition: 0,
|
||||
custom: [None, None],
|
||||
colors: Palette::light(false),
|
||||
@@ -112,6 +114,10 @@ impl Theme {
|
||||
self.high_contrast
|
||||
}
|
||||
|
||||
pub fn color_blind_safe(&self) -> bool {
|
||||
self.color_blind_safe
|
||||
}
|
||||
|
||||
pub fn is_dark(&self) -> bool {
|
||||
self.mode == Mode::Dark
|
||||
}
|
||||
@@ -129,7 +135,14 @@ impl Theme {
|
||||
Self::fade_to_target(cx);
|
||||
}
|
||||
|
||||
/// The owner's palette for `mode`, as an edited or imported theme gives, or none to bring Ely's back. The colors fade to it when `mode` shows. High contrast strengthens Ely's own palettes alone.
|
||||
/// Chart hues that stay apart for color-blind eyes, in Ely's own palettes.
|
||||
pub fn set_color_blind_safe(on: bool, cx: &mut App) {
|
||||
log::info!("theme: color-blind safe charts -> {on}");
|
||||
cx.global_mut::<Theme>().color_blind_safe = on;
|
||||
Self::fade_to_target(cx);
|
||||
}
|
||||
|
||||
/// The owner's palette for `mode`, as an edited or imported theme gives, or none to bring Ely's back. The colors fade to it when `mode` shows. High contrast and color-blind safe charts change Ely's own palettes alone.
|
||||
pub fn set_palette(mode: Mode, palette: Option<Palette>, cx: &mut App) {
|
||||
log::info!(
|
||||
"theme: {mode:?} palette -> {}",
|
||||
@@ -158,10 +171,14 @@ impl Theme {
|
||||
if let Some(palette) = &self.custom[self.mode as usize] {
|
||||
return palette.clone();
|
||||
}
|
||||
match self.mode {
|
||||
let mut palette = match self.mode {
|
||||
Mode::Light => Palette::light(self.high_contrast),
|
||||
Mode::Dark => Palette::dark(self.high_contrast),
|
||||
};
|
||||
if self.color_blind_safe {
|
||||
palette.chart = palette::color_blind_chart(self.mode);
|
||||
}
|
||||
palette
|
||||
}
|
||||
|
||||
fn fade_to_target(cx: &mut App) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use gpui::{Hsla, Rgba, rgb, rgba};
|
||||
|
||||
use super::Mode;
|
||||
|
||||
pub trait Mix {
|
||||
fn mix(&self, to: &Self, t: f32) -> Self;
|
||||
}
|
||||
@@ -142,6 +144,18 @@ pub const HUE_NAMES: [&str; 8] = [
|
||||
"Blue", "Teal", "Ochre", "Rose", "Violet", "Green", "Rust", "Cyan",
|
||||
];
|
||||
|
||||
/// Chart hues each 3:1 on its mode's page that stay apart for protanopia, deuteranopia and tritanopia; `HUE_NAMES` still name them.
|
||||
pub(crate) fn color_blind_chart(mode: Mode) -> [Hsla; 8] {
|
||||
match mode {
|
||||
Mode::Light => c8([
|
||||
0x0240b1, 0x08a399, 0xcd8017, 0x844954, 0xa276e3, 0x184606, 0xb84f10, 0x20789d,
|
||||
]),
|
||||
Mode::Dark => c8([
|
||||
0x3471e3, 0x57b6b2, 0xf6a537, 0xde545a, 0x695a91, 0xc4ecb7, 0xa93d0e, 0x52dafe,
|
||||
]),
|
||||
}
|
||||
}
|
||||
|
||||
impl Palette {
|
||||
/// The chart color at `hue`; a hue past the chart fails, naming `owner`.
|
||||
pub fn hue(&self, hue: usize, owner: impl std::fmt::Display) -> Hsla {
|
||||
|
||||
Reference in new issue
Block a user