theme2.rs

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