theme2.rs

  1mod default_colors;
  2mod default_theme;
  3mod one_themes;
  4mod registry;
  5mod scale;
  6mod settings;
  7mod styles;
  8#[cfg(not(feature = "importing-themes"))]
  9mod themes;
 10mod user_theme;
 11
 12use std::sync::Arc;
 13
 14use ::settings::Settings;
 15pub use default_colors::*;
 16pub use default_theme::*;
 17pub use registry::*;
 18pub use scale::*;
 19pub use settings::*;
 20pub use styles::*;
 21#[cfg(not(feature = "importing-themes"))]
 22pub use themes::*;
 23pub use user_theme::*;
 24
 25use gpui::{AppContext, Hsla, SharedString};
 26use serde::Deserialize;
 27
 28#[derive(Debug, PartialEq, Clone, Copy, Deserialize)]
 29pub enum Appearance {
 30    Light,
 31    Dark,
 32}
 33
 34#[derive(Debug, PartialEq, Eq, Clone, Copy)]
 35pub enum LoadThemes {
 36    /// Only load the base theme.
 37    ///
 38    /// No user themes will be loaded.
 39    JustBase,
 40
 41    /// Load all of the built-in themes.
 42    All,
 43}
 44
 45pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
 46    cx.set_global(ThemeRegistry::default());
 47
 48    match themes_to_load {
 49        LoadThemes::JustBase => (),
 50        LoadThemes::All => cx.global_mut::<ThemeRegistry>().load_user_themes(),
 51    }
 52
 53    ThemeSettings::register(cx);
 54}
 55
 56pub trait ActiveTheme {
 57    fn theme(&self) -> &Arc<Theme>;
 58}
 59
 60impl ActiveTheme for AppContext {
 61    fn theme(&self) -> &Arc<Theme> {
 62        &ThemeSettings::get_global(self).active_theme
 63    }
 64}
 65
 66pub struct ThemeFamily {
 67    pub id: String,
 68    pub name: SharedString,
 69    pub author: SharedString,
 70    pub themes: Vec<Theme>,
 71    pub scales: ColorScales,
 72}
 73
 74impl ThemeFamily {}
 75
 76pub struct Theme {
 77    pub id: String,
 78    pub name: SharedString,
 79    pub appearance: Appearance,
 80    pub styles: ThemeStyles,
 81}
 82
 83impl Theme {
 84    /// Returns the [`SystemColors`] for the theme.
 85    #[inline(always)]
 86    pub fn system(&self) -> &SystemColors {
 87        &self.styles.system
 88    }
 89
 90    /// Returns the [`PlayerColors`] for the theme.
 91    #[inline(always)]
 92    pub fn players(&self) -> &PlayerColors {
 93        &self.styles.player
 94    }
 95
 96    /// Returns the [`ThemeColors`] for the theme.
 97    #[inline(always)]
 98    pub fn colors(&self) -> &ThemeColors {
 99        &self.styles.colors
100    }
101
102    /// Returns the [`SyntaxTheme`] for the theme.
103    #[inline(always)]
104    pub fn syntax(&self) -> &Arc<SyntaxTheme> {
105        &self.styles.syntax
106    }
107
108    /// Returns the [`StatusColors`] for the theme.
109    #[inline(always)]
110    pub fn status(&self) -> &StatusColors {
111        &self.styles.status
112    }
113
114    /// Returns the color for the syntax node with the given name.
115    #[inline(always)]
116    pub fn syntax_color(&self, name: &str) -> Hsla {
117        self.syntax().color(name)
118    }
119
120    /// Returns the [`DiagnosticStyle`] for the theme.
121    #[inline(always)]
122    pub fn diagnostic_style(&self) -> DiagnosticStyle {
123        DiagnosticStyle {
124            error: self.status().error,
125            warning: self.status().warning,
126            info: self.status().info,
127            hint: self.status().info,
128            ignored: self.status().ignored,
129        }
130    }
131}
132
133#[derive(Clone, Debug, Default)]
134pub struct DiagnosticStyle {
135    pub error: Hsla,
136    pub warning: Hsla,
137    pub info: Hsla,
138    pub hint: Hsla,
139    pub ignored: Hsla,
140}
141
142#[cfg(feature = "stories")]
143mod story;
144#[cfg(feature = "stories")]
145pub use story::*;