From 494fa680cb3e0dc9f5e93d872d5ebbaea506c45b Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Tue, 14 Nov 2023 08:43:05 -0800 Subject: [PATCH] Contrast calculation adjustments I noticed that the new default theme settings were causing the "wrong" text color to be picked. After reviewing why the contrast values were the way they were, I reasoned that the less lightness, the less the ColorSource contrast matters. So I've applied a multiplication of the average ligntess between the two colors being compared. --- src/styles.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/styles.rs b/src/styles.rs index 4446f97..8d8c95f 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -1381,12 +1381,19 @@ impl ColorExt for Color { let (other_source, other_lightness) = self.into_source_and_lightness(); let lightness_delta = other_lightness.difference_between(check_lightness); + let average_lightness = ZeroToOne::new((*check_lightness + *other_lightness) / 2.); + let source_change = check_source.contrast_between(other_source); let other_alpha = ZeroToOne::new(self.alpha_f32()); let alpha_delta = check_alpha.difference_between(other_alpha); - ZeroToOne::new((*lightness_delta + *source_change + *alpha_delta) / 3.) + ZeroToOne::new( + (*lightness_delta + + *average_lightness * *source_change + + *average_lightness * *alpha_delta) + / 3., + ) } fn most_contrasting(self, others: &[Self]) -> Self