Files
oak-gpui/crates/theme2/src/theme2.rs
T
Marshall Bowers 36a73d657a Remove old Theme definition (#3195)
This PR removes the old `Theme` definition in favor of the new
`ThemeVariant`s.

The new `SyntaxStyles` have been reverted to the old `SyntaxTheme` that
operates by storing the syntax styles as a vector of
`gpui2::HighlightStyle`s.

This is necessary for the intended usage by `language2`, where we find
the longest key in the theme's syntax styles that matches the capture
name:

https://github.com/zed-industries/zed/blob/18431051d9d750d9e66284a71f7a55a1e31c1374/crates/language2/src/highlight_map.rs#L15-L41
2023-10-31 23:05:50 -04:00

80 lines
1.6 KiB
Rust

mod colors;
mod default_colors;
mod default_theme;
mod registry;
mod scale;
mod settings;
mod syntax;
mod utils;
pub use colors::*;
pub use default_colors::*;
pub use default_theme::*;
pub use registry::*;
pub use scale::*;
pub use settings::*;
pub use syntax::*;
use gpui2::{AppContext, Hsla, SharedString};
use settings2::Settings;
#[derive(Debug, Clone, PartialEq)]
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) -> &ThemeVariant;
}
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: SharedString,
pub author: SharedString,
pub themes: Vec<ThemeVariant>,
pub scales: ColorScales,
}
impl ThemeFamily {}
pub struct ThemeVariant {
#[allow(dead_code)]
pub(crate) id: String,
pub name: SharedString,
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 [`SyntaxTheme`] for the theme.
#[inline(always)]
pub fn syntax(&self) -> &SyntaxTheme {
&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)
}
}