Merge branch 'master' into wgpu/better-architecture

This commit is contained in:
Héctor Ramón Jiménez 2024-04-08 13:56:38 +02:00
commit 6ea763c2a7
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 16 additions and 12 deletions

View file

@ -20,7 +20,7 @@ pkgs.mkShell rec {
freetype
freetype.dev
libGL
pkgconfig
pkg-config
xorg.libX11
xorg.libXcursor
xorg.libXi

View file

@ -612,19 +612,16 @@ fn mix(a: Color, b: Color, factor: f32) -> Color {
fn readable(background: Color, text: Color) -> Color {
if is_readable(background, text) {
return text;
}
let fallback = if is_dark(background) {
Color::WHITE
text
} else {
Color::BLACK
};
let white_contrast = relative_contrast(background, Color::WHITE);
let black_contrast = relative_contrast(background, Color::BLACK);
if is_readable(background, fallback) {
fallback
} else {
fallback.inverse()
if white_contrast >= black_contrast {
Color::WHITE
} else {
Color::BLACK
}
}
}
@ -639,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))
}