use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
pub enum Theme {
Light,
Dark,
}
impl Theme {
pub fn as_str(self) -> &'static str {
match self {
Theme::Light => "light",
Theme::Dark => "dark",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Rgb {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl Rgb {
pub const fn hex(v: u32) -> Self {
Self {
r: ((v >> 16) & 0xFF) as u8,
g: ((v >> 8) & 0xFF) as u8,
b: (v & 0xFF) as u8,
}
}
pub fn mix(self, other: Rgb, t: f64) -> Rgb {
fn ch(a: u8, b: u8, t: f64) -> u8 {
let v = f64::from(a) + (f64::from(b) - f64::from(a)) * t;
v.round().clamp(0.0, 255.0) as u8
}
Rgb {
r: ch(self.r, other.r, t),
g: ch(self.g, other.g, t),
b: ch(self.b, other.b, t),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct PaletteFamily {
pub id: &'static str,
pub theme: Theme,
pub bg_edge: Rgb,
pub bg_center: Rgb,
pub ink: Rgb,
pub accent: Rgb,
pub ember: Rgb,
pub glow_strength: f64,
pub tint_strength: f64,
}
pub const FAMILIES: [PaletteFamily; 4] = [
PaletteFamily {
id: "ember_night",
theme: Theme::Dark,
bg_edge: Rgb::hex(0x151412),
bg_center: Rgb::hex(0x211F1C), ink: Rgb::hex(0xE9E5D7),
accent: Rgb::hex(0xFF9646),
ember: Rgb::hex(0xFF9646),
glow_strength: 0.20,
tint_strength: 0.70,
},
PaletteFamily {
id: "slate_night",
theme: Theme::Dark,
bg_edge: Rgb::hex(0x121416),
bg_center: Rgb::hex(0x1C1F23),
ink: Rgb::hex(0xDCE1E4),
accent: Rgb::hex(0xFF9A52),
ember: Rgb::hex(0xFFA25E),
glow_strength: 0.17,
tint_strength: 0.62,
},
PaletteFamily {
id: "paper_day",
theme: Theme::Light,
bg_edge: Rgb::hex(0xE2DFD4),
bg_center: Rgb::hex(0xF2EFE6),
ink: Rgb::hex(0x1C1A17),
accent: Rgb::hex(0xD9652B),
ember: Rgb::hex(0xCF5320),
glow_strength: 0.10,
tint_strength: 0.55,
},
PaletteFamily {
id: "sand_day",
theme: Theme::Light,
bg_edge: Rgb::hex(0xE4DACA),
bg_center: Rgb::hex(0xF3EBDD),
ink: Rgb::hex(0x29221C),
accent: Rgb::hex(0xC8562A),
ember: Rgb::hex(0xC24E20),
glow_strength: 0.10,
tint_strength: 0.50,
},
];
pub fn family(id: &str) -> Option<&'static PaletteFamily> {
FAMILIES.iter().find(|f| f.id == id)
}
pub fn families_for(theme: Theme) -> impl Iterator<Item = &'static PaletteFamily> {
FAMILIES.iter().filter(move |f| f.theme == theme)
}