Skip to content

Commit

Permalink
style: add flex-flow shortcut property
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloamed committed Sep 12, 2024
1 parent 891e933 commit 70e3757
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/web/vaev-style/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,51 @@ struct FlexWrapProp {
}
};

// https://www.w3.org/TR/css-flexbox-1/#propdef-flex-flow
// <'flex-direction'> || <'flex-wrap'>
struct FlexFlowProp {
Tuple<FlexDirection, FlexWrap> value = initial();

static Tuple<FlexDirection, FlexWrap> initial() {
return {
FlexDirection::ROW,
FlexWrap::NOWRAP,
};
}

static constexpr Str name() { return "flex-flow"; }

void apply(Computed &c) const {
c.flex.cow().direction = value.v0;
c.flex.cow().wrap = value.v1;
}

Res<> parse(Cursor<Css::Sst> &c) {
if (c.ended())
return Error::invalidData("unexpected end of input");

auto direction = parseValue<FlexDirection>(c);
if (direction) {
value.v0 = direction.unwrap();

auto wrap = parseValue<FlexWrap>(c);
if (wrap)
value.v1 = wrap.unwrap();
} else {
auto wrap = parseValue<FlexWrap>(c);
if (not wrap)
return Error::invalidData("expected flex direction or wrap");
value.v1 = wrap.unwrap();

direction = parseValue<FlexDirection>(c);
if (direction)
value.v0 = direction.unwrap();
}

return Ok();
}
};

// MARK: Fonts -----------------------------------------------------------------

// https://www.w3.org/TR/css-fonts-4/#font-family-prop
Expand Down Expand Up @@ -1545,6 +1590,7 @@ using _StyleProp = Union<
FlexGrowProp,
FlexShrinkProp,
FlexWrapProp,
FlexFlowProp,

// Font
FontFamilyProp,
Expand Down

0 comments on commit 70e3757

Please sign in to comment.