theme2.rs

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