Merge branch 'theme-color-scales' into zed2

This commit is contained in:
Marshall Bowers
2023-10-30 17:31:51 -04:00
6 changed files with 2324 additions and 0 deletions
+2
View File
@@ -1,9 +1,11 @@
mod colors;
mod focus;
mod kitchen_sink;
mod scroll;
mod text;
mod z_index;
pub use colors::*;
pub use focus::*;
pub use kitchen_sink::*;
pub use scroll::*;
+28
View File
@@ -0,0 +1,28 @@
use ui::prelude::*;
use crate::story::Story;
#[derive(Component)]
pub struct ColorsStory;
impl ColorsStory {
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let color_scales = theme2::default_color_scales();
Story::container(cx)
.child(Story::title(cx, "Colors"))
.child(
div()
.id("colors")
.flex()
.flex_col()
.overflow_y_scroll()
.text_color(gpui2::white())
.children(color_scales.into_iter().map(|(name, scale)| {
div().child(name.to_string()).child(div().flex().children(
(1..=12).map(|step| div().flex().size_4().bg(scale.step(cx, step))),
))
})),
)
}
}
+2
View File
@@ -14,6 +14,7 @@ use ui::prelude::*;
pub enum ElementStory {
Avatar,
Button,
Colors,
Details,
Focus,
Icon,
@@ -29,6 +30,7 @@ impl ElementStory {
match self {
Self::Avatar => { cx.build_view(|cx| (), |_, _| ui::AvatarStory.render()) }.into_any(),
Self::Button => { cx.build_view(|cx| (), |_, _| ui::ButtonStory.render()) }.into_any(),
Self::Colors => { cx.build_view(|cx| (), |_, _| ColorsStory.render()) }.into_any(),
Self::Details => {
{ cx.build_view(|cx| (), |_, _| ui::DetailsStory.render()) }.into_any()
}
File diff suppressed because it is too large Load Diff
+164
View File
@@ -0,0 +1,164 @@
use gpui2::{AppContext, Hsla};
use indexmap::IndexMap;
use crate::{theme, Appearance};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ColorScaleName {
Gray,
Mauve,
Slate,
Sage,
Olive,
Sand,
Gold,
Bronze,
Brown,
Yellow,
Amber,
Orange,
Tomato,
Red,
Ruby,
Crimson,
Pink,
Plum,
Purple,
Violet,
Iris,
Indigo,
Blue,
Cyan,
Teal,
Jade,
Green,
Grass,
Lime,
Mint,
Sky,
Black,
White,
}
impl std::fmt::Display for ColorScaleName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::Gray => "Gray",
Self::Mauve => "Mauve",
Self::Slate => "Slate",
Self::Sage => "Sage",
Self::Olive => "Olive",
Self::Sand => "Sand",
Self::Gold => "Gold",
Self::Bronze => "Bronze",
Self::Brown => "Brown",
Self::Yellow => "Yellow",
Self::Amber => "Amber",
Self::Orange => "Orange",
Self::Tomato => "Tomato",
Self::Red => "Red",
Self::Ruby => "Ruby",
Self::Crimson => "Crimson",
Self::Pink => "Pink",
Self::Plum => "Plum",
Self::Purple => "Purple",
Self::Violet => "Violet",
Self::Iris => "Iris",
Self::Indigo => "Indigo",
Self::Blue => "Blue",
Self::Cyan => "Cyan",
Self::Teal => "Teal",
Self::Jade => "Jade",
Self::Green => "Green",
Self::Grass => "Grass",
Self::Lime => "Lime",
Self::Mint => "Mint",
Self::Sky => "Sky",
Self::Black => "Black",
Self::White => "White",
}
)
}
}
pub type ColorScale = [Hsla; 12];
pub type ColorScales = IndexMap<ColorScaleName, ColorScaleSet>;
/// A one-based step in a [`ColorScale`].
pub type ColorScaleStep = usize;
pub struct ColorScaleSet {
name: ColorScaleName,
light: ColorScale,
dark: ColorScale,
light_alpha: ColorScale,
dark_alpha: ColorScale,
}
impl ColorScaleSet {
pub fn new(
name: ColorScaleName,
light: ColorScale,
light_alpha: ColorScale,
dark: ColorScale,
dark_alpha: ColorScale,
) -> Self {
Self {
name,
light,
light_alpha,
dark,
dark_alpha,
}
}
pub fn name(&self) -> String {
self.name.to_string()
}
pub fn light(&self, step: ColorScaleStep) -> Hsla {
self.light[step - 1]
}
pub fn light_alpha(&self, step: ColorScaleStep) -> Hsla {
self.light_alpha[step - 1]
}
pub fn dark(&self, step: ColorScaleStep) -> Hsla {
self.dark[step - 1]
}
pub fn dark_alpha(&self, step: ColorScaleStep) -> Hsla {
self.dark[step - 1]
}
fn current_appearance(cx: &AppContext) -> Appearance {
let theme = theme(cx);
if theme.metadata.is_light {
Appearance::Light
} else {
Appearance::Dark
}
}
pub fn step(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
let appearance = Self::current_appearance(cx);
match appearance {
Appearance::Light => self.light(step),
Appearance::Dark => self.dark(step),
}
}
pub fn step_alpha(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
let appearance = Self::current_appearance(cx);
match appearance {
Appearance::Light => self.light_alpha(step),
Appearance::Dark => self.dark_alpha(step),
}
}
}
+10
View File
@@ -1,14 +1,24 @@
mod default;
mod registry;
mod scale;
mod settings;
mod themes;
pub use default::*;
pub use registry::*;
pub use scale::*;
pub use settings::*;
use gpui2::{AppContext, HighlightStyle, Hsla, SharedString};
use settings2::Settings;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq)]
pub enum Appearance {
Light,
Dark,
}
pub fn init(cx: &mut AppContext) {
cx.set_global(ThemeRegistry::default());
ThemeSettings::register(cx);