This PR reworks the way we define our third-party themes to make them work as overlays on top of a base theme. We introduce the concept of a `UserThemeFamily` that contains `UserTheme`s. Rather than being an entire theme definition on their own, a `UserTheme` just contains optional overrides for the values in a `Theme`. When resolving a `UserTheme`, we apply it on top of the base theme. Any values not overridden in the `UserTheme` will fall back to the `Theme` defaults. Right now we are just using `UserTheme` to model third-party themes that we distribute with the Zed binary. However, this same structure can also be used to import arbitrary user themes (such as from a theme registry, or even a theme blob from the settings file). Release Notes: - N/A
102 lines
2.1 KiB
Rust
102 lines
2.1 KiB
Rust
mod colors;
|
|
mod default_colors;
|
|
mod default_theme;
|
|
mod registry;
|
|
mod scale;
|
|
mod settings;
|
|
mod syntax;
|
|
mod themes;
|
|
mod user_theme;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use ::settings::Settings;
|
|
pub use colors::*;
|
|
pub use default_colors::*;
|
|
pub use default_theme::*;
|
|
pub use registry::*;
|
|
pub use scale::*;
|
|
pub use settings::*;
|
|
pub use syntax::*;
|
|
pub use themes::*;
|
|
pub use user_theme::*;
|
|
|
|
use gpui::{AppContext, Hsla, SharedString};
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Debug, PartialEq, Clone, Copy, Deserialize)]
|
|
pub enum Appearance {
|
|
Light,
|
|
Dark,
|
|
}
|
|
|
|
pub fn init(cx: &mut AppContext) {
|
|
cx.set_global(ThemeRegistry::default());
|
|
ThemeSettings::register(cx);
|
|
}
|
|
|
|
pub trait ActiveTheme {
|
|
fn theme(&self) -> &Arc<Theme>;
|
|
}
|
|
|
|
impl ActiveTheme for AppContext {
|
|
fn theme(&self) -> &Arc<Theme> {
|
|
&ThemeSettings::get_global(self).active_theme
|
|
}
|
|
}
|
|
|
|
pub struct ThemeFamily {
|
|
pub id: String,
|
|
pub name: SharedString,
|
|
pub author: SharedString,
|
|
pub themes: Vec<Theme>,
|
|
pub scales: ColorScales,
|
|
}
|
|
|
|
impl ThemeFamily {}
|
|
|
|
pub struct Theme {
|
|
pub id: String,
|
|
pub name: SharedString,
|
|
pub appearance: Appearance,
|
|
pub styles: ThemeStyles,
|
|
}
|
|
|
|
impl Theme {
|
|
/// Returns the [`ThemeColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn players(&self) -> &PlayerColors {
|
|
&self.styles.player
|
|
}
|
|
|
|
/// Returns the [`ThemeColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn colors(&self) -> &ThemeColors {
|
|
&self.styles.colors
|
|
}
|
|
|
|
/// Returns the [`SyntaxTheme`] for the theme.
|
|
#[inline(always)]
|
|
pub fn syntax(&self) -> &SyntaxTheme {
|
|
&self.styles.syntax
|
|
}
|
|
|
|
/// Returns the [`StatusColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn status(&self) -> &StatusColors {
|
|
&self.styles.status
|
|
}
|
|
|
|
/// Returns the [`GitStatusColors`] for the theme.
|
|
#[inline(always)]
|
|
pub fn git(&self) -> &GitStatusColors {
|
|
&self.styles.git
|
|
}
|
|
|
|
/// Returns the color for the syntax node with the given name.
|
|
#[inline(always)]
|
|
pub fn syntax_color(&self, name: &str) -> Hsla {
|
|
self.syntax().color(name)
|
|
}
|
|
}
|