diff --git a/src/app.rs b/src/app.rs index 4606c57..0dc6408 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,6 +8,7 @@ use crate::{api, app}; pub struct Global { pub safe_area: gpui::Bounds, + pub theme_family: theme::ThemeFamily, pub current_theme: theme::Theme, pub rng: rand::prelude::ThreadRng, } @@ -18,7 +19,9 @@ impl Chrome { pub fn new(window: &mut gpui::Window, cx: &mut gpui::Context) -> Self { cx.observe_window_appearance(window, |_, window, cx| { cx.update_global::(|global, cx| { - global.current_theme = window.appearance().into(); + global.current_theme = global + .theme_family + .theme_for_appearance(window.appearance()); cx.notify(); }); }) diff --git a/src/colors.rs b/src/colors.rs index ac6a753..0c9c010 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -11,6 +11,7 @@ pub const fn hex(hex: u32) -> Rgba { } } +#[allow(dead_code)] pub const fn neutral(shade: u16) -> Rgba { match shade { 50 => hex(0xfafafa), @@ -28,6 +29,7 @@ pub const fn neutral(shade: u16) -> Rgba { } } +#[allow(dead_code)] pub const fn violet(shade: u16) -> Rgba { match shade { 50 => hex(0xf5f3ff), @@ -45,6 +47,7 @@ pub const fn violet(shade: u16) -> Rgba { } } +#[allow(dead_code)] pub const fn amber(shade: u16) -> Rgba { match shade { 50 => hex(0xfffbeb), @@ -62,6 +65,7 @@ pub const fn amber(shade: u16) -> Rgba { } } +#[allow(dead_code)] pub const fn red(shade: u16) -> Rgba { match shade { 50 => hex(0xfef2f2), diff --git a/src/dashboard.rs b/src/dashboard.rs index 4faf5e5..aa947ae 100644 --- a/src/dashboard.rs +++ b/src/dashboard.rs @@ -1,6 +1,6 @@ use gpui::{div, prelude::*}; -use crate::{app, theme::Variant}; +use crate::app; pub struct Screen { pub text: gpui::SharedString, diff --git a/src/main.rs b/src/main.rs index dc61e7f..7a07f03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,9 +49,11 @@ fn setup_application(cx: &mut gpui::App) { }, }); + let theme_family = theme::ThemeFamily::default(); let global = app::Global { safe_area: bounds(point(px(0.), px(0.)), size(px(72.), px(12.))), - current_theme: cx.window_appearance().into(), + theme_family, + current_theme: theme_family.theme_for_appearance(cx.window_appearance()), rng: rand::rng(), }; diff --git a/src/screen/setup_wizard/mod.rs b/src/screen/setup_wizard/mod.rs index 42cd09d..ad77b95 100644 --- a/src/screen/setup_wizard/mod.rs +++ b/src/screen/setup_wizard/mod.rs @@ -46,7 +46,9 @@ pub fn open_window(screen: Screen, cx: &mut gpui::App) -> anyhow::Result<()> { cx.new(|cx| { cx.observe_window_appearance(window, |_, window, cx| { cx.update_global::(|global, cx| { - global.current_theme = window.appearance().into(); + global.current_theme = global + .theme_family + .theme_for_appearance(window.appearance()); cx.notify(); }); }) diff --git a/src/theme.rs b/src/theme.rs index c27716e..7f2b870 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,6 +1,6 @@ use gpui::Rgba; -use crate::colors::{amber, hex, neutral, red, violet}; +use crate::colors::hex; #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum ThemeMode { @@ -19,7 +19,7 @@ pub struct Theme { impl Default for Theme { fn default() -> Self { - Variant::default().theme() + ThemeFamily::default().theme(ThemeMode::default()) } } @@ -41,83 +41,132 @@ pub struct ThemeColors { #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] #[allow(dead_code)] -pub enum Variant { - VioletLight, +pub enum ThemeFamily { #[default] - VioletDark, + Catppuccin, } -pub(crate) fn current(cx: &gpui::App) -> &Theme { - cx.global::() -} +#[allow(dead_code)] +impl ThemeFamily { + pub const ALL: [Self; 1] = [Self::Catppuccin]; -impl Variant { - #[allow(dead_code)] - pub const ALL: [Self; 2] = [Self::VioletLight, Self::VioletDark]; + pub const fn id(self) -> &'static str { + match self { + Self::Catppuccin => "catppuccin", + } + } pub const fn label(self) -> &'static str { match self { - Self::VioletLight => "Violet Light", - Self::VioletDark => "Violet Dark", + Self::Catppuccin => "Catppuccin", + } + } + + pub const fn variant(self, mode: ThemeMode) -> ThemeVariant { + match (self, mode) { + (Self::Catppuccin, ThemeMode::Light) => ThemeVariant::CatppuccinLatte, + (Self::Catppuccin, ThemeMode::Dark) => ThemeVariant::CatppuccinMocha, + } + } + + pub const fn theme(self, mode: ThemeMode) -> Theme { + self.variant(mode).theme() + } + + pub fn theme_for_appearance(self, appearance: gpui::WindowAppearance) -> Theme { + self.theme(appearance.into()) + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[allow(dead_code)] +pub enum ThemeVariant { + CatppuccinLatte, + #[default] + CatppuccinMocha, +} + +#[allow(dead_code)] +impl ThemeVariant { + pub const ALL: [Self; 2] = [Self::CatppuccinLatte, Self::CatppuccinMocha]; + + pub const fn family(self) -> ThemeFamily { + match self { + Self::CatppuccinLatte | Self::CatppuccinMocha => ThemeFamily::Catppuccin, + } + } + + pub const fn mode(self) -> ThemeMode { + match self { + Self::CatppuccinLatte => ThemeMode::Light, + Self::CatppuccinMocha => ThemeMode::Dark, + } + } + + pub const fn label(self) -> &'static str { + match self { + Self::CatppuccinLatte => "Catppuccin Latte", + Self::CatppuccinMocha => "Catppuccin Mocha", } } pub const fn theme(self) -> Theme { match self { - Self::VioletLight => Theme { - id: "violet-light", - name: "Violet Light", + Self::CatppuccinLatte => Theme { + id: "catppuccin-latte", + name: "Catppuccin Latte", mode: ThemeMode::Light, colors: ThemeColors { - background: neutral(50), - surface: neutral(100), - surface_elevated: neutral(200), - border: neutral(200), - text: neutral(900), - text_muted: neutral(600), - accent: violet(600), - accent_hover: violet(500), - accent_text: neutral(100), - success: hex(0x16a34a), - warning: amber(600), - danger: red(600), + background: hex(0xeff1f5), + surface: hex(0xe6e9ef), + surface_elevated: hex(0xdce0e8), + border: hex(0xccd0da), + text: hex(0x4c4f69), + text_muted: hex(0x6c6f85), + accent: hex(0x8839ef), + accent_hover: hex(0x7287fd), + accent_text: hex(0xeff1f5), + success: hex(0x40a02b), + warning: hex(0xdf8e1d), + danger: hex(0xd20f39), }, }, - Self::VioletDark => Theme { - id: "violet-dark", - name: "Violet Dark", + Self::CatppuccinMocha => Theme { + id: "catppuccin-mocha", + name: "Catppuccin Mocha", mode: ThemeMode::Dark, colors: ThemeColors { - background: neutral(950), - surface: neutral(900), - surface_elevated: neutral(800), - border: neutral(800), - text: neutral(50), - text_muted: neutral(400), - accent: violet(600), - accent_hover: violet(300), - accent_text: neutral(100), - success: hex(0x22c55e), - warning: amber(500), - danger: red(500), + background: hex(0x1e1e2e), + surface: hex(0x181825), + surface_elevated: hex(0x313244), + border: hex(0x45475a), + text: hex(0xcdd6f4), + text_muted: hex(0xa6adc8), + accent: hex(0xcba6f7), + accent_hover: hex(0xb4befe), + accent_text: hex(0x1e1e2e), + success: hex(0xa6e3a1), + warning: hex(0xf9e2af), + danger: hex(0xf38ba8), }, }, } } } +impl From for ThemeMode { + fn from(value: gpui::WindowAppearance) -> Self { + match value { + gpui::WindowAppearance::Light | gpui::WindowAppearance::VibrantLight => { + ThemeMode::Light + } + gpui::WindowAppearance::Dark | gpui::WindowAppearance::VibrantDark => ThemeMode::Dark, + } + } +} + impl From for Theme { fn from(value: gpui::WindowAppearance) -> Self { - let variant = match value { - gpui::WindowAppearance::Light | gpui::WindowAppearance::VibrantLight => { - Variant::VioletLight - } - gpui::WindowAppearance::Dark | gpui::WindowAppearance::VibrantDark => { - Variant::VioletDark - } - }; - variant.theme() + ThemeFamily::default().theme(value.into()) } } - -impl gpui::Global for Theme {}