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 14a1b3a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/web/vaev-style/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "base.h"
#include "computed.h"
#include "karm-base/tuple.h"
#include "karm-base/union.h"
#include "values.h"

// https://www.w3.org/TR/CSS22/propidx.html
Expand Down Expand Up @@ -824,6 +826,52 @@ 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 +1593,7 @@ using _StyleProp = Union<
FlexGrowProp,
FlexShrinkProp,
FlexWrapProp,
FlexFlowProp,

// Font
FontFamilyProp,
Expand Down

0 comments on commit 14a1b3a

Please sign in to comment.