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, Clone, PartialEq)]
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    #[allow(dead_code)]
43    pub(crate) id: String,
44    pub name: SharedString,
45    pub author: SharedString,
46    pub themes: Vec<ThemeVariant>,
47    pub scales: ColorScales,
48}
49
50impl ThemeFamily {}
51
52pub struct ThemeVariant {
53    #[allow(dead_code)]
54    pub(crate) id: String,
55    pub name: SharedString,
56    pub appearance: Appearance,
57    pub styles: ThemeStyles,
58}
59
60impl ThemeVariant {
61    /// Returns the [`ThemeColors`] for the theme.
62    #[inline(always)]
63    pub fn colors(&self) -> &ThemeColors {
64        &self.styles.colors
65    }
66
67    /// Returns the [`SyntaxTheme`] for the theme.
68    #[inline(always)]
69    pub fn syntax(&self) -> &SyntaxTheme {
70        &self.styles.syntax
71    }
72
73    /// Returns the color for the syntax node with the given name.
74    #[inline(always)]
75    pub fn syntax_color(&self, name: &str) -> Hsla {
76        self.syntax().color(name)
77    }
78}