colors.rs

  1#![allow(missing_docs)]
  2use crate::StatusColorsRefinement;
  3use gpui::{Hsla, WindowBackgroundAppearance};
  4use refineable::Refineable;
  5use std::sync::Arc;
  6
  7use crate::{AccentColors, PlayerColors, StatusColors, SyntaxTheme, SystemColors};
  8
  9#[derive(Refineable, Clone, Debug, PartialEq)]
 10#[refineable(Debug, serde::Deserialize)]
 11pub struct ThemeColors {
 12    /// Border color. Used for most borders, is usually a high contrast color.
 13    pub border: Hsla,
 14    /// Border color. Used for deemphasized borders, like a visual divider between two sections
 15    pub border_variant: Hsla,
 16    /// Border color. Used for focused elements, like keyboard focused list item.
 17    pub border_focused: Hsla,
 18    /// Border color. Used for selected elements, like an active search filter or selected checkbox.
 19    pub border_selected: Hsla,
 20    /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change.
 21    pub border_transparent: Hsla,
 22    /// Border color. Used for disabled elements, like a disabled input or button.
 23    pub border_disabled: Hsla,
 24    /// Border color. Used for elevated surfaces, like a context menu, popup, or dialog.
 25    pub elevated_surface_background: Hsla,
 26    /// Background Color. Used for grounded surfaces like a panel or tab.
 27    pub surface_background: Hsla,
 28    /// Background Color. Used for the app background and blank panels or windows.
 29    pub background: Hsla,
 30    /// Background Color. Used for the background of an element that should have a different background than the surface it's on.
 31    ///
 32    /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
 33    ///
 34    /// For an element that should have the same background as the surface it's on, use `ghost_element_background`.
 35    pub element_background: Hsla,
 36    /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on.
 37    ///
 38    /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
 39    pub element_hover: Hsla,
 40    /// Background Color. Used for the active state of an element that should have a different background than the surface it's on.
 41    ///
 42    /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressed.
 43    pub element_active: Hsla,
 44    /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on.
 45    ///
 46    /// Selected states are triggered by the element being selected (or "activated") by the user.
 47    ///
 48    /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
 49    pub element_selected: Hsla,
 50    /// Background Color. Used for the background of selections in a UI element.
 51    pub element_selection_background: Hsla,
 52    /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on.
 53    ///
 54    /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
 55    pub element_disabled: Hsla,
 56    /// Background Color. Used for the area that shows where a dragged element will be dropped.
 57    pub drop_target_background: Hsla,
 58    /// Used for the background of a ghost element that should have the same background as the surface it's on.
 59    ///
 60    /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
 61    ///
 62    /// For an element that should have a different background than the surface it's on, use `element_background`.
 63    pub ghost_element_background: Hsla,
 64    /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on.
 65    ///
 66    /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
 67    pub ghost_element_hover: Hsla,
 68    /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on.
 69    ///
 70    /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressed.
 71    pub ghost_element_active: Hsla,
 72    /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on.
 73    ///
 74    /// Selected states are triggered by the element being selected (or "activated") by the user.
 75    ///
 76    /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
 77    pub ghost_element_selected: Hsla,
 78    /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on.
 79    ///
 80    /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
 81    pub ghost_element_disabled: Hsla,
 82    /// Text Color. Default text color used for most text.
 83    pub text: Hsla,
 84    /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color.
 85    pub text_muted: Hsla,
 86    /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data.
 87    pub text_placeholder: Hsla,
 88    /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state.
 89    pub text_disabled: Hsla,
 90    /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search.
 91    pub text_accent: Hsla,
 92    /// Fill Color. Used for the default fill color of an icon.
 93    pub icon: Hsla,
 94    /// Fill Color. Used for the muted or deemphasized fill color of an icon.
 95    ///
 96    /// This might be used to show an icon in an inactive pane, or to deemphasize a series of icons to give them less visual weight.
 97    pub icon_muted: Hsla,
 98    /// Fill Color. Used for the disabled fill color of an icon.
 99    ///
100    /// Disabled states are shown when a user cannot interact with an element, like a icon button.
101    pub icon_disabled: Hsla,
102    /// Fill Color. Used for the placeholder fill color of an icon.
103    ///
104    /// This might be used to show an icon in an input that disappears when the user enters text.
105    pub icon_placeholder: Hsla,
106    /// Fill Color. Used for the accent fill color of an icon.
107    ///
108    /// This might be used to show when a toggleable icon button is selected.
109    pub icon_accent: Hsla,
110    /// Color used to accent some debugger elements
111    /// Is used by breakpoints
112    pub debugger_accent: Hsla,
113
114    // ===
115    // UI Elements
116    // ===
117    pub status_bar_background: Hsla,
118    pub title_bar_background: Hsla,
119    pub title_bar_inactive_background: Hsla,
120    pub toolbar_background: Hsla,
121    pub tab_bar_background: Hsla,
122    pub tab_inactive_background: Hsla,
123    pub tab_active_background: Hsla,
124    pub search_match_background: Hsla,
125    pub panel_background: Hsla,
126    pub panel_focused_border: Hsla,
127    pub panel_indent_guide: Hsla,
128    pub panel_indent_guide_hover: Hsla,
129    pub panel_indent_guide_active: Hsla,
130    pub pane_focused_border: Hsla,
131    pub pane_group_border: Hsla,
132    /// The color of the scrollbar thumb.
133    pub scrollbar_thumb_background: Hsla,
134    /// The color of the scrollbar thumb when hovered over.
135    pub scrollbar_thumb_hover_background: Hsla,
136    /// The color of the scrollbar thumb whilst being actively dragged.
137    pub scrollbar_thumb_active_background: Hsla,
138    /// The border color of the scrollbar thumb.
139    pub scrollbar_thumb_border: Hsla,
140    /// The background color of the scrollbar track.
141    pub scrollbar_track_background: Hsla,
142    /// The border color of the scrollbar track.
143    pub scrollbar_track_border: Hsla,
144    /// The color of the minimap thumb.
145    pub minimap_thumb_background: Hsla,
146    /// The color of the minimap thumb when hovered over.
147    pub minimap_thumb_hover_background: Hsla,
148    /// The color of the minimap thumb whilst being actively dragged.
149    pub minimap_thumb_active_background: Hsla,
150    /// The border color of the minimap thumb.
151    pub minimap_thumb_border: Hsla,
152
153    // ===
154    // Editor
155    // ===
156    pub editor_foreground: Hsla,
157    pub editor_background: Hsla,
158    pub editor_gutter_background: Hsla,
159    pub editor_subheader_background: Hsla,
160    pub editor_active_line_background: Hsla,
161    pub editor_highlighted_line_background: Hsla,
162    /// Line color of the line a debugger is currently stopped at
163    pub editor_debugger_active_line_background: Hsla,
164    /// Text Color. Used for the text of the line number in the editor gutter.
165    pub editor_line_number: Hsla,
166    /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted.
167    pub editor_active_line_number: Hsla,
168    /// Text Color. Used for the text of the line number in the editor gutter when the line is hovered over.
169    pub editor_hover_line_number: Hsla,
170    /// Text Color. Used to mark invisible characters in the editor.
171    ///
172    /// Example: spaces, tabs, carriage returns, etc.
173    pub editor_invisible: Hsla,
174    pub editor_wrap_guide: Hsla,
175    pub editor_active_wrap_guide: Hsla,
176    pub editor_indent_guide: Hsla,
177    pub editor_indent_guide_active: Hsla,
178    /// Read-access of a symbol, like reading a variable.
179    ///
180    /// A document highlight is a range inside a text document which deserves
181    /// special attention. Usually a document highlight is visualized by changing
182    /// the background color of its range.
183    pub editor_document_highlight_read_background: Hsla,
184    /// Read-access of a symbol, like reading a variable.
185    ///
186    /// A document highlight is a range inside a text document which deserves
187    /// special attention. Usually a document highlight is visualized by changing
188    /// the background color of its range.
189    pub editor_document_highlight_write_background: Hsla,
190    /// Highlighted brackets background color.
191    ///
192    /// Matching brackets in the cursor scope are highlighted with this background color.
193    pub editor_document_highlight_bracket_background: Hsla,
194
195    // ===
196    // Terminal
197    // ===
198    /// Terminal layout background color.
199    pub terminal_background: Hsla,
200    /// Terminal foreground color.
201    pub terminal_foreground: Hsla,
202    /// Bright terminal foreground color.
203    pub terminal_bright_foreground: Hsla,
204    /// Dim terminal foreground color.
205    pub terminal_dim_foreground: Hsla,
206    /// Terminal ANSI background color.
207    pub terminal_ansi_background: Hsla,
208    /// Black ANSI terminal color.
209    pub terminal_ansi_black: Hsla,
210    /// Bright black ANSI terminal color.
211    pub terminal_ansi_bright_black: Hsla,
212    /// Dim black ANSI terminal color.
213    pub terminal_ansi_dim_black: Hsla,
214    /// Red ANSI terminal color.
215    pub terminal_ansi_red: Hsla,
216    /// Bright red ANSI terminal color.
217    pub terminal_ansi_bright_red: Hsla,
218    /// Dim red ANSI terminal color.
219    pub terminal_ansi_dim_red: Hsla,
220    /// Green ANSI terminal color.
221    pub terminal_ansi_green: Hsla,
222    /// Bright green ANSI terminal color.
223    pub terminal_ansi_bright_green: Hsla,
224    /// Dim green ANSI terminal color.
225    pub terminal_ansi_dim_green: Hsla,
226    /// Yellow ANSI terminal color.
227    pub terminal_ansi_yellow: Hsla,
228    /// Bright yellow ANSI terminal color.
229    pub terminal_ansi_bright_yellow: Hsla,
230    /// Dim yellow ANSI terminal color.
231    pub terminal_ansi_dim_yellow: Hsla,
232    /// Blue ANSI terminal color.
233    pub terminal_ansi_blue: Hsla,
234    /// Bright blue ANSI terminal color.
235    pub terminal_ansi_bright_blue: Hsla,
236    /// Dim blue ANSI terminal color.
237    pub terminal_ansi_dim_blue: Hsla,
238    /// Magenta ANSI terminal color.
239    pub terminal_ansi_magenta: Hsla,
240    /// Bright magenta ANSI terminal color.
241    pub terminal_ansi_bright_magenta: Hsla,
242    /// Dim magenta ANSI terminal color.
243    pub terminal_ansi_dim_magenta: Hsla,
244    /// Cyan ANSI terminal color.
245    pub terminal_ansi_cyan: Hsla,
246    /// Bright cyan ANSI terminal color.
247    pub terminal_ansi_bright_cyan: Hsla,
248    /// Dim cyan ANSI terminal color.
249    pub terminal_ansi_dim_cyan: Hsla,
250    /// White ANSI terminal color.
251    pub terminal_ansi_white: Hsla,
252    /// Bright white ANSI terminal color.
253    pub terminal_ansi_bright_white: Hsla,
254    /// Dim white ANSI terminal color.
255    pub terminal_ansi_dim_white: Hsla,
256
257    /// Represents a link text hover color.
258    pub link_text_hover: Hsla,
259
260    /// Represents an added entry or hunk in vcs, like git.
261    pub version_control_added: Hsla,
262    /// Represents a deleted entry in version control systems.
263    pub version_control_deleted: Hsla,
264    /// Represents a modified entry in version control systems.
265    pub version_control_modified: Hsla,
266    /// Represents a renamed entry in version control systems.
267    pub version_control_renamed: Hsla,
268    /// Represents a conflicting entry in version control systems.
269    pub version_control_conflict: Hsla,
270    /// Represents an ignored entry in version control systems.
271    pub version_control_ignored: Hsla,
272
273    /// Represents the "ours" region of a merge conflict.
274    pub version_control_conflict_marker_ours: Hsla,
275    /// Represents the "theirs" region of a merge conflict.
276    pub version_control_conflict_marker_theirs: Hsla,
277}
278
279#[derive(Refineable, Clone, Debug, PartialEq)]
280pub struct ThemeStyles {
281    /// The background appearance of the window.
282    pub window_background_appearance: WindowBackgroundAppearance,
283    pub system: SystemColors,
284    /// An array of colors used for theme elements that iterate through a series of colors.
285    ///
286    /// Example: Player colors, rainbow brackets and indent guides, etc.
287    pub accents: AccentColors,
288
289    #[refineable]
290    pub colors: ThemeColors,
291
292    #[refineable]
293    pub status: StatusColors,
294
295    pub player: PlayerColors,
296
297    pub syntax: Arc<SyntaxTheme>,
298}
299
300#[cfg(test)]
301mod tests {
302    use serde_json::json;
303
304    use crate::default::default_dark_theme;
305
306    use super::*;
307
308    #[test]
309    fn override_a_single_theme_color() {
310        let mut colors = default_dark_theme().colors().clone();
311
312        let magenta: Hsla = gpui::rgb(0xff00ff).into();
313
314        assert_ne!(colors.text, magenta);
315
316        let overrides = ThemeColorsRefinement {
317            text: Some(magenta),
318            ..Default::default()
319        };
320
321        colors.refine(&overrides);
322
323        assert_eq!(colors.text, magenta);
324    }
325
326    #[test]
327    fn override_multiple_theme_colors() {
328        let mut colors = default_dark_theme().colors().clone();
329
330        let magenta: Hsla = gpui::rgb(0xff00ff).into();
331        let green: Hsla = gpui::rgb(0x00ff00).into();
332
333        assert_ne!(colors.text, magenta);
334        assert_ne!(colors.background, green);
335
336        let overrides = ThemeColorsRefinement {
337            text: Some(magenta),
338            background: Some(green),
339            ..Default::default()
340        };
341
342        colors.refine(&overrides);
343
344        assert_eq!(colors.text, magenta);
345        assert_eq!(colors.background, green);
346    }
347
348    #[test]
349    fn deserialize_theme_colors_refinement_from_json() {
350        let colors: ThemeColorsRefinement = serde_json::from_value(json!({
351            "background": "#ff00ff",
352            "text": "#ff0000"
353        }))
354        .unwrap();
355
356        assert_eq!(colors.background, Some(gpui::rgb(0xff00ff).into()));
357        assert_eq!(colors.text, Some(gpui::rgb(0xff0000).into()));
358    }
359}