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 struct Theme {
 22    pub metadata: ThemeMetadata,
 23
 24    pub transparent: Hsla,
 25    pub mac_os_traffic_light_red: Hsla,
 26    pub mac_os_traffic_light_yellow: Hsla,
 27    pub mac_os_traffic_light_green: Hsla,
 28    pub border: Hsla,
 29    pub border_variant: Hsla,
 30    pub border_focused: Hsla,
 31    pub border_transparent: Hsla,
 32    /// The background color of an elevated surface, like a modal, tooltip or toast.
 33    pub elevated_surface: Hsla,
 34    pub surface: Hsla,
 35    /// Window background color of the base app
 36    pub background: Hsla,
 37    /// Default background for elements like filled buttons,
 38    /// text fields, checkboxes, radio buttons, etc.
 39    /// - TODO: Map to step 3.
 40    pub filled_element: Hsla,
 41    /// The background color of a hovered element, like a button being hovered
 42    /// with a mouse, or hovered on a touch screen.
 43    /// - TODO: Map to step 4.
 44    pub filled_element_hover: Hsla,
 45    /// The background color of an active element, like a button being pressed,
 46    /// or tapped on a touch screen.
 47    /// - TODO: Map to step 5.
 48    pub filled_element_active: Hsla,
 49    /// The background color of a selected element, like a selected tab,
 50    /// a button toggled on, or a checkbox that is checked.
 51    pub filled_element_selected: Hsla,
 52    pub filled_element_disabled: Hsla,
 53    pub ghost_element: Hsla,
 54    /// The background color of a hovered element with no default background,
 55    /// like a ghost-style button or an interactable list item.
 56    /// - TODO: Map to step 3.
 57    pub ghost_element_hover: Hsla,
 58    /// - TODO: Map to step 4.
 59    pub ghost_element_active: Hsla,
 60    pub ghost_element_selected: Hsla,
 61    pub ghost_element_disabled: Hsla,
 62    pub text: Hsla,
 63    pub text_muted: Hsla,
 64    pub text_placeholder: Hsla,
 65    pub text_disabled: Hsla,
 66    pub text_accent: Hsla,
 67    pub icon_muted: Hsla,
 68    pub syntax: SyntaxTheme,
 69
 70    pub status_bar: Hsla,
 71    pub title_bar: Hsla,
 72    pub toolbar: Hsla,
 73    pub tab_bar: Hsla,
 74    /// The background of the editor
 75    pub editor: Hsla,
 76    pub editor_subheader: Hsla,
 77    pub editor_active_line: Hsla,
 78    pub terminal: Hsla,
 79    pub image_fallback_background: Hsla,
 80
 81    pub git_created: Hsla,
 82    pub git_modified: Hsla,
 83    pub git_deleted: Hsla,
 84    pub git_conflict: Hsla,
 85    pub git_ignored: Hsla,
 86    pub git_renamed: Hsla,
 87
 88    pub players: [PlayerTheme; 8],
 89}
 90
 91#[derive(Clone)]
 92pub struct SyntaxTheme {
 93    pub comment: Hsla,
 94    pub string: Hsla,
 95    pub function: Hsla,
 96    pub keyword: Hsla,
 97    pub highlights: Vec<(String, HighlightStyle)>,
 98}
 99
100#[derive(Clone, Copy)]
101pub struct PlayerTheme {
102    pub cursor: Hsla,
103    pub selection: Hsla,
104}
105
106#[derive(Clone)]
107pub struct ThemeMetadata {
108    pub name: SharedString,
109    pub is_light: bool,
110}
111
112pub struct Editor {
113    pub syntax: Arc<SyntaxTheme>,
114}