summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorLibravatar David Huculak <davidhuculak5@gmail.com>2024-04-07 02:20:44 -0400
committerLibravatar David Huculak <davidhuculak5@gmail.com>2024-04-07 02:20:44 -0400
commitc45c79b5d6e25f73dc76a816c08a7041ad971c66 (patch)
tree20014290d1ae706b9db3d4609215a6a32f64120d /core/src
parent31d1d5fecbef50fa319cabd5d4194f1e4aaefa21 (diff)
downloadiced-c45c79b5d6e25f73dc76a816c08a7041ad971c66.tar.gz
iced-c45c79b5d6e25f73dc76a816c08a7041ad971c66.tar.bz2
iced-c45c79b5d6e25f73dc76a816c08a7041ad971c66.zip
add stronger guarantee of readability/contrast for palette background/text color pairs
Diffstat (limited to 'core/src')
-rw-r--r--core/src/theme/palette.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs
index ca91c248..91543567 100644
--- a/core/src/theme/palette.rs
+++ b/core/src/theme/palette.rs
@@ -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()
}
}