Files
oak-gpui/crates/theme2/src/theme2.rs
T
Marshall Bowers 93a818d018 Add additional status colors and style diagnostic popovers (#3846)
This PR adds additional background and border colors for each of the
status colors to the theme.

These colors are then used to style the diagnostic popovers:

<img width="407" alt="Screenshot 2024-01-02 at 4 25 50 PM"
src="https://github.com/zed-industries/zed/assets/1486634/fbc64ea7-3dcd-43b7-8520-91f16304bfba">

<img width="396" alt="Screenshot 2024-01-02 at 4 26 05 PM"
src="https://github.com/zed-industries/zed/assets/1486634/6e4a44bf-4aac-4595-afff-7fbf8b2b9e1f">

Release Notes:

- N/A
2024-01-02 16:37:55 -05:00

149 lines
3.1 KiB
Rust

mod default_colors;
mod default_theme;
mod one_themes;
pub mod prelude;
mod registry;
mod scale;
mod settings;
mod styles;
#[cfg(not(feature = "importing-themes"))]
mod themes;
mod user_theme;
use std::sync::Arc;
use ::settings::Settings;
pub use default_colors::*;
pub use default_theme::*;
pub use registry::*;
pub use scale::*;
pub use settings::*;
pub use styles::*;
#[cfg(not(feature = "importing-themes"))]
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,
}
impl Appearance {
pub fn is_light(&self) -> bool {
match self {
Self::Light => true,
Self::Dark => false,
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum LoadThemes {
/// Only load the base theme.
///
/// No user themes will be loaded.
JustBase,
/// Load all of the built-in themes.
All,
}
pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
cx.set_global(ThemeRegistry::default());
match themes_to_load {
LoadThemes::JustBase => (),
LoadThemes::All => cx.global_mut::<ThemeRegistry>().load_user_themes(),
}
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
}
}
// todo!()
// impl<'a> ActiveTheme for WindowContext<'a> {
// fn theme(&self) -> &Arc<Theme> {
// &ThemeSettings::get_global(self.app()).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 [`SystemColors`] for the theme.
#[inline(always)]
pub fn system(&self) -> &SystemColors {
&self.styles.system
}
/// Returns the [`PlayerColors`] 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) -> &Arc<SyntaxTheme> {
&self.styles.syntax
}
/// Returns the [`StatusColors`] for the theme.
#[inline(always)]
pub fn status(&self) -> &StatusColors {
&self.styles.status
}
/// 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)
}
/// Returns the [`Appearance`] for the theme.
#[inline(always)]
pub fn appearance(&self) -> Appearance {
self.appearance
}
}
pub fn color_alpha(color: Hsla, alpha: f32) -> Hsla {
let mut color = color;
color.a = alpha;
color
}