user_theme.rs

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