pub type Color = (u8, u8, u8);
pub struct Palette {
name: &'static str,
colors: [Color; 5],
text_color: Color,
}
impl Palette {
fn get_color(&self, level: usize) -> Color {
self.colors[level]
}
pub fn calculate_color(&self, value: u32, max: u32, ranges: &[u32]) -> Color {
let level = if value < 60 {
0
} else {
let ratio = value as f32 / max as f32;
if ratio >= ranges[0] as f32 / 100.0 {
4
} else if ratio >= ranges[1] as f32 / 100.0 {
3
} else if ratio >= ranges[2] as f32 / 100.0 {
2
} else {
1
}
};
self.get_color(level)
}
pub fn text_color(&self) -> Color {
self.text_color
}
pub fn all_colors(&self) -> &[Color; 5] {
&self.colors
}
}
pub fn get_palette<'a>(palletes: &'a [Palette], name: &String) -> &'a Palette {
palletes
.iter()
.find(|p| p.name == name)
.unwrap_or(&PALETTES[0]) }
pub const PALETTES: &[Palette] = &[
Palette {
name: "dark", colors: [
(22, 27, 34), (0, 69, 41), (0, 109, 50), (38, 166, 65), (57, 211, 83), ],
text_color: (139, 148, 158),
},
Palette {
name: "light", colors: [
(235, 237, 240), (155, 233, 168), (64, 196, 99), (48, 161, 78), (33, 110, 57), ],
text_color: (87, 96, 106),
},
Palette {
name: "catppuccin_light", colors: [
(204, 208, 218), (64, 160, 43), (223, 142, 29), (254, 100, 11), (210, 15, 57), ],
text_color: (76, 79, 105),
},
Palette {
name: "catppuccin_dark", colors: [
(49, 50, 68), (166, 227, 161), (249, 226, 175), (250, 179, 135), (243, 139, 168), ],
text_color: (205, 214, 244),
},
];