Skip to content

Commit

Permalink
Merge pull request #2376 from Davidster/fix_palette_readable_color_co…
Browse files Browse the repository at this point in the history
…ntrast

Add stronger guarantee of readability/contrast for palette background/text color pairs
  • Loading branch information
hecrj authored Apr 7, 2024
2 parents 31d1d5f + c45c79b commit 6304235
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/src/theme/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 6304235

Please sign in to comment.