diff options
| author | 2024-04-07 02:20:44 -0400 | |
|---|---|---|
| committer | 2024-04-07 02:20:44 -0400 | |
| commit | c45c79b5d6e25f73dc76a816c08a7041ad971c66 (patch) | |
| tree | 20014290d1ae706b9db3d4609215a6a32f64120d | |
| parent | 31d1d5fecbef50fa319cabd5d4194f1e4aaefa21 (diff) | |
| download | iced-c45c79b5d6e25f73dc76a816c08a7041ad971c66.tar.gz iced-c45c79b5d6e25f73dc76a816c08a7041ad971c66.tar.bz2 iced-c45c79b5d6e25f73dc76a816c08a7041ad971c66.zip | |
add stronger guarantee of readability/contrast for palette background/text color pairs
Diffstat (limited to '')
| -rw-r--r-- | core/src/theme/palette.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index ca91c248..91543567 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -612,11 +612,19 @@ fn mix(a: Color, b: Color, factor: f32) -> Color { fn readable(background: Color, text: Color) -> Color { if is_readable(background, text) { - text - } else if is_dark(background) { + return text; + } + + let fallback = if is_dark(background) { Color::WHITE } else { Color::BLACK + }; + + if is_readable(background, fallback) { + fallback + } else { + fallback.inverse() } } |
