Skip to content

Commit

Permalink
(ast/values) implement padding/margin
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Nov 7, 2024
1 parent 3e1a7bf commit c2e667a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 58 deletions.
29 changes: 29 additions & 0 deletions crates/hdx_ast/src/css/values/box/impls.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
pub(crate) use crate::traits::StyleValue;
pub(crate) use hdx_proc_macro::*;

#[cfg(test)]
mod tests {
use super::super::*;
use crate::test_helpers::*;

#[test]
pub fn size_test() {
assert_size!(MarginTop, 8);
assert_size!(MarginRight, 8);
assert_size!(MarginBottom, 8);
assert_size!(MarginLeft, 8);
assert_size!(Margin, 32);
assert_size!(PaddingTop, 8);
assert_size!(PaddingRight, 8);
assert_size!(PaddingBottom, 8);
assert_size!(PaddingLeft, 8);
assert_size!(Padding, 32);
// assert_size!(MarginTrim, 1);
}

#[test]
fn test_writes() {
assert_parse!(MarginLeft, "auto");
assert_parse!(Margin, "1px 1px");
assert_parse!(Margin, "1px 2px");
assert_parse!(Margin, "1px 2px 3px 4px");
}
}
108 changes: 54 additions & 54 deletions crates/hdx_ast/src/css/values/box/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,55 @@ use impls::*;
* CSS Box Model Module Level 4
*/

// // https://drafts.csswg.org/css-box-4/#margin-top
// #[value(" <length-percentage> | auto ")]
// #[initial("0")]
// #[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
// #[inherited("no")]
// #[percentages("refer to logical width of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type")]
// pub enum MarginTop {}
// https://drafts.csswg.org/css-box-4/#margin-top
#[value(" <length-percentage> | auto ")]
#[initial("0")]
#[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
#[inherited("no")]
#[percentages("refer to logical width of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type")]
pub enum MarginTop {}

// // https://drafts.csswg.org/css-box-4/#margin-right
// #[value(" <length-percentage> | auto ")]
// #[initial("0")]
// #[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
// #[inherited("no")]
// #[percentages("refer to logical width of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type")]
// pub enum MarginRight {}
// https://drafts.csswg.org/css-box-4/#margin-right
#[value(" <length-percentage> | auto ")]
#[initial("0")]
#[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
#[inherited("no")]
#[percentages("refer to logical width of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type")]
pub enum MarginRight {}

// // https://drafts.csswg.org/css-box-4/#margin-bottom
// #[value(" <length-percentage> | auto ")]
// #[initial("0")]
// #[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
// #[inherited("no")]
// #[percentages("refer to logical width of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type")]
// pub enum MarginBottom {}
// https://drafts.csswg.org/css-box-4/#margin-bottom
#[value(" <length-percentage> | auto ")]
#[initial("0")]
#[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
#[inherited("no")]
#[percentages("refer to logical width of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type")]
pub enum MarginBottom {}

// // https://drafts.csswg.org/css-box-4/#margin-left
// #[value(" <length-percentage> | auto ")]
// #[initial("0")]
// #[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
// #[inherited("no")]
// #[percentages("refer to logical width of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type")]
// pub enum MarginLeft {}
// https://drafts.csswg.org/css-box-4/#margin-left
#[value(" <length-percentage> | auto ")]
#[initial("0")]
#[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
#[inherited("no")]
#[percentages("refer to logical width of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type")]
pub enum MarginLeft {}

// // https://drafts.csswg.org/css-box-4/#margin
// #[value(" <'margin-top'>{1,4} ")]
// #[initial("0")]
// #[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
// #[inherited("no")]
// #[percentages("refer to logical width of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type")]
// pub struct Margin;
// https://drafts.csswg.org/css-box-4/#margin
#[value(" <'margin-top'>{1,4} ")]
#[initial("0")]
#[applies_to("all elements except internal table elements, ruby base containers, and ruby annotation containers")]
#[inherited("no")]
#[percentages("refer to logical width of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type")]
pub struct Margin;

// https://drafts.csswg.org/css-box-4/#padding-top
#[value(" <length-percentage [0,∞]> ")]
Expand Down Expand Up @@ -98,15 +98,15 @@ pub struct PaddingBottom;
#[animation_type("by computed value type")]
pub struct PaddingLeft;

// // https://drafts.csswg.org/css-box-4/#padding
// #[value(" <'padding-top'>{1,4} ")]
// #[initial("0")]
// #[applies_to("all elements except: internal table elements other than table cells, ruby base containers, and ruby annotation containers")]
// #[inherited("no")]
// #[percentages("refer to logical width of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type")]
// pub struct Padding;
// https://drafts.csswg.org/css-box-4/#padding
#[value(" <'padding-top'>{1,4} ")]
#[initial("0")]
#[applies_to("all elements except: internal table elements other than table cells, ruby base containers, and ruby annotation containers")]
#[inherited("no")]
#[percentages("refer to logical width of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type")]
pub struct Padding;

// // https://drafts.csswg.org/css-box-4/#margin-trim
// #[value(" none | [ block || inline ] | [ block-start || inline-start || block-end || inline-end ] ")]
Expand Down
3 changes: 3 additions & 0 deletions crates/hdx_ast/src/css/values/box/types.rs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pub(crate) use crate::css::units::*;

// Re-expose stylevalues for shorthands
pub(crate) use super::{PaddingTop, MarginTop};
8 changes: 4 additions & 4 deletions crates/hdx_proc_macro/src/initial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ pub fn generate(args: Args, ast: DeriveInput) -> TokenStream {
Args::Dimension(f) => {
let first_deep = variants.iter().find(|v| v.fields != Fields::Unit).expect("Cannot find variant");
let num = f.base10_digits();
let variant_ident = quote! { first_deep.ident.clone() };
let variant_ident = first_deep.ident.clone();
let mut vec = false;
let ty = if let Fields::Unnamed(FieldsUnnamed { unnamed, .. }) = &first_deep.fields {
if let Type::Path(type_path) = &unnamed.first().unwrap().ty {
vec = type_path.path.segments.first().map(|s| s.ident == "smallvec").unwrap_or(false);
quote! { type_path }
quote! { #type_path }
} else {
quote! { variant_ident }
quote! { #variant_ident }
}
} else {
quote! { variant_ident }
quote! { #variant_ident }
};
let val = if let Ok(0) = f.base10_parse() {
quote! { #ty::Zero }
Expand Down

0 comments on commit c2e667a

Please sign in to comment.