mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
theme: dark-mode accent buttons show a visible hover (wordcraft#7317 C7-14) (#3124)
* theme: dark-mode accent buttons show a visible hover (wordcraft#7317 C7-14) accent.strong_hover/pressed offset the rest fill by the ramp distance from accent.solid to accent.hover/pressed. A light dark-mode seed leaves those ramp steps 0.01 OKLCH-L apart, so the hover was invisible; and a fill near white or black clamped. The offset now has a floor (hover 0.06, pressed 0.10) and flips toward the text when there is no room away from it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE * theme: explain names the shift's floor and flip Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE * wordcraft#7317 C7-14: test that explaining the dark accent hover names its base and its lightness floor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5c5e0d52c3
commit
ee01a2b421
+14
-10
@@ -201,8 +201,8 @@ fn derived_values(unpinned: &ColorTokens, before_pass: &ColorTokens, pinned: &BT
|
||||
}
|
||||
Source::Same(other) | Source::SolidFrom(other) => unpinned.get(other),
|
||||
Source::Faded(other, a) => unpinned.get(other).with_alpha(a),
|
||||
Source::ShiftedFrom { base, from, to, away_from } => {
|
||||
shifted(unpinned.get(base), unpinned.get(from), unpinned.get(to), unpinned.get(away_from))
|
||||
Source::ShiftedFrom { base, from, to, away_from, min } => {
|
||||
shifted(unpinned.get(base), unpinned.get(from), unpinned.get(to), unpinned.get(away_from), min)
|
||||
}
|
||||
// Lit like the anchored greys: from the panel's own value, pinned or not.
|
||||
Source::Lighting(amount) => lighting(before_pass.surface.panel, amount),
|
||||
@@ -411,8 +411,8 @@ fn follow(c: &mut ColorTokens, ramp: &ColorTokens, pinned: &BTreeSet<ColorToken>
|
||||
Source::Faded(other, a) => c.set(t, c.get(other).with_alpha(a)),
|
||||
Source::Lighting(amount) => c.set(t, lighting(c.surface.panel, amount)),
|
||||
Source::SolidFrom(other) if on_solid => c.set(t, c.get(other)),
|
||||
Source::ShiftedFrom { base, from, to, away_from } if on_solid => {
|
||||
c.set(t, shifted(c.get(base), ramp.get(from), ramp.get(to), c.get(away_from)))
|
||||
Source::ShiftedFrom { base, from, to, away_from, min } if on_solid => {
|
||||
c.set(t, shifted(c.get(base), ramp.get(from), ramp.get(to), c.get(away_from), min))
|
||||
}
|
||||
Source::OnSolid(solids) if on_solid => c.set(t, best_extreme(c, solids)),
|
||||
_ => {}
|
||||
@@ -435,11 +435,15 @@ fn lighting(panel: Rgba, amount: f64) -> Rgba {
|
||||
}
|
||||
|
||||
/// `base` with its OKLCH lightness moved by the distance between `from` and `to`, away from
|
||||
/// `text`: darker under lighter text, lighter under darker. Clamped to 0..=1, hue and chroma kept.
|
||||
fn shifted(base: Rgba, from: Rgba, to: Rgba, text: Rgba) -> Rgba {
|
||||
/// `text`: darker under lighter text, lighter under darker, by at least `min`. Toward `text` instead when there is no room. Clamped to 0..=1, hue and chroma kept.
|
||||
fn shifted(base: Rgba, from: Rgba, to: Rgba, text: Rgba, min: f64) -> Rgba {
|
||||
let o = base.to_oklch();
|
||||
let step = (to.to_oklch().l - from.to_oklch().l).abs();
|
||||
let sign = if relative_luminance(text) >= relative_luminance(base) { -1.0 } else { 1.0 };
|
||||
let step = (to.to_oklch().l - from.to_oklch().l).abs().max(min);
|
||||
let mut sign = if relative_luminance(text) >= relative_luminance(base) { -1.0 } else { 1.0 };
|
||||
// A base too close to white or black to move that far away from the text moves toward it.
|
||||
if !(0.0..=1.0).contains(&(o.l + sign * step)) {
|
||||
sign = -sign;
|
||||
}
|
||||
Oklch { l: (o.l + sign * step).clamp(0.0, 1.0), ..o }.to_rgba().with_alpha(base.a())
|
||||
}
|
||||
|
||||
@@ -512,8 +516,8 @@ fn fix_rule(c: &mut ColorTokens, pass: &Pass, rule: &PairRule, done: &[PairRule]
|
||||
{
|
||||
match values::source(t, pass.mode) {
|
||||
Source::SolidFrom(other) => c.set(t, c.get(other)),
|
||||
Source::ShiftedFrom { base, from, to, away_from } => {
|
||||
c.set(t, shifted(c.get(base), pass.ramp.get(from), pass.ramp.get(to), c.get(away_from)));
|
||||
Source::ShiftedFrom { base, from, to, away_from, min } => {
|
||||
c.set(t, shifted(c.get(base), pass.ramp.get(from), pass.ramp.get(to), c.get(away_from), min));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -126,9 +126,13 @@ fn source_words(source: ColorSource, anchored_on: Option<ColorToken>) -> String
|
||||
ColorSource::Fixed(c) => format!("fixed {}", c.to_hex()),
|
||||
ColorSource::Oklch(l, c, h) => format!("oklch {l} {c} {h}"),
|
||||
ColorSource::Same(t) | ColorSource::SolidFrom(t) => format!("= {}", t.path()),
|
||||
ColorSource::ShiftedFrom { base, from, to, away_from } => {
|
||||
format!("= {} moved away from {} as far as {} lies from {}", base.path(), away_from.path(), to.path(), from.path())
|
||||
}
|
||||
ColorSource::ShiftedFrom { base, from, to, away_from, min } => format!(
|
||||
"= {} moved away from {} as far as {} lies from {}, at least {min} lightness (toward it when there is no room)",
|
||||
base.path(),
|
||||
away_from.path(),
|
||||
to.path(),
|
||||
from.path()
|
||||
),
|
||||
ColorSource::OnSolid([only]) => format!("white or black on {}", only.path()),
|
||||
ColorSource::OnSolid(solids) => match solids.first() {
|
||||
Some(first) => format!("white or black on {} and {} more solids", first.path(), solids.len() - 1),
|
||||
|
||||
@@ -98,6 +98,9 @@ pub enum ColorSource {
|
||||
to: ColorToken,
|
||||
/// The text the fill moves away from.
|
||||
away_from: ColorToken,
|
||||
/// The least OKLCH lightness distance from `base`, so a variant under a seed whose ramp
|
||||
/// steps lie close together (a light dark-mode accent) still shows.
|
||||
min: f64,
|
||||
},
|
||||
/// White or black, whichever has the higher lowest contrast on all of these tokens.
|
||||
OnSolid(&'static [ColorToken]),
|
||||
@@ -137,6 +140,11 @@ const SOLID_HOVER: usize = 10;
|
||||
/// `status.<s>.solid_pressed`).
|
||||
const SOLID_PRESSED: (usize, usize, f64) = (10, 11, 0.5);
|
||||
|
||||
/// The least OKLCH lightness a hovered `accent.strong` moves from rest, and a pressed one. The
|
||||
/// dark ramp's steps 9 and 10 lie 0.01 apart for a light seed, which hides the hover.
|
||||
const STRONG_HOVER_MIN: f64 = 0.06;
|
||||
const STRONG_PRESSED_MIN: f64 = 0.10;
|
||||
|
||||
/// How far a bevel's lit edge (`edge.light`) lies above `surface.panel` in OKLCH lightness, in
|
||||
/// either mode. Windows 2000's #d4d0c8 face (L 0.86) has a white lit edge.
|
||||
pub const BEVEL_LIT: f64 = 0.15;
|
||||
@@ -225,8 +233,12 @@ pub(super) fn source(token: ColorToken, mode: Mode) -> ColorSource {
|
||||
T::AccentHover => Accent(SOLID_HOVER),
|
||||
T::AccentPressed => AccentMix { from: pressed_from, to: pressed_to, t: pressed_t },
|
||||
T::AccentStrong => SolidFrom(T::AccentSolid),
|
||||
T::AccentStrongHover => ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentHover, away_from: T::TextOnStrong },
|
||||
T::AccentStrongPressed => ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentPressed, away_from: T::TextOnStrong },
|
||||
T::AccentStrongHover => {
|
||||
ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentHover, away_from: T::TextOnStrong, min: STRONG_HOVER_MIN }
|
||||
}
|
||||
T::AccentStrongPressed => {
|
||||
ShiftedFrom { base: T::AccentStrong, from: T::AccentSolid, to: T::AccentPressed, away_from: T::TextOnStrong, min: STRONG_PRESSED_MIN }
|
||||
}
|
||||
T::AccentSoft => Accent(pick(4, 3)),
|
||||
T::AccentBorder => Same(T::AccentSolid),
|
||||
T::AccentText => Accent(11),
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #0058adff
|
||||
accent.hover = #0058adff
|
||||
accent.pressed = #0958abff
|
||||
accent.strong = #0058adff
|
||||
accent.strong_hover = #004c98ff
|
||||
accent.strong_pressed = #004182ff
|
||||
accent.strong_hover = #00488fff
|
||||
accent.strong_pressed = #003d7cff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #486c99ff
|
||||
accent.text = #034d98ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #0058adff
|
||||
accent.hover = #0058adff
|
||||
accent.pressed = #0958abff
|
||||
accent.strong = #0058adff
|
||||
accent.strong_hover = #004c98ff
|
||||
accent.strong_pressed = #004182ff
|
||||
accent.strong_hover = #00488fff
|
||||
accent.strong_pressed = #003d7cff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #486c99ff
|
||||
accent.text = #034d98ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3584e4ff
|
||||
accent.hover = #2977d3ff
|
||||
accent.pressed = #226abeff
|
||||
accent.strong = #2676d5ff
|
||||
accent.strong_hover = #1569c7ff
|
||||
accent.strong_pressed = #005bb6ff
|
||||
accent.strong_hover = #0b63c1ff
|
||||
accent.strong_pressed = #0058b0ff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #3584e482
|
||||
accent.text = #1b5daaff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3584e4ff
|
||||
accent.hover = #2977d3ff
|
||||
accent.pressed = #226abeff
|
||||
accent.strong = #2676d5ff
|
||||
accent.strong_hover = #1569c7ff
|
||||
accent.strong_pressed = #005bb6ff
|
||||
accent.strong_hover = #0b63c1ff
|
||||
accent.strong_pressed = #0058b0ff
|
||||
accent.soft = #3584e428
|
||||
accent.border = #3584e482
|
||||
accent.text = #1b5daaff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #bbdaffff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #405b7aff
|
||||
accent.strong_hover = #3d5877ff
|
||||
accent.strong_pressed = #375170ff
|
||||
accent.strong_hover = #304a68ff
|
||||
accent.strong_pressed = #26405dff
|
||||
accent.soft = #595959ff
|
||||
accent.border = #bbdaffff
|
||||
accent.text = #ffffffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #bbdaffff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #405b7aff
|
||||
accent.strong_hover = #3d5877ff
|
||||
accent.strong_pressed = #375170ff
|
||||
accent.strong_hover = #304a68ff
|
||||
accent.strong_pressed = #26405dff
|
||||
accent.soft = #595959ff
|
||||
accent.border = #bbdaffff
|
||||
accent.text = #ffffffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #1674d4ff
|
||||
accent.strong_pressed = #066ccbff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #6e6e6eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #bad6ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #7cb0f8ff
|
||||
accent.pressed = #88b8fcff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #1674d4ff
|
||||
accent.strong_pressed = #066ccbff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #6e6e6eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #bad6ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #005d92ff
|
||||
accent.strong_hover = #005a8eff
|
||||
accent.strong_pressed = #004e7cff
|
||||
accent.strong_hover = #004c78ff
|
||||
accent.strong_pressed = #004168ff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #5199c2ff
|
||||
accent.text = #59c1f7ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #005d92ff
|
||||
accent.strong_hover = #005a8eff
|
||||
accent.strong_pressed = #004e7cff
|
||||
accent.strong_hover = #004c78ff
|
||||
accent.strong_pressed = #004168ff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #5199c2ff
|
||||
accent.text = #59c1f7ff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #1e76b0ff
|
||||
accent.strong_hover = #1a73adff
|
||||
accent.strong_pressed = #00669fff
|
||||
accent.strong_hover = #00649cff
|
||||
accent.strong_pressed = #00588aff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #3aace8a0
|
||||
accent.text = #50b8eeff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #3aace8ff
|
||||
accent.hover = #42afeaff
|
||||
accent.pressed = #5bbcf4ff
|
||||
accent.strong = #1e76b0ff
|
||||
accent.strong_hover = #1a73adff
|
||||
accent.strong_pressed = #00669fff
|
||||
accent.strong_hover = #00649cff
|
||||
accent.strong_pressed = #00588aff
|
||||
accent.soft = #3aace828
|
||||
accent.border = #3aace8a0
|
||||
accent.text = #50b8eeff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #5394feff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #1354b9ff
|
||||
accent.strong_hover = #054aaeff
|
||||
accent.strong_pressed = #003a90ff
|
||||
accent.strong_hover = #0042a2ff
|
||||
accent.strong_pressed = #00398dff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #5394feff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #5394feff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #1354b9ff
|
||||
accent.strong_hover = #054aaeff
|
||||
accent.strong_pressed = #003a90ff
|
||||
accent.strong_hover = #0042a2ff
|
||||
accent.strong_pressed = #00398dff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #5394feff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #4b8bf5ff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #3573dbff
|
||||
accent.strong_hover = #2b69d0ff
|
||||
accent.strong_pressed = #1856bbff
|
||||
accent.strong_hover = #2360c7ff
|
||||
accent.strong_pressed = #1554b9ff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #4b8bf5ff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #4b8bf5ff
|
||||
accent.hover = #5796feff
|
||||
accent.pressed = #78abffff
|
||||
accent.strong = #3573dbff
|
||||
accent.strong_hover = #2b69d0ff
|
||||
accent.strong_pressed = #1856bbff
|
||||
accent.strong_hover = #2360c7ff
|
||||
accent.strong_pressed = #1554b9ff
|
||||
accent.soft = #12284cff
|
||||
accent.border = #4b8bf5ff
|
||||
accent.text = #98bfffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #60a9ffff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #0359a8ff
|
||||
accent.strong_hover = #004f97ff
|
||||
accent.strong_pressed = #003f7bff
|
||||
accent.strong_hover = #00498cff
|
||||
accent.strong_pressed = #003e79ff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #60a9ffff
|
||||
accent.text = #add1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #60a9ffff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #0359a8ff
|
||||
accent.strong_hover = #004f97ff
|
||||
accent.strong_pressed = #003f7bff
|
||||
accent.strong_hover = #00498cff
|
||||
accent.strong_pressed = #003e79ff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #60a9ffff
|
||||
accent.text = #add1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #056bcaff
|
||||
accent.strong_pressed = #005baeff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #8fc1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #056bcaff
|
||||
accent.strong_pressed = #005baeff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #8fc1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #378ef0ff
|
||||
accent.hover = #469afbff
|
||||
accent.pressed = #6caefdff
|
||||
accent.strong = #1b77d7ff
|
||||
accent.strong_hover = #056bcaff
|
||||
accent.strong_pressed = #005baeff
|
||||
accent.strong_hover = #0065c0ff
|
||||
accent.strong_pressed = #005aacff
|
||||
accent.soft = #4e4e4eff
|
||||
accent.border = #378ef0ff
|
||||
accent.text = #8fc1ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #97a8f7ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #4251abff
|
||||
accent.strong_hover = #404ea8ff
|
||||
accent.strong_pressed = #35429aff
|
||||
accent.strong_hover = #333f98ff
|
||||
accent.strong_pressed = #2a338bff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #9eaadfff
|
||||
accent.text = #cbd4ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #97a8f7ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #4251abff
|
||||
accent.strong_hover = #404ea8ff
|
||||
accent.strong_pressed = #35429aff
|
||||
accent.strong_hover = #333f98ff
|
||||
accent.strong_pressed = #2a338bff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #9eaadfff
|
||||
accent.text = #cbd4ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8a9ae8ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #5668c4ff
|
||||
accent.strong_hover = #5465c1ff
|
||||
accent.strong_pressed = #4859b3ff
|
||||
accent.strong_hover = #4656b0ff
|
||||
accent.strong_pressed = #3c4aa3ff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #8a9ae896
|
||||
accent.text = #bec8fcff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8a9ae8ff
|
||||
accent.hover = #8d9deaff
|
||||
accent.pressed = #9babf4ff
|
||||
accent.strong = #5668c4ff
|
||||
accent.strong_hover = #5465c1ff
|
||||
accent.strong_pressed = #4859b3ff
|
||||
accent.strong_hover = #4656b0ff
|
||||
accent.strong_pressed = #3c4aa3ff
|
||||
accent.soft = #8a9ae830
|
||||
accent.border = #8a9ae896
|
||||
accent.text = #bec8fcff
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #4551a5ff
|
||||
accent.hover = #4552a4ff
|
||||
accent.pressed = #46539fff
|
||||
accent.strong = #4151acff
|
||||
accent.strong_hover = #33409aff
|
||||
accent.strong_hover = #323f99ff
|
||||
accent.strong_pressed = #29338bff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6069a1ff
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #4551a5ff
|
||||
accent.hover = #4552a4ff
|
||||
accent.pressed = #46539fff
|
||||
accent.strong = #4151acff
|
||||
accent.strong_hover = #33409aff
|
||||
accent.strong_hover = #323f99ff
|
||||
accent.strong_pressed = #29338bff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6069a1ff
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #6e80d8ff
|
||||
accent.hover = #5f6fc4ff
|
||||
accent.pressed = #5463b0ff
|
||||
accent.strong = #5062beff
|
||||
accent.strong_hover = #4151abff
|
||||
accent.strong_hover = #4050aaff
|
||||
accent.strong_pressed = #36449dff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6e80d8aa
|
||||
|
||||
@@ -29,7 +29,7 @@ accent.solid = #6e80d8ff
|
||||
accent.hover = #5f6fc4ff
|
||||
accent.pressed = #5463b0ff
|
||||
accent.strong = #5062beff
|
||||
accent.strong_hover = #4151abff
|
||||
accent.strong_hover = #4050aaff
|
||||
accent.strong_pressed = #36449dff
|
||||
accent.soft = #6e80d82c
|
||||
accent.border = #6e80d8aa
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #9385ffff
|
||||
accent.hover = #9385fdff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #8884b7ff
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #9385ffff
|
||||
accent.hover = #9385fdff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #8884b7ff
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8b7cf6ff
|
||||
accent.hover = #9284fcff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #a094ff6e
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -29,8 +29,8 @@ accent.solid = #8b7cf6ff
|
||||
accent.hover = #9284fcff
|
||||
accent.pressed = #a49cfeff
|
||||
accent.strong = #f6f6f8ff
|
||||
accent.strong_hover = #fefeffff
|
||||
accent.strong_pressed = #ffffffff
|
||||
accent.strong_hover = #e2e2e4ff
|
||||
accent.strong_pressed = #d5d5d7ff
|
||||
accent.soft = #8b7cf62e
|
||||
accent.border = #a094ff6e
|
||||
accent.text = #d6d0ffff
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
|
||||
mod dumps;
|
||||
mod selection;
|
||||
mod strong_hover;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//! Primary / accent buttons (`accent.strong`) must show hover and press in every built-in theme,
|
||||
//! in both modes, without the text on them dropping below the text minimum (wordcraft#7317 C7-14).
|
||||
|
||||
use craft_theme::contrast::contrast_ratio;
|
||||
use craft_theme::{Appearance, Contrast, Mode, Size, TextSize, Variants, builtins, resolve};
|
||||
|
||||
/// Least OKLCH lightness change of hover and of press from rest. Below about 0.05 a fill change is
|
||||
/// hard to see next to a neighbouring control.
|
||||
const HOVER_MIN: f64 = 0.05;
|
||||
const PRESSED_MIN: f64 = 0.08;
|
||||
|
||||
#[test]
|
||||
fn strong_accent_hover_and_pressed_are_visible_and_keep_text_contrast() {
|
||||
for theme in builtins() {
|
||||
// Classic pins all three states to one grey: its bevel, not the fill, shows the state.
|
||||
if theme.name == "Classic" {
|
||||
continue;
|
||||
}
|
||||
let modes = match theme.variants {
|
||||
Variants::Both => vec![Mode::Light, Mode::Dark],
|
||||
Variants::LightOnly => vec![Mode::Light],
|
||||
Variants::DarkOnly => vec![Mode::Dark],
|
||||
};
|
||||
for mode in modes {
|
||||
let appearance =
|
||||
Appearance { mode, contrast: Contrast::Standard, size: Size::Comfortable, text_size: TextSize::Small, reduced_motion: false };
|
||||
let c = resolve(theme, appearance, None).tokens.color;
|
||||
let (rest, hover, pressed) = (c.accent.strong, c.accent.strong_hover, c.accent.strong_pressed);
|
||||
let l = |x: craft_theme::color::Rgba| x.to_oklch().l;
|
||||
let who = format!("{} {mode:?}", theme.name);
|
||||
assert!((l(hover) - l(rest)).abs() >= HOVER_MIN, "{who}: hover barely differs from rest");
|
||||
assert!((l(pressed) - l(rest)).abs() >= PRESSED_MIN, "{who}: pressed barely differs from rest");
|
||||
for (state, fill) in [("rest", rest), ("hover", hover), ("pressed", pressed)] {
|
||||
let ratio = contrast_ratio(c.text.on_strong, fill);
|
||||
assert!(ratio >= 4.5, "{who}: text.on_strong on {state} is {ratio:.2}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A user asking why the hover fill differs from rest is told which token it starts from and how much
|
||||
/// lightness it moves at least; the floor shown is the one the colour is held to.
|
||||
#[test]
|
||||
fn explaining_strong_hover_names_its_base_and_the_lightness_floor() {
|
||||
use craft_theme::{ColorSource, ColorToken, explain};
|
||||
let theme = builtins().iter().find(|t| t.name != "Classic" && t.variants != Variants::LightOnly).unwrap();
|
||||
let appearance =
|
||||
Appearance { mode: Mode::Dark, contrast: Contrast::Standard, size: Size::Comfortable, text_size: TextSize::Small, reduced_motion: false };
|
||||
let e = explain(theme, appearance, None);
|
||||
let origin = e.color(ColorToken::AccentStrongHover).unwrap();
|
||||
let ColorSource::ShiftedFrom { min, .. } = origin.source else { panic!("hover is a shifted colour: {:?}", origin.source) };
|
||||
let words = origin.source_words();
|
||||
assert!(words.contains(ColorToken::AccentStrong.path()), "names the base token: {words}");
|
||||
assert!(words.contains(&min.to_string()), "names the floor {min}: {words}");
|
||||
}
|
||||
Reference in New Issue
Block a user