1mod default;
2mod registry;
3mod scale;
4mod settings;
5mod themes;
6
7pub use registry::*;
8pub use settings::*;
9
10use gpui2::{AppContext, HighlightStyle, Hsla, SharedString};
11use settings2::Settings;
12use std::sync::Arc;
13
14#[derive(Debug, Clone, PartialEq)]
15pub enum Appearance {
16 Light,
17 Dark,
18}
19
20pub fn init(cx: &mut AppContext) {
21 cx.set_global(ThemeRegistry::default());
22 ThemeSettings::register(cx);
23}
24
25pub fn active_theme<'a>(cx: &'a AppContext) -> &'a Arc<Theme> {
26 &ThemeSettings::get_global(cx).active_theme
27}
28
29pub fn theme(cx: &AppContext) -> Arc<Theme> {
30 active_theme(cx).clone()
31}
32
33pub struct Theme {
34 pub metadata: ThemeMetadata,
35
36 pub transparent: Hsla,
37 pub mac_os_traffic_light_red: Hsla,
38 pub mac_os_traffic_light_yellow: Hsla,
39 pub mac_os_traffic_light_green: Hsla,
40 pub border: Hsla,
41 pub border_variant: Hsla,
42 pub border_focused: Hsla,
43 pub border_transparent: Hsla,
44 /// The background color of an elevated surface, like a modal, tooltip or toast.
45 pub elevated_surface: Hsla,
46 pub surface: Hsla,
47 /// Window background color of the base app
48 pub background: Hsla,
49 /// Default background for elements like filled buttons,
50 /// text fields, checkboxes, radio buttons, etc.
51 /// - TODO: Map to step 3.
52 pub filled_element: Hsla,
53 /// The background color of a hovered element, like a button being hovered
54 /// with a mouse, or hovered on a touch screen.
55 /// - TODO: Map to step 4.
56 pub filled_element_hover: Hsla,
57 /// The background color of an active element, like a button being pressed,
58 /// or tapped on a touch screen.
59 /// - TODO: Map to step 5.
60 pub filled_element_active: Hsla,
61 /// The background color of a selected element, like a selected tab,
62 /// a button toggled on, or a checkbox that is checked.
63 pub filled_element_selected: Hsla,
64 pub filled_element_disabled: Hsla,
65 pub ghost_element: Hsla,
66 /// The background color of a hovered element with no default background,
67 /// like a ghost-style button or an interactable list item.
68 /// - TODO: Map to step 3.
69 pub ghost_element_hover: Hsla,
70 /// - TODO: Map to step 4.
71 pub ghost_element_active: Hsla,
72 pub ghost_element_selected: Hsla,
73 pub ghost_element_disabled: Hsla,
74 pub text: Hsla,
75 pub text_muted: Hsla,
76 pub text_placeholder: Hsla,
77 pub text_disabled: Hsla,
78 pub text_accent: Hsla,
79 pub icon_muted: Hsla,
80 pub syntax: SyntaxTheme,
81
82 pub status_bar: Hsla,
83 pub title_bar: Hsla,
84 pub toolbar: Hsla,
85 pub tab_bar: Hsla,
86 /// The background of the editor
87 pub editor: Hsla,
88 pub editor_subheader: Hsla,
89 pub editor_active_line: Hsla,
90 pub terminal: Hsla,
91 pub image_fallback_background: Hsla,
92
93 pub git_created: Hsla,
94 pub git_modified: Hsla,
95 pub git_deleted: Hsla,
96 pub git_conflict: Hsla,
97 pub git_ignored: Hsla,
98 pub git_renamed: Hsla,
99
100 pub players: [PlayerTheme; 8],
101}
102
103#[derive(Clone)]
104pub struct SyntaxTheme {
105 pub highlights: Vec<(String, HighlightStyle)>,
106}
107
108impl SyntaxTheme {
109 pub fn get(&self, name: &str) -> HighlightStyle {
110 self.highlights
111 .iter()
112 .find_map(|entry| if entry.0 == name { Some(entry.1) } else { None })
113 .unwrap_or_default()
114 }
115
116 pub fn color(&self, name: &str) -> Hsla {
117 self.get(name).color.unwrap_or_default()
118 }
119}
120
121#[derive(Clone, Copy)]
122pub struct PlayerTheme {
123 pub cursor: Hsla,
124 pub selection: Hsla,
125}
126
127#[derive(Clone)]
128pub struct ThemeMetadata {
129 pub name: SharedString,
130 pub is_light: bool,
131}
132
133pub struct Editor {
134 pub syntax: Arc<SyntaxTheme>,
135}