diff --git a/crates/horizon-theme/src/lib.rs b/crates/horizon-theme/src/lib.rs index ec54a3699..3ed778c7f 100644 --- a/crates/horizon-theme/src/lib.rs +++ b/crates/horizon-theme/src/lib.rs @@ -271,8 +271,18 @@ pub const DARK: Palette = Palette { dark: true, }; -/// How strongly the game's menus veil the live title backdrop with the page colour. -pub const VEIL: f32 = 0.86; +/// How strongly the game's menus veil the live backdrop (the title panorama, or the world behind +/// the pause and options screens) with the page colour. Every text colour the menus use keeps +/// WCAG AA over it, even on a selected row's plate, with a backdrop as bright as +/// [`BRIGHT_BACKDROP`] (a test checks it). +pub const VEIL: f32 = 0.90; +/// The title's home page shows more of the world; its text is `ink` and `ink_soft` only. +pub const HOME_VEIL: f32 = 0.80; +/// Muted text over the veiled backdrop: the dark palette's `muted`, lifted so it holds AA there. +pub const BACKDROP_MUTED: u32 = 0x9fa3ae; +/// The brightest backdrop the veils are measured against: a light grey of luminance 0.77, +/// brighter than the snowiest title panorama measured (0.49) and a sunlit world. +pub const BRIGHT_BACKDROP: u32 = 0xe3e3e3; impl Palette { /// Every colour with its token name, in the order the docs list them. @@ -444,6 +454,36 @@ mod tests { } } + /// The game's menus over the brightest backdrop: the page colour veiled over it, and a + /// selected row's plate (ink at 8 %) on top. + #[test] + fn menu_text_meets_wcag_aa_over_a_bright_backdrop() { + let mix = |a: u32, b: u32, t: f32| { + [16, 8, 0].iter().fold(0, |out, s| { + let (x, y) = (((a >> s) & 255) as f32, ((b >> s) & 255) as f32); + out | ((x * (1. - t) + y * t).round() as u32) << s + }) + }; + let p = DARK; + for (veil, texts) in [ + ( + VEIL, + &[p.ink, p.ink_soft, BACKDROP_MUTED, p.danger, p.success][..], + ), + (HOME_VEIL, &[p.ink, p.ink_soft][..]), + ] { + let bg = mix(BRIGHT_BACKDROP, p.page, veil); + let plate = mix(bg, p.ink, 0.08); + for &text in texts { + for under in [bg, plate] { + let ratio = contrast(text, under); + assert!(ratio >= 4.5, "#{text:06x} over veil {veil}: {ratio:.2}"); + } + } + } + assert!(contrast(BACKDROP_MUTED, p.page) >= 4.5); + } + #[test] fn contrast_matches_known_values() { assert!((contrast(0x000000, 0xffffff) - 21.).abs() < 0.01); diff --git a/docs/design-system.md b/docs/design-system.md index d61aff351..7a93fb806 100644 --- a/docs/design-system.md +++ b/docs/design-system.md @@ -55,7 +55,11 @@ Every text colour passes WCAG AA (4.5:1) on every background it is used on; the | `success` | `#1d7a48` | `#45c27a` | "Matches vanilla", "Ready" | The game's menus draw over the live title backdrop, always in the dark palette, with the page -colour as a veil (`VEIL`, 0.86) so text keeps its contrast whatever the world shows. +colour as a flat veil so text keeps its contrast whatever the world shows: `VEIL` (0.90) on +every page and in a world, `HOME_VEIL` (0.80) on the title's home page, which shows more of the +world and keeps to `ink` and `ink_soft`. Muted text over the backdrop is `BACKDROP_MUTED` +(`#9fa3ae`). A test holds every pair to AA over a backdrop of luminance 0.77 (the snowiest title +panorama measured reaches 0.49), on the bare veil and on a selected row's plate. ### Type