Skip to content

Commit

Permalink
(ast/values) implement sizing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Nov 6, 2024
1 parent c789251 commit 4e20e1f
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 59 deletions.
26 changes: 26 additions & 0 deletions crates/hdx_ast/src/css/values/sizing/impls.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
pub(crate) use crate::traits::StyleValue;
pub(crate) use hdx_proc_macro::*;


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

#[test]
fn size_test() {
assert_size!(Width, 12);
assert_size!(Height, 12);
assert_size!(MinWidth, 12);
assert_size!(MinHeight, 12);
assert_size!(MaxWidth, 12);
assert_size!(MaxHeight, 12);
}

#[test]
fn test_writes() {
assert_parse!(Width, "0");
assert_parse!(Width, "1px");
assert_parse!(Width, "fit-content");
assert_parse!(Width, "fit-content(20rem)");
assert_parse!(Width, "fit-content(0)");
}
}
130 changes: 71 additions & 59 deletions crates/hdx_ast/src/css/values/sizing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,77 @@ use impls::*;
* CSS Box Sizing Module Level 4
*/

// // https://drafts.csswg.org/css-sizing-4/#width
// #[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> ")]
// #[initial("auto")]
// #[applies_to("all elements except non-replaced inlines")]
// #[inherited("no")]
// #[percentages("relative to width/height of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type, recursing into fit-content()")]
// pub enum Width {}

// // https://drafts.csswg.org/css-sizing-4/#height
// #[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> ")]
// #[initial("auto")]
// #[applies_to("all elements except non-replaced inlines")]
// #[inherited("no")]
// #[percentages("relative to width/height of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value type, recursing into fit-content()")]
// pub enum Height {}

// // https://drafts.csswg.org/css-sizing-4/#min-width
// #[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> ")]
// #[initial("auto")]
// #[applies_to("all elements that accept width or height")]
// #[inherited("no")]
// #[percentages("relative to width/height of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value, recursing into fit-content()")]
// pub enum MinWidth {}

// // https://drafts.csswg.org/css-sizing-4/#min-height
// #[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> ")]
// #[initial("auto")]
// #[applies_to("all elements that accept width or height")]
// #[inherited("no")]
// #[percentages("relative to width/height of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value, recursing into fit-content()")]
// pub enum MinHeight {}

// // https://drafts.csswg.org/css-sizing-4/#max-width
// #[value(" none | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> ")]
// #[initial("none")]
// #[applies_to("all elements that accept width or height")]
// #[inherited("no")]
// #[percentages("relative to width/height of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value, recursing into fit-content()")]
// pub enum MaxWidth {}

// // https://drafts.csswg.org/css-sizing-4/#max-height
// #[value(" none | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> ")]
// #[initial("none")]
// #[applies_to("all elements that accept width or height")]
// #[inherited("no")]
// #[percentages("relative to width/height of containing block")]
// #[canonical_order("per grammar")]
// #[animation_type("by computed value, recursing into fit-content()")]
// pub enum MaxHeight {}
// https://drafts.csswg.org/css-sizing-3/#width
// https://drafts.csswg.org/css-sizing-4/#sizing-values
// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords
#[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | stretch | fit-content | contain ")]
#[initial("auto")]
#[applies_to("all elements except non-replaced inlines")]
#[inherited("no")]
#[percentages("relative to width/height of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type, recursing into fit-content()")]
pub enum Width {}

// https://drafts.csswg.org/css-sizing-3/#height
// https://drafts.csswg.org/css-sizing-4/#sizing-values
// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords
#[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | stretch | fit-content | contain ")]
#[initial("auto")]
#[applies_to("all elements except non-replaced inlines")]
#[inherited("no")]
#[percentages("relative to width/height of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value type, recursing into fit-content()")]
pub enum Height {}

// https://drafts.csswg.org/css-sizing-3/#min-width
// https://drafts.csswg.org/css-sizing-4/#sizing-values
// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords
#[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | stretch | fit-content | contain ")]
#[initial("auto")]
#[applies_to("all elements that accept width or height")]
#[inherited("no")]
#[percentages("relative to width/height of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value, recursing into fit-content()")]
pub enum MinWidth {}

// https://drafts.csswg.org/css-sizing-3/#min-height
// https://drafts.csswg.org/css-sizing-4/#sizing-values
// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords
#[value(" auto | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | stretch | fit-content | contain ")]
#[initial("auto")]
#[applies_to("all elements that accept width or height")]
#[inherited("no")]
#[percentages("relative to width/height of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value, recursing into fit-content()")]
pub enum MinHeight {}

// https://drafts.csswg.org/css-sizing-3/#max-width
// https://drafts.csswg.org/css-sizing-4/#sizing-values
// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords
#[value(" none | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | stretch | fit-content | contain ")]
#[initial("none")]
#[applies_to("all elements that accept width or height")]
#[inherited("no")]
#[percentages("relative to width/height of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value, recursing into fit-content()")]
pub enum MaxWidth {}

// https://drafts.csswg.org/css-sizing-3/#max-height
// https://drafts.csswg.org/css-sizing-4/#sizing-values
// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords
#[value(" none | <length-percentage [0,∞]> | min-content | max-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | stretch | fit-content | contain ")]
#[initial("none")]
#[applies_to("all elements that accept width or height")]
#[inherited("no")]
#[percentages("relative to width/height of containing block")]
#[canonical_order("per grammar")]
#[animation_type("by computed value, recursing into fit-content()")]
pub enum MaxHeight {}

// https://drafts.csswg.org/css-sizing-4/#box-sizing
#[value(" content-box | border-box ")]
Expand Down
32 changes: 32 additions & 0 deletions crates/hdx_ast/src/css/values/sizing/types.rs
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
use hdx_parser::{Parse, Parser, Peek, Result as ParserResult, Token};
use hdx_writer::{CssWriter, Result as WriterResult, WriteCss};

pub use crate::css::units::*;

mod func {
use hdx_parser::custom_function;
custom_function!(CalcSize, atom!("calc-size"));
custom_function!(FitContent, atom!("fit-content"));
}

#[derive(Debug, PartialEq, Hash, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct CalcSize;

impl<'a> Peek<'a> for CalcSize {
fn peek(parser: &Parser<'a>) -> Option<hdx_lexer::Token> {
parser.peek::<func::CalcSize>()
}
}

impl<'a> Parse<'a> for CalcSize {
fn parse(parser: &mut Parser<'a>) -> ParserResult<Self> {
parser.parse::<func::CalcSize>()?;
todo!();
}
}

impl<'a> WriteCss<'a> for CalcSize {
fn write_css<W: CssWriter>(&self, _sink: &mut W) -> WriterResult {
todo!();
}
}
1 change: 1 addition & 0 deletions crates/hdx_proc_macro/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ impl GenerateParseImpl for Def {
return Err(::hdx_parser::diagnostics::UnexpectedFunction(atom, token.span()))?
}
#inner
parser.parse::<::hdx_parser::token::RightParen>()?;
}
}
Self::Multiplier(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl<'a> ::hdx_parser::Parse<'a> for Foo {
),
)?;
}
parser.parse::<::hdx_parser::token::RightParen>()?;
Ok(Self::FitContentFunction(val))
}
}
Expand Down

0 comments on commit 4e20e1f

Please sign in to comment.