theme2.rs

 1mod colors;
 2mod default_colors;
 3mod default_theme;
 4mod registry;
 5mod scale;
 6mod settings;
 7mod syntax;
 8
 9pub use colors::*;
10pub use default_colors::*;
11pub use default_theme::*;
12pub use registry::*;
13pub use scale::*;
14pub use settings::*;
15pub use syntax::*;
16
17use gpui2::{AppContext, Hsla, SharedString};
18use settings2::Settings;
19
20#[derive(Debug, PartialEq, Clone, Copy)]
21pub enum Appearance {
22    Light,
23    Dark,
24}
25
26pub fn init(cx: &mut AppContext) {
27    cx.set_global(ThemeRegistry::default());
28    ThemeSettings::register(cx);
29}
30
31pub trait ActiveTheme {
32    fn theme(&self) -> &ThemeVariant;
33}
34
35impl ActiveTheme for AppContext {
36    fn theme(&self) -> &ThemeVariant {
37        &ThemeSettings::get_global(self).active_theme
38    }
39}
40
41pub struct ThemeFamily {
42    pub id: String,
43    pub name: SharedString,
44    pub author: SharedString,
45    pub themes: Vec<ThemeVariant>,
46    pub scales: ColorScales,
47}
48
49impl ThemeFamily {}
50
51pub struct ThemeVariant {
52    pub id: String,
53    pub name: SharedString,
54    pub appearance: Appearance,
55    pub styles: ThemeStyles,
56}
57
58impl ThemeVariant {
59    /// Returns the [`ThemeColors`] for the theme.
60    #[inline(always)]
61    pub fn colors(&self) -> &ThemeColors {
62        &self.styles.colors
63    }
64
65    /// Returns the [`SyntaxTheme`] for the theme.
66    #[inline(always)]
67    pub fn syntax(&self) -> &SyntaxTheme {
68        &self.styles.syntax
69    }
70
71    /// Returns the [`StatusColors`] for the theme.
72    #[inline(always)]
73    pub fn status(&self) -> &StatusColors {
74        &self.styles.status
75    }
76
77    /// Returns the [`GitStatusColors`] for the theme.
78    #[inline(always)]
79    pub fn git(&self) -> &GitStatusColors {
80        &self.styles.git
81    }
82
83    /// Returns the color for the syntax node with the given name.
84    #[inline(always)]
85    pub fn syntax_color(&self, name: &str) -> Hsla {
86        self.syntax().color(name)
87    }
88}