Merge branch 'master' into wgpu/better-architecture
This commit is contained in:
commit
6ea763c2a7
2 changed files with 16 additions and 12 deletions
|
|
@ -20,7 +20,7 @@ pkgs.mkShell rec {
|
||||||
freetype
|
freetype
|
||||||
freetype.dev
|
freetype.dev
|
||||||
libGL
|
libGL
|
||||||
pkgconfig
|
pkg-config
|
||||||
xorg.libX11
|
xorg.libX11
|
||||||
xorg.libXcursor
|
xorg.libXcursor
|
||||||
xorg.libXi
|
xorg.libXi
|
||||||
|
|
|
||||||
|
|
@ -612,19 +612,16 @@ fn mix(a: Color, b: Color, factor: f32) -> Color {
|
||||||
|
|
||||||
fn readable(background: Color, text: Color) -> Color {
|
fn readable(background: Color, text: Color) -> Color {
|
||||||
if is_readable(background, text) {
|
if is_readable(background, text) {
|
||||||
return text;
|
text
|
||||||
}
|
|
||||||
|
|
||||||
let fallback = if is_dark(background) {
|
|
||||||
Color::WHITE
|
|
||||||
} else {
|
} else {
|
||||||
Color::BLACK
|
let white_contrast = relative_contrast(background, Color::WHITE);
|
||||||
};
|
let black_contrast = relative_contrast(background, Color::BLACK);
|
||||||
|
|
||||||
if is_readable(background, fallback) {
|
if white_contrast >= black_contrast {
|
||||||
fallback
|
Color::WHITE
|
||||||
} else {
|
} else {
|
||||||
fallback.inverse()
|
Color::BLACK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -639,6 +636,13 @@ fn is_readable(a: Color, b: Color) -> bool {
|
||||||
a_srgb.has_enhanced_contrast_text(b_srgb)
|
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 {
|
fn to_hsl(color: Color) -> Hsl {
|
||||||
Hsl::from_color(Rgb::from(color))
|
Hsl::from_color(Rgb::from(color))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue