Rework theme2 with new theme structure (#3194)

This PR reworks the theme definition in the `theme2` crate to be based
off of the new theme work that @iamnbutler has been working on.

We're still developing the new theme system, but it is complete enough
that we can now load the default theme and use it to theme the storybook
(albeit with some further refining of the color palette required).

---------

Co-authored-by: Nate Butler <iamnbutler@gmail.com>
Co-authored-by: Marshall Bowers <marshall@zed.dev>
This commit is contained in:
Marshall Bowers 2023-11-01 03:23:00 +01:00 committed by GitHub
parent ed5f1d3bdd
commit 18431051d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 1615 additions and 494 deletions

View file

@ -1,17 +1,25 @@
mod default;
mod colors;
mod default_colors;
mod default_theme;
mod registry;
mod scale;
mod settings;
mod syntax;
mod themes;
mod utils;
pub use default::*;
pub use colors::*;
pub use default_colors::*;
pub use default_theme::*;
pub use registry::*;
pub use scale::*;
pub use settings::*;
pub use syntax::*;
use std::sync::Arc;
use gpui2::{AppContext, HighlightStyle, Hsla, SharedString};
use settings2::Settings;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq)]
pub enum Appearance {
@ -24,12 +32,53 @@ pub fn init(cx: &mut AppContext) {
ThemeSettings::register(cx);
}
pub fn active_theme<'a>(cx: &'a AppContext) -> &'a Arc<Theme> {
&ThemeSettings::get_global(cx).active_theme
pub trait ActiveTheme {
fn theme(&self) -> &ThemeVariant;
}
pub fn theme(cx: &AppContext) -> Arc<Theme> {
active_theme(cx).clone()
impl ActiveTheme for AppContext {
fn theme(&self) -> &ThemeVariant {
&ThemeSettings::get_global(self).active_theme
}
}
pub struct ThemeFamily {
#[allow(dead_code)]
pub(crate) id: String,
pub name: String,
pub author: String,
pub themes: Vec<ThemeVariant>,
pub scales: ColorScales,
}
impl ThemeFamily {}
pub struct ThemeVariant {
#[allow(dead_code)]
pub(crate) id: String,
pub name: String,
pub appearance: Appearance,
pub styles: ThemeStyle,
}
impl ThemeVariant {
/// Returns the [`ThemeColors`] for the theme.
#[inline(always)]
pub fn colors(&self) -> &ThemeColors {
&self.styles.colors
}
/// Returns the [`SyntaxStyles`] for the theme.
#[inline(always)]
pub fn syntax(&self) -> &SyntaxStyles {
&self.styles.syntax
}
/// 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)
}
}
pub struct Theme {