From 272f85646050d997c755ca3885080ae6ff1a4195 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 1 Nov 2023 04:33:51 +0100 Subject: [PATCH] Use `Refineable` for `ThemeStyles` (#3196) This PR updates the `ThemeStyles` struct to use the `Refineable` trait instead of a custom declarative macro for generating refinements. Release Notes: - N/A --- crates/theme2/src/colors.rs | 23 ++++++++-------- crates/theme2/src/default_theme.rs | 6 ++--- crates/theme2/src/syntax.rs | 2 +- crates/theme2/src/theme2.rs | 3 +-- crates/theme2/src/utils.rs | 43 ------------------------------ 5 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 crates/theme2/src/utils.rs diff --git a/crates/theme2/src/colors.rs b/crates/theme2/src/colors.rs index 2a59fa41bd..02c93a2e98 100644 --- a/crates/theme2/src/colors.rs +++ b/crates/theme2/src/colors.rs @@ -1,8 +1,9 @@ use gpui2::Hsla; use refineable::Refineable; -use crate::{generate_struct_with_overrides, SyntaxTheme}; +use crate::SyntaxTheme; +#[derive(Clone)] pub struct SystemColors { pub transparent: Hsla, pub mac_os_traffic_light_red: Hsla, @@ -17,6 +18,7 @@ pub struct PlayerColor { pub selection: Hsla, } +#[derive(Clone)] pub struct PlayerColors(pub Vec); #[derive(Refineable, Clone, Debug)] @@ -46,7 +48,7 @@ pub struct GitStatusColors { pub renamed: Hsla, } -#[derive(Refineable, Clone, Debug)] +#[derive(Refineable, Clone, Debug, Default)] #[refineable(debug)] pub struct ThemeColors { pub border: Hsla, @@ -86,15 +88,14 @@ pub struct ThemeColors { pub editor_active_line: Hsla, } -generate_struct_with_overrides! { - ThemeStyle, - ThemeStyleOverrides, - system: SystemColors, - colors: ThemeColors, - status: StatusColors, - git: GitStatusColors, - player: PlayerColors, - syntax: SyntaxTheme +#[derive(Refineable, Clone)] +pub struct ThemeStyles { + pub system: SystemColors, + pub colors: ThemeColors, + pub status: StatusColors, + pub git: GitStatusColors, + pub player: PlayerColors, + pub syntax: SyntaxTheme, } #[cfg(test)] diff --git a/crates/theme2/src/default_theme.rs b/crates/theme2/src/default_theme.rs index 26a55b5e0d..d7360b6f71 100644 --- a/crates/theme2/src/default_theme.rs +++ b/crates/theme2/src/default_theme.rs @@ -1,5 +1,5 @@ use crate::{ - colors::{GitStatusColors, PlayerColors, StatusColors, SystemColors, ThemeColors, ThemeStyle}, + colors::{GitStatusColors, PlayerColors, StatusColors, SystemColors, ThemeColors, ThemeStyles}, default_color_scales, Appearance, SyntaxTheme, ThemeFamily, ThemeVariant, }; @@ -8,7 +8,7 @@ fn zed_pro_daylight() -> ThemeVariant { id: "zed_pro_daylight".to_string(), name: "Zed Pro Daylight".into(), appearance: Appearance::Light, - styles: ThemeStyle { + styles: ThemeStyles { system: SystemColors::default(), colors: ThemeColors::default_light(), status: StatusColors::default(), @@ -24,7 +24,7 @@ pub(crate) fn zed_pro_moonlight() -> ThemeVariant { id: "zed_pro_moonlight".to_string(), name: "Zed Pro Moonlight".into(), appearance: Appearance::Dark, - styles: ThemeStyle { + styles: ThemeStyles { system: SystemColors::default(), colors: ThemeColors::default_dark(), status: StatusColors::default(), diff --git a/crates/theme2/src/syntax.rs b/crates/theme2/src/syntax.rs index 1cf8564bca..a8127f0c44 100644 --- a/crates/theme2/src/syntax.rs +++ b/crates/theme2/src/syntax.rs @@ -1,6 +1,6 @@ use gpui2::{HighlightStyle, Hsla}; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct SyntaxTheme { pub highlights: Vec<(String, HighlightStyle)>, } diff --git a/crates/theme2/src/theme2.rs b/crates/theme2/src/theme2.rs index 372e976bd3..34727eaf89 100644 --- a/crates/theme2/src/theme2.rs +++ b/crates/theme2/src/theme2.rs @@ -5,7 +5,6 @@ mod registry; mod scale; mod settings; mod syntax; -mod utils; pub use colors::*; pub use default_colors::*; @@ -55,7 +54,7 @@ pub struct ThemeVariant { pub(crate) id: String, pub name: SharedString, pub appearance: Appearance, - pub styles: ThemeStyle, + pub styles: ThemeStyles, } impl ThemeVariant { diff --git a/crates/theme2/src/utils.rs b/crates/theme2/src/utils.rs deleted file mode 100644 index ccdcde4274..0000000000 --- a/crates/theme2/src/utils.rs +++ /dev/null @@ -1,43 +0,0 @@ -/// This macro generates a struct and a corresponding struct with optional fields. -/// -/// It takes as input the name of the struct to be generated, the name of the struct with optional fields, -/// and a list of field names along with their types. -/// -/// # Example -/// ``` -/// generate_struct_with_overrides!( -/// MyStruct, -/// MyStructOverride, -/// field1: i32, -/// field2: String -/// ); -/// ``` -/// This will generate the following structs: -/// ``` -/// pub struct MyStruct { -/// pub field1: i32, -/// pub field2: String, -/// } -/// -/// pub struct MyStructOverride { -/// pub field1: Option, -/// pub field2: Option, -/// } -/// ``` -#[macro_export] -macro_rules! generate_struct_with_overrides { - ($struct_name:ident, $struct_override_name:ident, $($field:ident: $type:ty),*) => { - pub struct $struct_name { - $( - pub $field: $type, - )* - } - - #[allow(dead_code)] - pub struct $struct_override_name { - $( - pub $field: Option<$type>, - )* - } - }; -}