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.
This commit is contained in:
Jonathan Johnson 2023-11-14 08:43:05 -08:00
parent ca81c3702c
commit 494fa680cb
No known key found for this signature in database
GPG key ID: A66D6A34D6620579

View file

@ -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