add stronger guarantee of readability/contrast for palette background/text color pairs

This commit is contained in:
David Huculak 2024-04-07 02:20:44 -04:00
parent 31d1d5fecb
commit c45c79b5d6

View file

@ -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()
}
}