Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloamed committed Sep 11, 2024
1 parent fcb33fe commit 62a4b1a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/web/vaev-base/flex.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ enum struct FlexWrap {
_LEN
};

struct FlexFlow {
FlexDirection direction;
FlexWrap wrap;

constexpr FlexFlow(FlexDirection direction, FlexWrap wrap)
: direction(direction), wrap(wrap) {
}

constexpr FlexFlow(FlexDirection direction)
: direction(direction) {
}

constexpr FlexFlow(FlexWrap wrap)
: wrap(wrap) {
}
};

struct FlexBasis {
enum struct Type {
CONTENT,
Expand Down
25 changes: 25 additions & 0 deletions src/web/vaev-style/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,30 @@ struct FlexWrapProp {
}
};

// https://www.w3.org/TR/css-flexbox-1/#propdef-flex-flow
struct FlexFlowProp {
FlexFlow value = initial();

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

static constexpr FlexFlow initial() {
return FlexFlow{
FlexDirection::ROW,
FlexWrap::NOWRAP,
};
}

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

Res<> parse(Cursor<Css::Sst> &c) {
value = try$(parseValue<FlexFlow>(c));
return Ok();
}
};

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

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

// Font
FontFamilyProp,
Expand Down
19 changes: 19 additions & 0 deletions src/web/vaev-style/values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,25 @@ Res<FlexWrap> ValueParser<FlexWrap>::parse(Cursor<Css::Sst> &c) {
return Error::invalidData("expected flex wrap");
}

// MARK: FlexFlow
// https://drafts.csswg.org/css-flexbox-1/#flex-flow-property
Res<FlexFlow> ValueParser<FlexFlow>::parse(Cursor<Css::Sst> &c) {
if (c.ended())
return Error::invalidData("unexpected end of input");

auto direction = parseValue<FlexDirection>(c);
auto wrap = parseValue<FlexWrap>(c);

if(direction && wrap)
return Ok(FlexFlow(direction.unwrap(), wrap.unwrap()));
else if(direction && !wrap)
return Ok(FlexFlow(direction.unwrap()));
else if(!direction && wrap)
return Ok(FlexFlow(wrap.unwrap()));
else
return Error::invalidData("expected flex direction or wrap");
}

// MARK: FlexBasis
// https://drafts.csswg.org/css-flexbox-1/#flex-basis-property
Res<FlexBasis> ValueParser<FlexBasis>::parse(Cursor<Css::Sst> &c) {
Expand Down
5 changes: 5 additions & 0 deletions src/web/vaev-style/values.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ struct ValueParser<FlexWrap> {
static Res<FlexWrap> parse(Cursor<Css::Sst> &c);
};

template <>
struct ValueParser<FlexFlow> {
static Res<FlexFlow> parse(Cursor<Css::Sst> &c);
};

template <>
struct ValueParser<FlexBasis> {
static Res<FlexBasis> parse(Cursor<Css::Sst> &c);
Expand Down

0 comments on commit 62a4b1a

Please sign in to comment.