diff options
author | 2024-04-16 00:08:17 +0900 | |
---|---|---|
committer | 2024-04-16 00:08:17 +0900 | |
commit | 0ebe0629cef37aee5c48b9409fc36618a3a3e60d (patch) | |
tree | 909d9ecf28e7c491bae3afc81928c118517fa7a9 /core/src/theme | |
parent | 13bd106fc585034a7aba17b9c17589113274aaf5 (diff) | |
parent | 105b8bd5ad6ade1f203a0d8b0b93bd06f61f621a (diff) | |
download | iced-0ebe0629cef37aee5c48b9409fc36618a3a3e60d.tar.gz iced-0ebe0629cef37aee5c48b9409fc36618a3a3e60d.tar.bz2 iced-0ebe0629cef37aee5c48b9409fc36618a3a3e60d.zip |
Merge branch 'iced-rs:master' into viewer_content_fit
Diffstat (limited to 'core/src/theme')
-rw-r--r-- | core/src/theme/palette.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index ca91c248..e0ff397a 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -613,10 +613,15 @@ 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) { - Color::WHITE } else { - Color::BLACK + let white_contrast = relative_contrast(background, Color::WHITE); + let black_contrast = relative_contrast(background, Color::BLACK); + + if white_contrast >= black_contrast { + Color::WHITE + } else { + Color::BLACK + } } } @@ -631,6 +636,13 @@ fn is_readable(a: Color, b: Color) -> bool { a_srgb.has_enhanced_contrast_text(b_srgb) } +fn relative_contrast(a: Color, b: Color) -> f32 { + let a_srgb = Rgb::from(a); + let b_srgb = Rgb::from(b); + + a_srgb.relative_contrast(b_srgb) +} + fn to_hsl(color: Color) -> Hsl { Hsl::from_color(Rgb::from(color)) } |