1pub use crate::{old_theme, ButtonVariant, ElementExt, Theme};
2use gpui2::{rgb, Hsla, WindowContext};
3use strum::EnumIter;
4
5#[derive(Clone, Copy)]
6pub struct PlayerThemeColors {
7 pub cursor: Hsla,
8 pub selection: Hsla,
9}
10
11impl PlayerThemeColors {
12 pub fn new(cx: &WindowContext, ix: usize) -> Self {
13 let theme = old_theme(cx);
14
15 if ix < theme.players.len() {
16 Self {
17 cursor: theme.players[ix].cursor,
18 selection: theme.players[ix].selection,
19 }
20 } else {
21 Self {
22 cursor: rgb::<Hsla>(0xff00ff),
23 selection: rgb::<Hsla>(0xff00ff),
24 }
25 }
26 }
27}
28
29#[derive(Clone, Copy, Debug)]
30pub struct SyntaxColor {
31 pub comment: Hsla,
32 pub string: Hsla,
33 pub function: Hsla,
34 pub keyword: Hsla,
35}
36
37impl SyntaxColor {
38 pub fn new(cx: &WindowContext) -> Self {
39 let theme = old_theme(cx);
40
41 Self {
42 comment: theme
43 .syntax
44 .get("comment")
45 .cloned()
46 .unwrap_or_else(|| rgb::<Hsla>(0xff00ff)),
47 string: theme
48 .syntax
49 .get("string")
50 .cloned()
51 .unwrap_or_else(|| rgb::<Hsla>(0xff00ff)),
52 function: theme
53 .syntax
54 .get("function")
55 .cloned()
56 .unwrap_or_else(|| rgb::<Hsla>(0xff00ff)),
57 keyword: theme
58 .syntax
59 .get("keyword")
60 .cloned()
61 .unwrap_or_else(|| rgb::<Hsla>(0xff00ff)),
62 }
63 }
64}
65
66/// ThemeColor is the primary interface for coloring elements in the UI.
67///
68/// It is a mapping layer between semantic theme colors and colors from the reference library.
69///
70/// While we are between zed and zed2 we use this to map semantic colors to the old theme.
71#[derive(Clone, Copy)]
72pub struct ThemeColor {
73 pub transparent: Hsla,
74 pub mac_os_traffic_light_red: Hsla,
75 pub mac_os_traffic_light_yellow: Hsla,
76 pub mac_os_traffic_light_green: Hsla,
77 pub border: Hsla,
78 pub border_variant: Hsla,
79 pub border_focused: Hsla,
80 pub border_transparent: Hsla,
81 /// The background color of an elevated surface, like a modal, tooltip or toast.
82 pub elevated_surface: Hsla,
83 pub surface: Hsla,
84 /// Window background color of the base app
85 pub background: Hsla,
86 /// Default background for elements like filled buttons,
87 /// text fields, checkboxes, radio buttons, etc.
88 /// - TODO: Map to step 3.
89 pub filled_element: Hsla,
90 /// The background color of a hovered element, like a button being hovered
91 /// with a mouse, or hovered on a touch screen.
92 /// - TODO: Map to step 4.
93 pub filled_element_hover: Hsla,
94 /// The background color of an active element, like a button being pressed,
95 /// or tapped on a touch screen.
96 /// - TODO: Map to step 5.
97 pub filled_element_active: Hsla,
98 /// The background color of a selected element, like a selected tab,
99 /// a button toggled on, or a checkbox that is checked.
100 pub filled_element_selected: Hsla,
101 pub filled_element_disabled: Hsla,
102 pub ghost_element: Hsla,
103 /// The background color of a hovered element with no default background,
104 /// like a ghost-style button or an interactable list item.
105 /// - TODO: Map to step 3.
106 pub ghost_element_hover: Hsla,
107 /// - TODO: Map to step 4.
108 pub ghost_element_active: Hsla,
109 pub ghost_element_selected: Hsla,
110 pub ghost_element_disabled: Hsla,
111 pub text: Hsla,
112 pub text_muted: Hsla,
113 pub text_placeholder: Hsla,
114 pub text_disabled: Hsla,
115 pub text_accent: Hsla,
116 pub icon_muted: Hsla,
117 pub syntax: SyntaxColor,
118
119 pub status_bar: Hsla,
120 pub title_bar: Hsla,
121 pub toolbar: Hsla,
122 pub tab_bar: Hsla,
123 /// The background of the editor
124 pub editor: Hsla,
125 pub editor_subheader: Hsla,
126 pub editor_active_line: Hsla,
127 pub terminal: Hsla,
128 pub image_fallback_background: Hsla,
129
130 pub git_created: Hsla,
131 pub git_modified: Hsla,
132 pub git_deleted: Hsla,
133 pub git_conflict: Hsla,
134 pub git_ignored: Hsla,
135 pub git_renamed: Hsla,
136
137 pub players: [PlayerThemeColors; 8],
138}
139
140/// Colors used exclusively for syntax highlighting.
141///
142/// For now we deserialize these from a theme.
143/// These will be defined statically in the new theme.
144#[derive(Default, PartialEq, EnumIter, Clone, Copy)]
145pub enum HighlightColor {
146 #[default]
147 Default,
148 Comment,
149 String,
150 Function,
151 Keyword,
152}
153
154impl HighlightColor {
155 pub fn hsla(&self, theme: &Theme) -> Hsla {
156 match self {
157 Self::Default => theme
158 .syntax
159 .get("primary")
160 .cloned()
161 .expect("Couldn't find `primary` in theme.syntax"),
162 Self::Comment => theme
163 .syntax
164 .get("comment")
165 .cloned()
166 .expect("Couldn't find `comment` in theme.syntax"),
167 Self::String => theme
168 .syntax
169 .get("string")
170 .cloned()
171 .expect("Couldn't find `string` in theme.syntax"),
172 Self::Function => theme
173 .syntax
174 .get("function")
175 .cloned()
176 .expect("Couldn't find `function` in theme.syntax"),
177 Self::Keyword => theme
178 .syntax
179 .get("keyword")
180 .cloned()
181 .expect("Couldn't find `keyword` in theme.syntax"),
182 }
183 }
184}