Skip to content

Commit bdcfe14

Browse files
committed
feat(css): impl parse gap
1 parent d9c03a4 commit bdcfe14

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

float-pigment-css/src/property.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ property_list! (PropertyValueWithGlobal, {
5555
0x28 FlexBasis: LengthType as Initial default Length::Undefined, resolver = Length::resolve_em;
5656
0x29 JustifyItems: JustifyItemsType as Initial default JustifyItems::Stretch;
5757
0x2a Order: NumberType as Initial default Number::I32(0);
58+
0x2b RowGap: GapType as Initial default Gap::Normal;
59+
0x2c ColumnGap: GapType as Initial default Gap::Normal;
5860

5961
// background
6062
0x30 BackgroundColor: ColorType as Initial default Color::Undefined;
@@ -330,6 +332,20 @@ property_value_format! (PropertyValueWithGlobal, {
330332
| "right" => JustifyItems::Right
331333
}};
332334
order: {{ Order = <number> -> |x: Number| Number::I32(x.to_i32()); }};
335+
<gap_repr: Gap>:
336+
"normal" => Gap::Normal
337+
| <non_negative_length> -> |length| Gap::Length(length);
338+
;
339+
column_gap: {{ ColumnGap = <gap_repr> }};
340+
row_gap: {{ RowGap = <gap_repr> }};
341+
gap: {{ (RowGap, ColumnGap)
342+
= [ <gap_repr> <gap_repr>? ] -> |(row_gap, column_gap): (Gap, Option<Gap>)| {
343+
if let Some(column_gap) = column_gap {
344+
return (row_gap, column_gap);
345+
}
346+
return (row_gap.clone(), row_gap);
347+
};
348+
}};
333349
flex_grow: {{ FlexGrow = <number> }};
334350
flex_shrink: {{ FlexShrink = <number> }};
335351
flex_basis: {{ FlexBasis = <length> }};

float-pigment-css/src/typing.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,3 +1785,14 @@ pub struct FeatureTag {
17851785
/// The optional number value in `font-feature-settings`.
17861786
pub value: Number,
17871787
}
1788+
1789+
#[allow(missing_docs)]
1790+
#[repr(C)]
1791+
#[property_value_type(PropertyValueWithGlobal for GapType)]
1792+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ResolveFontSize)]
1793+
#[cfg_attr(debug_assertions, derive(CompatibilityEnumCheck))]
1794+
pub enum Gap {
1795+
Normal,
1796+
#[resolve_font_size(Length::resolve_em_and_ratio)]
1797+
Length(Length),
1798+
}

float-pigment-css/src/typing_stringify.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,3 +2327,12 @@ impl fmt::Display for FontFeatureSettings {
23272327
write!(f, "{}", ret.join(","))
23282328
}
23292329
}
2330+
2331+
impl fmt::Display for Gap {
2332+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2333+
match self {
2334+
Gap::Normal => write!(f, "normal"),
2335+
Gap::Length(length) => write!(f, "{}", length),
2336+
}
2337+
}
2338+
}

float-pigment-css/tests/property.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,42 @@ mod flex {
20582058
test_parse_property!(order, "order", "1", Number::I32(1));
20592059
test_parse_property!(order, "order", "-100", Number::I32(-100));
20602060
}
2061+
// 0x2b
2062+
#[test]
2063+
fn row_gap() {
2064+
test_parse_property!(row_gap, "row-gap", "normal", Gap::Normal);
2065+
test_parse_property!(row_gap, "row-gap", "10px", Gap::Length(Length::Px(10.)));
2066+
}
2067+
2068+
// 0x2c
2069+
#[test]
2070+
fn column_gap() {
2071+
test_parse_property!(column_gap, "column-gap", "normal", Gap::Normal);
2072+
test_parse_property!(column_gap, "column-gap", "-10%", Gap::Normal);
2073+
}
2074+
2075+
#[test]
2076+
fn gap() {
2077+
test_parse_property!(row_gap, "gap", "normal", Gap::Normal);
2078+
test_parse_property!(column_gap, "gap", "normal", Gap::Normal);
2079+
2080+
test_parse_property!(row_gap, "gap", "30px", Gap::Length(Length::Px(30.)));
2081+
test_parse_property!(column_gap, "gap", "20px", Gap::Length(Length::Px(20.)));
2082+
2083+
test_parse_property!(row_gap, "gap", "normal 10px", Gap::Normal);
2084+
test_parse_property!(row_gap, "gap", "10px normal", Gap::Length(Length::Px(10.)));
2085+
test_parse_property!(
2086+
column_gap,
2087+
"gap",
2088+
"normal 10px",
2089+
Gap::Length(Length::Px(10.))
2090+
);
2091+
test_parse_property!(column_gap, "gap", "10px normal", Gap::Normal);
2092+
2093+
test_parse_property!(row_gap, "gap", "30px 40px", Gap::Length(Length::Px(30.)));
2094+
test_parse_property!(column_gap, "gap", "30px 40px", Gap::Length(Length::Px(40.)));
2095+
}
2096+
20612097
#[test]
20622098
fn flex_flow() {
20632099
let mut ssg = StyleSheetGroup::new();

0 commit comments

Comments
 (0)