Skip to content

Commit

Permalink
new shades of colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Redhawk18 committed Aug 13, 2023
1 parent e3eedcc commit 34138b3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/gui/theme/shades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ use palette::{DarkenAssign, FromColor, LightenAssign, Okhsl, Srgb};
pub struct Shades {
pub default: Color,
pub light: Color,
pub lighter: Color,
pub lightest: Color,
pub dark: Color,
pub darker: Color,
pub darkest: Color,
}

impl Shades {
pub fn new(color: Color) -> Self {
Self {
default: color,
light: lighten(color, 0.5),
dark: darken(color, 0.5),
light: lighten(color, 0.25),
lighter: lighten(color, 0.50),
lightest: lighten(color, 0.75),
dark: darken(color, 0.25),
darker: darken(color, 0.50),
darkest: darken(color, 0.75),
}
}
}
Expand All @@ -38,18 +46,22 @@ fn from_hsl(hsl: Okhsl) -> Color {
// Color { a: alpha, ..color }
// }

fn lighten(color: Color, amount: f32) -> Color {
fn darken(color: Color, amount: f32) -> Color {
let mut hsl = to_hsl(color);

hsl.lighten_fixed_assign(amount);
hsl.darken_fixed_assign(amount);

from_hsl(hsl)
}

fn darken(color: Color, amount: f32) -> Color {
fn lighten(color: Color, amount: f32) -> Color {
let mut hsl = to_hsl(color);

hsl.darken_fixed_assign(amount);
hsl.lighten_fixed_assign(amount);

from_hsl(hsl)
}

pub fn is_dark(color: Color) -> bool {
to_hsl(color).lightness < 0.5
}

0 comments on commit 34138b3

Please sign in to comment.