From 70e3757e32e0345d86644495ea26530069fc996a Mon Sep 17 00:00:00 2001 From: Paulo Medeiros Date: Wed, 11 Sep 2024 12:04:36 +0200 Subject: [PATCH] style: add flex-flow shortcut property --- src/web/vaev-style/styles.h | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/web/vaev-style/styles.h b/src/web/vaev-style/styles.h index 9a977a9..5398038 100644 --- a/src/web/vaev-style/styles.h +++ b/src/web/vaev-style/styles.h @@ -824,6 +824,51 @@ struct FlexWrapProp { } }; +// https://www.w3.org/TR/css-flexbox-1/#propdef-flex-flow +// <'flex-direction'> || <'flex-wrap'> +struct FlexFlowProp { + Tuple value = initial(); + + static Tuple 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 &c) { + if (c.ended()) + return Error::invalidData("unexpected end of input"); + + auto direction = parseValue(c); + if (direction) { + value.v0 = direction.unwrap(); + + auto wrap = parseValue(c); + if (wrap) + value.v1 = wrap.unwrap(); + } else { + auto wrap = parseValue(c); + if (not wrap) + return Error::invalidData("expected flex direction or wrap"); + value.v1 = wrap.unwrap(); + + direction = parseValue(c); + if (direction) + value.v0 = direction.unwrap(); + } + + return Ok(); + } +}; + // MARK: Fonts ----------------------------------------------------------------- // https://www.w3.org/TR/css-fonts-4/#font-family-prop @@ -1545,6 +1590,7 @@ using _StyleProp = Union< FlexGrowProp, FlexShrinkProp, FlexWrapProp, + FlexFlowProp, // Font FontFamilyProp,