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