summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-22 02:20:24 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-22 02:20:24 +0100
commita216a0a04ed2d647123472e37330725b5899632b (patch)
treef9814e0a9fee7e26d4017286fdb8cecacc25613b
parent9b79aa567a185c835e09c26230245e12176ce4e7 (diff)
downloadiced-a216a0a04ed2d647123472e37330725b5899632b.tar.gz
iced-a216a0a04ed2d647123472e37330725b5899632b.tar.bz2
iced-a216a0a04ed2d647123472e37330725b5899632b.zip
Improve `readable` fallback strategy in `palette`
-rw-r--r--core/src/theme/palette.rs31
1 files changed, 20 insertions, 11 deletions
diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs
index 0f6f0dff..0ef610bb 100644
--- a/core/src/theme/palette.rs
+++ b/core/src/theme/palette.rs
@@ -205,8 +205,8 @@ impl Palette {
///
/// [Kanagawa]: https://github.com/rebelot/kanagawa.nvim
pub const KANAGAWA_WAVE: Self = Self {
- background: color!(0x363646), // Sumi Ink 3
- text: color!(0xCD7BA), // Fuji White
+ background: color!(0x1f1f28), // Sumi Ink 3
+ text: color!(0xDCD7BA), // Fuji White
primary: color!(0x7FB4CA), // Wave Blue
success: color!(0x76946A), // Autumn Green
warning: color!(0xff9e3b), // Ronin Yellow
@@ -657,16 +657,25 @@ fn mix(a: Color, b: Color, factor: f32) -> Color {
fn readable(background: Color, text: Color) -> Color {
if is_readable(background, text) {
- text
- } else {
- let white_contrast = relative_contrast(background, Color::WHITE);
- let black_contrast = relative_contrast(background, Color::BLACK);
+ return text;
+ }
- if white_contrast >= black_contrast {
- Color::WHITE
- } else {
- Color::BLACK
- }
+ let improve = if is_dark(background) { lighten } else { darken };
+
+ // TODO: Compute factor from relative contrast value
+ let candidate = improve(text, 0.1);
+
+ if is_readable(background, candidate) {
+ return candidate;
+ }
+
+ let white_contrast = relative_contrast(background, Color::WHITE);
+ let black_contrast = relative_contrast(background, Color::BLACK);
+
+ if white_contrast >= black_contrast {
+ mix(Color::WHITE, background, 0.05)
+ } else {
+ mix(Color::BLACK, background, 0.05)
}
}