Remove old theme constructs

This commit is contained in:
Marshall Bowers 2023-10-30 14:47:38 -04:00
parent 1a54ac0d69
commit ba789fc0c4
9 changed files with 21 additions and 1874 deletions

View file

@ -1,9 +1,9 @@
use crate::themes::rose_pine;
use gpui2::{
div, Focusable, KeyBinding, ParentElement, StatelessInteractive, Styled, View, VisualContext,
WindowContext,
};
use serde::Deserialize;
use theme2::theme;
#[derive(Clone, Default, PartialEq, Deserialize)]
struct ActionA;
@ -27,14 +27,14 @@ impl FocusStory {
]);
cx.register_action_type::<ActionA>();
cx.register_action_type::<ActionB>();
let theme = rose_pine();
let theme = theme(cx);
let color_1 = theme.lowest.negative.default.foreground;
let color_2 = theme.lowest.positive.default.foreground;
let color_3 = theme.lowest.warning.default.foreground;
let color_4 = theme.lowest.accent.default.foreground;
let color_5 = theme.lowest.variant.default.foreground;
let color_6 = theme.highest.negative.default.foreground;
let color_1 = theme.git_created;
let color_2 = theme.git_modified;
let color_3 = theme.git_deleted;
let color_4 = theme.git_conflict;
let color_5 = theme.git_ignored;
let color_6 = theme.git_renamed;
let child_1 = cx.focus_handle();
let child_2 = cx.focus_handle();

View file

@ -1,7 +1,7 @@
use crate::themes::rose_pine;
use gpui2::{
div, px, Component, ParentElement, SharedString, Styled, View, VisualContext, WindowContext,
};
use theme2::theme;
pub struct ScrollStory {
text: View<()>,
@ -9,25 +9,21 @@ pub struct ScrollStory {
impl ScrollStory {
pub fn view(cx: &mut WindowContext) -> View<()> {
let theme = rose_pine();
{
cx.build_view(|cx| (), move |_, cx| checkerboard(1))
}
cx.build_view(|cx| (), move |_, cx| checkerboard(cx, 1))
}
}
fn checkerboard<S>(depth: usize) -> impl Component<S>
fn checkerboard<S>(cx: &mut WindowContext, depth: usize) -> impl Component<S>
where
S: 'static + Send + Sync,
{
let theme = rose_pine();
let color_1 = theme.lowest.positive.default.background;
let color_2 = theme.lowest.warning.default.background;
let theme = theme(cx);
let color_1 = theme.git_created;
let color_2 = theme.git_modified;
div()
.id("parent")
.bg(theme.lowest.base.default.background)
.bg(theme.background)
.size_full()
.overflow_scroll()
.children((0..10).map(|row| {

View file

@ -4,7 +4,6 @@ mod assets;
mod stories;
mod story;
mod story_selector;
mod themes;
use std::sync::Arc;
@ -50,7 +49,6 @@ fn main() {
let story_selector = args.story.clone();
let theme_name = args.theme.unwrap_or("One Dark".to_string());
let theme = themes::load_theme(theme_name.clone()).unwrap();
let asset_source = Arc::new(Assets);
gpui2::App::production(asset_source).run(move |cx| {

View file

@ -1,30 +0,0 @@
mod rose_pine;
pub use rose_pine::*;
use anyhow::{Context, Result};
use gpui2::serde_json;
use serde::Deserialize;
use ui::Theme;
use crate::assets::Assets;
#[derive(Deserialize)]
struct LegacyTheme {
pub base_theme: serde_json::Value,
}
/// Loads the [`Theme`] with the given name.
pub fn load_theme(name: String) -> Result<Theme> {
let theme_contents = Assets::get(&format!("themes/{name}.json"))
.with_context(|| format!("theme file not found: '{name}'"))?;
let legacy_theme: LegacyTheme =
serde_json::from_str(std::str::from_utf8(&theme_contents.data)?)
.context("failed to parse legacy theme")?;
let theme: Theme = serde_json::from_value(legacy_theme.base_theme.clone())
.context("failed to parse `base_theme`")?;
Ok(theme)
}

File diff suppressed because it is too large Load diff

View file

@ -18,6 +18,10 @@ pub fn active_theme<'a>(cx: &'a AppContext) -> &'a Arc<Theme> {
&ThemeSettings::get_global(cx).active_theme
}
pub fn theme(cx: &AppContext) -> Arc<Theme> {
active_theme(cx).clone()
}
pub struct Theme {
pub metadata: ThemeMetadata,

View file

@ -23,7 +23,6 @@ mod elevation;
pub mod prelude;
pub mod settings;
mod static_data;
mod theme;
pub use components::*;
pub use elements::*;
@ -38,7 +37,6 @@ pub use static_data::*;
// AFAICT this is something to do with conflicting names between crates and modules that
// interfaces with declaring the `ClassDecl`.
pub use crate::settings::*;
pub use crate::theme::*;
#[cfg(feature = "stories")]
mod story;

View file

@ -5,7 +5,8 @@ pub use gpui2::{
pub use crate::elevation::*;
use crate::settings::user_settings;
pub use crate::{theme, ButtonVariant};
pub use crate::ButtonVariant;
pub use theme2::theme;
use gpui2::{rems, Hsla, Rems};
use strum::EnumIter;

View file

@ -1,134 +0,0 @@
use gpui2::{AppContext, Hsla, Result};
use serde::{de::Visitor, Deserialize, Deserializer};
use std::collections::HashMap;
use std::fmt;
use std::sync::Arc;
#[derive(Deserialize, Clone, Default, Debug)]
pub struct Theme {
pub name: String,
pub is_light: bool,
pub lowest: Layer,
pub middle: Layer,
pub highest: Layer,
pub popover_shadow: Shadow,
pub modal_shadow: Shadow,
#[serde(deserialize_with = "deserialize_player_colors")]
pub players: Vec<PlayerColors>,
#[serde(deserialize_with = "deserialize_syntax_colors")]
pub syntax: HashMap<String, Hsla>,
}
#[derive(Deserialize, Clone, Default, Debug)]
pub struct Layer {
pub base: StyleSet,
pub variant: StyleSet,
pub on: StyleSet,
pub accent: StyleSet,
pub positive: StyleSet,
pub warning: StyleSet,
pub negative: StyleSet,
}
#[derive(Deserialize, Clone, Default, Debug)]
pub struct StyleSet {
#[serde(rename = "default")]
pub default: ContainerColors,
pub hovered: ContainerColors,
pub pressed: ContainerColors,
pub active: ContainerColors,
pub disabled: ContainerColors,
pub inverted: ContainerColors,
}
#[derive(Deserialize, Clone, Default, Debug)]
pub struct ContainerColors {
pub background: Hsla,
pub foreground: Hsla,
pub border: Hsla,
}
#[derive(Deserialize, Clone, Default, Debug)]
pub struct PlayerColors {
pub selection: Hsla,
pub cursor: Hsla,
}
#[derive(Deserialize, Clone, Default, Debug)]
pub struct Shadow {
pub blur: u8,
pub color: Hsla,
pub offset: Vec<u8>,
}
fn deserialize_player_colors<'de, D>(deserializer: D) -> Result<Vec<PlayerColors>, D::Error>
where
D: Deserializer<'de>,
{
struct PlayerArrayVisitor;
impl<'de> Visitor<'de> for PlayerArrayVisitor {
type Value = Vec<PlayerColors>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("an object with integer keys")
}
fn visit_map<A: serde::de::MapAccess<'de>>(
self,
mut map: A,
) -> Result<Self::Value, A::Error> {
let mut players = Vec::with_capacity(8);
while let Some((key, value)) = map.next_entry::<usize, PlayerColors>()? {
if key < 8 {
players.push(value);
} else {
return Err(serde::de::Error::invalid_value(
serde::de::Unexpected::Unsigned(key as u64),
&"a key in range 0..7",
));
}
}
Ok(players)
}
}
deserializer.deserialize_map(PlayerArrayVisitor)
}
fn deserialize_syntax_colors<'de, D>(deserializer: D) -> Result<HashMap<String, Hsla>, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
struct ColorWrapper {
color: Hsla,
}
struct SyntaxVisitor;
impl<'de> Visitor<'de> for SyntaxVisitor {
type Value = HashMap<String, Hsla>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a map with keys and objects with a single color field as values")
}
fn visit_map<M>(self, mut map: M) -> Result<HashMap<String, Hsla>, M::Error>
where
M: serde::de::MapAccess<'de>,
{
let mut result = HashMap::new();
while let Some(key) = map.next_key()? {
let wrapper: ColorWrapper = map.next_value()?; // Deserialize values as Hsla
result.insert(key, wrapper.color);
}
Ok(result)
}
}
deserializer.deserialize_map(SyntaxVisitor)
}
pub fn theme(cx: &AppContext) -> Arc<theme2::Theme> {
theme2::active_theme(cx).clone()
}