Tweak styling of Slider and improve contrast of Background

This commit is contained in:
Héctor Ramón Jiménez 2022-05-26 05:31:25 +02:00
parent 822a3cd04f
commit 5a39dad506
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 16 additions and 18 deletions

View file

@ -31,7 +31,7 @@ impl Theme {
impl Default for Theme {
fn default() -> Self {
Self::Dark
Self::Light
}
}
@ -145,10 +145,10 @@ impl slider::StyleSheet for Theme {
};
slider::Style {
rail_colors: (palette.background.strong, palette.background.base),
rail_colors: (palette.primary.base, palette.background.base),
handle: slider::Handle {
color: palette.background.base,
border_color: palette.border,
border_color: palette.primary.base,
..handle
},
}
@ -160,7 +160,7 @@ impl slider::StyleSheet for Theme {
slider::Style {
handle: slider::Handle {
color: palette.background.weak,
color: palette.primary.weak,
..active.handle
},
..active
@ -173,7 +173,7 @@ impl slider::StyleSheet for Theme {
slider::Style {
handle: slider::Handle {
color: palette.background.strong,
color: palette.primary.base,
..active.handle
},
..active

View file

@ -63,7 +63,6 @@ pub struct Extended {
pub primary: Group,
pub success: Group,
pub danger: Group,
pub border: Color,
}
lazy_static! {
@ -91,7 +90,6 @@ impl Extended {
palette.background,
palette.text,
),
border: mix(palette.background, palette.text, 0.7),
}
}
}
@ -107,8 +105,8 @@ impl Background {
pub fn new(base: Color, text: Color) -> Self {
Self {
base,
weak: muted(base, 0.1),
strong: muted(base, 0.2),
weak: mix(base, text, 0.15),
strong: mix(base, text, 0.25),
text,
}
}
@ -142,7 +140,7 @@ fn muted(color: Color, amount: f32) -> Color {
let mut hsl = to_hsl(color);
hsl.lightness = if is_dark(color) {
let delta = amount * (1.0 - hsl.lightness).powi(7);
let delta = amount * (1.0 - hsl.lightness).powi(5);
hsl.lightness + delta
} else {
let delta = amount * hsl.lightness.powi(5);
@ -164,14 +162,6 @@ fn darken(color: Color, amount: f32) -> Color {
from_hsl(hsl)
}
fn mix(a: Color, b: Color, factor: f32) -> Color {
let a_lin = Srgb::from(a).into_linear();
let b_lin = Srgb::from(b).into_linear();
let mixed = a_lin.mix(&b_lin, factor);
Srgb::from_linear(mixed).into()
}
fn lighten(color: Color, amount: f32) -> Color {
let mut hsl = to_hsl(color);
@ -184,6 +174,14 @@ fn lighten(color: Color, amount: f32) -> Color {
from_hsl(hsl)
}
fn mix(a: Color, b: Color, factor: f32) -> Color {
let a_lin = Srgb::from(a).into_linear();
let b_lin = Srgb::from(b).into_linear();
let mixed = a_lin.mix(&b_lin, factor);
Srgb::from_linear(mixed).into()
}
fn readable(background: Color, text: Color) -> Color {
if is_readable(background, text) {
text