Generalize Refineable derive macro to derive arbitrary traits on the refinement type
This commit is contained in:
parent
dba41e99dd
commit
28d3d21108
6 changed files with 24 additions and 40 deletions
|
@ -136,7 +136,7 @@ impl ToJson for RectF {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Debug)]
|
#[derive(Refineable, Debug)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
pub struct Point<T: Clone + Default + Debug> {
|
pub struct Point<T: Clone + Default + Debug> {
|
||||||
pub x: T,
|
pub x: T,
|
||||||
pub y: T,
|
pub y: T,
|
||||||
|
@ -161,7 +161,7 @@ impl<T: Clone + Default + Debug> Into<taffy::geometry::Point<T>> for Point<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Clone, Debug)]
|
#[derive(Refineable, Clone, Debug)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
pub struct Size<T: Clone + Default + Debug> {
|
pub struct Size<T: Clone + Default + Debug> {
|
||||||
pub width: T,
|
pub width: T,
|
||||||
pub height: T,
|
pub height: T,
|
||||||
|
@ -227,7 +227,7 @@ impl Size<Length> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Refineable, Debug)]
|
#[derive(Clone, Default, Refineable, Debug)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
pub struct Edges<T: Clone + Default + Debug> {
|
pub struct Edges<T: Clone + Default + Debug> {
|
||||||
pub top: T,
|
pub top: T,
|
||||||
pub right: T,
|
pub right: T,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Refineable, Default, Add, AddAssign, Sub, SubAssign, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Refineable, Default, Add, AddAssign, Sub, SubAssign, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Point<T: Default + Clone + Debug> {
|
pub struct Point<T: Default + Clone + Debug> {
|
||||||
pub x: T,
|
pub x: T,
|
||||||
|
@ -140,7 +140,7 @@ impl<T: Clone + Default + Debug> Clone for Point<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Default, Clone, Copy, PartialEq, Div, Hash, Serialize, Deserialize)]
|
#[derive(Refineable, Default, Clone, Copy, PartialEq, Div, Hash, Serialize, Deserialize)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Size<T: Clone + Default + Debug> {
|
pub struct Size<T: Clone + Default + Debug> {
|
||||||
pub width: T,
|
pub width: T,
|
||||||
|
@ -313,7 +313,7 @@ impl Size<Length> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
|
#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Bounds<T: Clone + Default + Debug> {
|
pub struct Bounds<T: Clone + Default + Debug> {
|
||||||
pub origin: Point<T>,
|
pub origin: Point<T>,
|
||||||
|
@ -477,7 +477,7 @@ impl Bounds<Pixels> {
|
||||||
impl<T: Clone + Debug + Copy + Default> Copy for Bounds<T> {}
|
impl<T: Clone + Debug + Copy + Default> Copy for Bounds<T> {}
|
||||||
|
|
||||||
#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
|
#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Edges<T: Clone + Default + Debug> {
|
pub struct Edges<T: Clone + Default + Debug> {
|
||||||
pub top: T,
|
pub top: T,
|
||||||
|
@ -619,7 +619,7 @@ impl Edges<Pixels> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
|
#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Corners<T: Clone + Default + Debug> {
|
pub struct Corners<T: Clone + Default + Debug> {
|
||||||
pub top_left: T,
|
pub top_left: T,
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub use taffy::style::{
|
||||||
pub type StyleCascade = Cascade<Style>;
|
pub type StyleCascade = Cascade<Style>;
|
||||||
|
|
||||||
#[derive(Clone, Refineable, Debug)]
|
#[derive(Clone, Refineable, Debug)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
pub struct Style {
|
pub struct Style {
|
||||||
/// What layout strategy should be used?
|
/// What layout strategy should be used?
|
||||||
pub display: Display,
|
pub display: Display,
|
||||||
|
@ -129,7 +129,7 @@ pub struct BoxShadow {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Clone, Debug)]
|
#[derive(Refineable, Clone, Debug)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
pub struct TextStyle {
|
pub struct TextStyle {
|
||||||
pub color: Hsla,
|
pub color: Hsla,
|
||||||
pub font_family: SharedString,
|
pub font_family: SharedString,
|
||||||
|
@ -353,7 +353,7 @@ impl Default for Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Copy, Clone, Default, Debug, PartialEq, Eq)]
|
#[derive(Refineable, Copy, Clone, Default, Debug, PartialEq, Eq)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
pub struct UnderlineStyle {
|
pub struct UnderlineStyle {
|
||||||
pub thickness: Pixels,
|
pub thickness: Pixels,
|
||||||
pub color: Option<Hsla>,
|
pub color: Option<Hsla>,
|
||||||
|
|
|
@ -19,8 +19,7 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
|
||||||
let refineable_attr = attrs.iter().find(|attr| attr.path.is_ident("refineable"));
|
let refineable_attr = attrs.iter().find(|attr| attr.path.is_ident("refineable"));
|
||||||
|
|
||||||
let mut impl_debug_on_refinement = false;
|
let mut impl_debug_on_refinement = false;
|
||||||
let mut derive_serialize_on_refinement = false;
|
let mut refinement_traits_to_derive = vec![];
|
||||||
let mut derive_deserialize_on_refinement = false;
|
|
||||||
|
|
||||||
if let Some(refineable_attr) = refineable_attr {
|
if let Some(refineable_attr) = refineable_attr {
|
||||||
if let Ok(syn::Meta::List(meta_list)) = refineable_attr.parse_meta() {
|
if let Ok(syn::Meta::List(meta_list)) = refineable_attr.parse_meta() {
|
||||||
|
@ -29,16 +28,10 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if path.is_ident("debug") {
|
if path.is_ident("Debug") {
|
||||||
impl_debug_on_refinement = true;
|
impl_debug_on_refinement = true;
|
||||||
}
|
} else {
|
||||||
|
refinement_traits_to_derive.push(path);
|
||||||
if path.is_ident("serialize") {
|
|
||||||
derive_serialize_on_refinement = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if path.is_ident("deserialize") {
|
|
||||||
derive_deserialize_on_refinement = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,22 +252,14 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
|
||||||
quote! {}
|
quote! {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let derive_serialize = if derive_serialize_on_refinement {
|
let mut derive_stream = quote! {};
|
||||||
quote! { #[derive(serde::Serialize)]}
|
for trait_to_derive in refinement_traits_to_derive {
|
||||||
} else {
|
derive_stream.extend(quote! { #[derive(#trait_to_derive)] })
|
||||||
quote! {}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
let derive_deserialize = if derive_deserialize_on_refinement {
|
|
||||||
quote! { #[derive(serde::Deserialize)]}
|
|
||||||
} else {
|
|
||||||
quote! {}
|
|
||||||
};
|
|
||||||
|
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#derive_serialize
|
#derive_stream
|
||||||
#derive_deserialize
|
|
||||||
pub struct #refinement_ident #impl_generics {
|
pub struct #refinement_ident #impl_generics {
|
||||||
#( #field_visibilities #field_names: #wrapped_types ),*
|
#( #field_visibilities #field_names: #wrapped_types ),*
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct SystemColors {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Clone, Debug)]
|
#[derive(Refineable, Clone, Debug)]
|
||||||
#[refineable(debug)]
|
#[refineable(Debug)]
|
||||||
pub struct StatusColors {
|
pub struct StatusColors {
|
||||||
pub conflict: Hsla,
|
pub conflict: Hsla,
|
||||||
pub created: Hsla,
|
pub created: Hsla,
|
||||||
|
@ -30,7 +30,7 @@ pub struct StatusColors {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Clone, Debug)]
|
#[derive(Refineable, Clone, Debug)]
|
||||||
#[refineable(debug, deserialize)]
|
#[refineable(Debug, serde::Deserialize)]
|
||||||
pub struct ThemeColors {
|
pub struct ThemeColors {
|
||||||
pub border: Hsla,
|
pub border: Hsla,
|
||||||
/// Border color. Used for deemphasized borders, like a visual divider between two sections
|
/// Border color. Used for deemphasized borders, like a visual divider between two sections
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
use crate::{Appearance, ThemeColors, ThemeColorsRefinement};
|
||||||
use refineable::Refineable;
|
use refineable::Refineable;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{Appearance, ThemeColors, ThemeColorsRefinement};
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct UserThemeFamily {
|
pub struct UserThemeFamily {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -18,7 +17,7 @@ pub struct UserTheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Refineable, Clone)]
|
#[derive(Refineable, Clone)]
|
||||||
#[refineable(deserialize)]
|
#[refineable(Deserialize)]
|
||||||
pub struct UserThemeStyles {
|
pub struct UserThemeStyles {
|
||||||
#[refineable]
|
#[refineable]
|
||||||
pub colors: ThemeColors,
|
pub colors: ThemeColors,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue