Files
novem/src/theme.rs

173 lines
4.7 KiB
Rust
Raw Normal View History

2026-04-20 15:13:26 +01:00
use gpui::Rgba;
2026-04-26 00:46:11 +01:00
use crate::colors::hex;
2026-04-20 15:13:26 +01:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ThemeMode {
Light,
#[default]
Dark,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Theme {
pub id: &'static str,
pub name: &'static str,
pub mode: ThemeMode,
pub colors: ThemeColors,
}
impl Default for Theme {
fn default() -> Self {
2026-04-26 00:46:11 +01:00
ThemeFamily::default().theme(ThemeMode::default())
2026-04-20 15:13:26 +01:00
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ThemeColors {
pub background: Rgba,
pub surface: Rgba,
pub surface_elevated: Rgba,
pub border: Rgba,
pub text: Rgba,
pub text_muted: Rgba,
pub accent: Rgba,
pub accent_hover: Rgba,
pub accent_text: Rgba,
pub success: Rgba,
pub warning: Rgba,
pub danger: Rgba,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[allow(dead_code)]
2026-04-26 00:46:11 +01:00
pub enum ThemeFamily {
2026-04-20 15:13:26 +01:00
#[default]
2026-04-26 00:46:11 +01:00
Catppuccin,
2026-04-20 15:13:26 +01:00
}
2026-04-26 00:46:11 +01:00
#[allow(dead_code)]
impl ThemeFamily {
pub const ALL: [Self; 1] = [Self::Catppuccin];
pub const fn id(self) -> &'static str {
match self {
Self::Catppuccin => "catppuccin",
}
}
pub const fn label(self) -> &'static str {
match self {
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,
2026-04-23 11:18:43 +01:00
}
2026-04-26 00:46:11 +01:00
#[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,
}
}
2026-04-20 15:13:26 +01:00
pub const fn label(self) -> &'static str {
match self {
2026-04-26 00:46:11 +01:00
Self::CatppuccinLatte => "Catppuccin Latte",
Self::CatppuccinMocha => "Catppuccin Mocha",
2026-04-20 15:13:26 +01:00
}
}
pub const fn theme(self) -> Theme {
match self {
2026-04-26 00:46:11 +01:00
Self::CatppuccinLatte => Theme {
id: "catppuccin-latte",
name: "Catppuccin Latte",
2026-04-20 15:13:26 +01:00
mode: ThemeMode::Light,
colors: ThemeColors {
2026-04-26 00:46:11 +01:00
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),
2026-04-20 15:13:26 +01:00
},
},
2026-04-26 00:46:11 +01:00
Self::CatppuccinMocha => Theme {
id: "catppuccin-mocha",
name: "Catppuccin Mocha",
2026-04-20 15:13:26 +01:00
mode: ThemeMode::Dark,
colors: ThemeColors {
2026-04-26 00:46:11 +01:00
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),
2026-04-20 15:13:26 +01:00
},
},
}
}
}
2026-04-26 00:46:11 +01:00
impl From<gpui::WindowAppearance> for ThemeMode {
2026-04-20 15:13:26 +01:00
fn from(value: gpui::WindowAppearance) -> Self {
2026-04-26 00:46:11 +01:00
match value {
2026-04-20 15:13:26 +01:00
gpui::WindowAppearance::Light | gpui::WindowAppearance::VibrantLight => {
2026-04-26 00:46:11 +01:00
ThemeMode::Light
2026-04-20 15:13:26 +01:00
}
2026-04-26 00:46:11 +01:00
gpui::WindowAppearance::Dark | gpui::WindowAppearance::VibrantDark => ThemeMode::Dark,
}
2026-04-20 15:13:26 +01:00
}
}
2026-04-23 11:18:43 +01:00
2026-04-26 00:46:11 +01:00
impl From<gpui::WindowAppearance> for Theme {
fn from(value: gpui::WindowAppearance) -> Self {
ThemeFamily::default().theme(value.into())
}
}