diff --git a/src/core/theme.rs b/src/core/theme.rs index 6d30d84..3fee5b1 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -1,11 +1,18 @@ +use dark_light; use iced::{color, Color}; #[derive(Default, Debug, PartialEq, Eq, Copy, Clone)] +/// Color scheme pub enum Theme { #[default] + /// `Dark`-ish and purple Lupin, + /// white on black Dark, + /// black on white Light, + /// `Dark` or `Light`, according to `dark_light` + Auto, } #[derive(Debug, Clone, Copy)] @@ -39,62 +46,73 @@ pub struct ColorPalette { } impl Theme { - pub const ALL: [Self; 3] = [Self::Lupin, Self::Dark, Self::Light]; + pub const ALL: [Self; 4] = [Self::Lupin, Self::Dark, Self::Light, Self::Auto]; + pub fn palette(self) -> ColorPalette { + const DARK: ColorPalette = ColorPalette { + base: BaseColors { + background: color!(0x111111), + foreground: color!(0x1C1C1C), + }, + normal: NormalColors { + primary: color!(0x5E4266), + secondary: color!(0x386e50), + surface: color!(0x828282), + error: color!(0x992B2B), + }, + bright: BrightColors { + primary: color!(0xBA84FC), + secondary: color!(0x49eb7a), + surface: color!(0xE0E0E0), + error: color!(0xC13047), + }, + }; + const LIGHT: ColorPalette = ColorPalette { + base: BaseColors { + background: color!(0xEEEEEE), + foreground: color!(0xE0E0E0), + }, + normal: NormalColors { + primary: color!(0x818181), + secondary: color!(0xF9D659), + surface: color!(0x818181), + error: color!(0x992B2B), + }, + bright: BrightColors { + primary: color!(0x673AB7), + secondary: color!(0x3797A4), + surface: color!(0x000000), + error: color!(0xC13047), + }, + }; + const LUPIN: ColorPalette = ColorPalette { + base: BaseColors { + background: color!(0x282a36), + foreground: color!(0x353746), + }, + normal: NormalColors { + primary: color!(0x58406F), + secondary: color!(0x386e50), + surface: color!(0xa2a4a3), + error: color!(0xA13034), + }, + bright: BrightColors { + primary: color!(0xbd94f9), + secondary: color!(0x49eb7a), + surface: color!(0xf4f8f3), + error: color!(0xE63E6D), + }, + }; match self { - Self::Dark => ColorPalette { - base: BaseColors { - background: color!(0x111111), - foreground: color!(0x1C1C1C), - }, - normal: NormalColors { - primary: color!(0x5E4266), - secondary: color!(0x386e50), - surface: color!(0x828282), - error: color!(0x992B2B), - }, - bright: BrightColors { - primary: color!(0xBA84FC), - secondary: color!(0x49eb7a), - surface: color!(0xE0E0E0), - error: color!(0xC13047), - }, - }, - Self::Light => ColorPalette { - base: BaseColors { - background: color!(0xEEEEEE), - foreground: color!(0xE0E0E0), - }, - normal: NormalColors { - primary: color!(0x818181), - secondary: color!(0xF9D659), - surface: color!(0x818181), - error: color!(0x992B2B), - }, - bright: BrightColors { - primary: color!(0x673AB7), - secondary: color!(0x3797A4), - surface: color!(0x000000), - error: color!(0xC13047), - }, - }, - Self::Lupin => ColorPalette { - base: BaseColors { - background: color!(0x282a36), - foreground: color!(0x353746), - }, - normal: NormalColors { - primary: color!(0x58406F), - secondary: color!(0x386e50), - surface: color!(0xa2a4a3), - error: color!(0xA13034), - }, - bright: BrightColors { - primary: color!(0xbd94f9), - secondary: color!(0x49eb7a), - surface: color!(0xf4f8f3), - error: color!(0xE63E6D), - }, + Self::Dark => DARK, + Self::Light => LIGHT, + Self::Lupin => LUPIN, + Self::Auto => match dark_light::detect() { + dark_light::Mode::Dark => DARK, + dark_light::Mode::Light => LIGHT, + // we should use `default` somehow, + // rather than hard-coding Lupin + _ => LUPIN, }, } } @@ -109,6 +127,8 @@ impl std::fmt::Display for Theme { Self::Dark => "Dark", Self::Light => "Light", Self::Lupin => "Lupin", + // should it be "Follow System"? + Self::Auto => "Auto (sync on startup)", } ) }