feat: impl catppuccin theme
This commit is contained in:
157
src/theme.rs
157
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::<Theme>()
|
||||
}
|
||||
#[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<gpui::WindowAppearance> 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<gpui::WindowAppearance> 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 {}
|
||||
|
||||
Reference in New Issue
Block a user