user_theme.rs

 1use gpui::{FontStyle, FontWeight, Hsla};
 2use refineable::Refineable;
 3use serde::Deserialize;
 4
 5use crate::{Appearance, StatusColors, StatusColorsRefinement, ThemeColors, ThemeColorsRefinement};
 6
 7#[derive(Deserialize)]
 8pub struct UserThemeFamily {
 9    pub name: String,
10    pub author: String,
11    pub themes: Vec<UserTheme>,
12}
13
14#[derive(Deserialize)]
15pub struct UserTheme {
16    pub name: String,
17    pub appearance: Appearance,
18    pub styles: UserThemeStylesRefinement,
19}
20
21#[derive(Refineable, Clone)]
22#[refineable(deserialize)]
23pub struct UserThemeStyles {
24    #[refineable]
25    pub colors: ThemeColors,
26    #[refineable]
27    pub status: StatusColors,
28    pub syntax: UserSyntaxTheme,
29}
30
31#[derive(Clone, Default, Deserialize)]
32pub struct UserSyntaxTheme {
33    pub highlights: Vec<(String, UserHighlightStyle)>,
34}
35
36#[derive(Clone, Default, Deserialize)]
37pub struct UserHighlightStyle {
38    pub color: Option<Hsla>,
39    pub font_style: Option<UserFontStyle>,
40    pub font_weight: Option<UserFontWeight>,
41}
42
43#[derive(Clone, Copy, Default, Deserialize)]
44pub struct UserFontWeight(pub f32);
45
46impl UserFontWeight {
47    /// Thin weight (100), the thinnest value.
48    pub const THIN: Self = Self(FontWeight::THIN.0);
49    /// Extra light weight (200).
50    pub const EXTRA_LIGHT: Self = Self(FontWeight::EXTRA_LIGHT.0);
51    /// Light weight (300).
52    pub const LIGHT: Self = Self(FontWeight::LIGHT.0);
53    /// Normal (400).
54    pub const NORMAL: Self = Self(FontWeight::NORMAL.0);
55    /// Medium weight (500, higher than normal).
56    pub const MEDIUM: Self = Self(FontWeight::MEDIUM.0);
57    /// Semibold weight (600).
58    pub const SEMIBOLD: Self = Self(FontWeight::SEMIBOLD.0);
59    /// Bold weight (700).
60    pub const BOLD: Self = Self(FontWeight::BOLD.0);
61    /// Extra-bold weight (800).
62    pub const EXTRA_BOLD: Self = Self(FontWeight::EXTRA_BOLD.0);
63    /// Black weight (900), the thickest value.
64    pub const BLACK: Self = Self(FontWeight::BLACK.0);
65}
66
67impl From<UserFontWeight> for FontWeight {
68    fn from(value: UserFontWeight) -> Self {
69        Self(value.0)
70    }
71}
72
73#[derive(Debug, Clone, Copy, Deserialize)]
74pub enum UserFontStyle {
75    Normal,
76    Italic,
77    Oblique,
78}
79
80impl From<UserFontStyle> for FontStyle {
81    fn from(value: UserFontStyle) -> Self {
82        match value {
83            UserFontStyle::Normal => FontStyle::Normal,
84            UserFontStyle::Italic => FontStyle::Italic,
85            UserFontStyle::Oblique => FontStyle::Oblique,
86        }
87    }
88}
89
90impl UserHighlightStyle {
91    pub fn is_empty(&self) -> bool {
92        self.color.is_none() && self.font_style.is_none() && self.font_weight.is_none()
93    }
94}