From 954f49d4d73d040ef9367800a662031cd92d9e09 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 22 Feb 2025 00:34:55 +0100 Subject: Add `weakest` and `strongest` to `Background` palette ... and tweak background shade generation logic. --- core/src/theme/palette.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'core/src/theme') diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index b4acaa83..3f30326b 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -207,7 +207,7 @@ impl Palette { pub const KANAGAWA_WAVE: Self = Self { background: color!(0x363646), // Sumi Ink 3 text: color!(0xCD7BA), // Fuji White - primary: color!(0x2D4F67), // Wave Blue 2 + primary: color!(0x7FB4CA), // Wave Blue success: color!(0x76946A), // Autumn Green warning: color!(0xff9e3b), // Ronin Yellow danger: color!(0xC34043), // Autumn Red @@ -231,7 +231,7 @@ impl Palette { pub const KANAGAWA_LOTUS: Self = Self { background: color!(0xf2ecbc), // Lotus White 3 text: color!(0x545464), // Lotus Ink 1 - primary: color!(0xc9cbd1), // Lotus Violet 3 + primary: color!(0x4d699b), // Lotus Blue success: color!(0x6f894e), // Lotus Green warning: color!(0xe98a00), // Lotus Orange 2 danger: color!(0xc84053), // Lotus Red @@ -453,22 +453,30 @@ impl Pair { pub struct Background { /// The base background color. pub base: Pair, + /// The weakest version of the base background color. + pub weakest: Pair, /// A weaker version of the base background color. pub weak: Pair, /// A stronger version of the base background color. pub strong: Pair, + /// The strongest version of the base background color. + pub strongest: Pair, } impl Background { /// Generates a set of [`Background`] colors from the base and text colors. pub fn new(base: Color, text: Color) -> Self { - let weak = mix(base, text, 0.15); - let strong = mix(base, text, 0.40); + let weakest = deviate(base, 0.03); + let weak = muted(deviate(base, 0.1)); + let strong = muted(deviate(base, 0.2)); + let strongest = muted(deviate(base, 0.3)); Self { base: Pair::new(base, text), + weakest: Pair::new(weakest, text), weak: Pair::new(weak, text), strong: Pair::new(strong, text), + strongest: Pair::new(strongest, text), } } } @@ -627,10 +635,18 @@ fn deviate(color: Color, amount: f32) -> Color { if is_dark(color) { lighten(color, amount) } else { - darken(color, amount) + darken(color, amount * 0.7) } } +fn muted(color: Color) -> Color { + let mut hsl = to_hsl(color); + + hsl.saturation = hsl.saturation.min(0.5); + + from_hsl(hsl) +} + fn mix(a: Color, b: Color, factor: f32) -> Color { let a_lin = Rgb::from(a).into_linear(); let b_lin = Rgb::from(b).into_linear(); -- cgit From 412dfe0e607f5e7df8027578e5de3ea4b667f66f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 22 Feb 2025 00:58:06 +0100 Subject: Tweak colors of `Light` and `Dark` themes --- core/src/theme/palette.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core/src/theme') diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 3f30326b..0f6f0dff 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -29,7 +29,7 @@ impl Palette { pub const LIGHT: Self = Self { background: Color::WHITE, text: Color::BLACK, - primary: color!(0x5e7ce2), + primary: color!(0x5865F2), success: color!(0x12664f), warning: color!(0xffc14e), danger: color!(0xc3423f), @@ -37,9 +37,9 @@ impl Palette { /// The built-in dark variant of a [`Palette`]. pub const DARK: Self = Self { - background: color!(0x202225), + background: color!(0x313338), text: Color::from_rgb(0.90, 0.90, 0.90), - primary: color!(0x5e7ce2), + primary: color!(0x5865F2), success: color!(0x12664f), warning: color!(0xffc14e), danger: color!(0xc3423f), -- cgit From a216a0a04ed2d647123472e37330725b5899632b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 22 Feb 2025 02:20:24 +0100 Subject: Improve `readable` fallback strategy in `palette` --- core/src/theme/palette.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'core/src/theme') 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) } } -- cgit From 873311558f1b96f7a40ee73ddb270c396607b9bb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 22 Feb 2025 02:25:01 +0100 Subject: Darken background of `Dark` theme --- core/src/theme/palette.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src/theme') diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 0ef610bb..ed49063c 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -37,7 +37,7 @@ impl Palette { /// The built-in dark variant of a [`Palette`]. pub const DARK: Self = Self { - background: color!(0x313338), + background: color!(0x2B2D31), text: Color::from_rgb(0.90, 0.90, 0.90), primary: color!(0x5865F2), success: color!(0x12664f), -- cgit