diff --git a/src/vaev-engine/layout/flex.cpp b/src/vaev-engine/layout/flex.cpp index dda0afa8..1ea38e83 100644 --- a/src/vaev-engine/layout/flex.cpp +++ b/src/vaev-engine/layout/flex.cpp @@ -240,21 +240,21 @@ struct FlexItem { // https://www.w3.org/TR/css-flexbox-1/#valdef-flex-basis-auto void computeFlexBaseSize(Tree& tree, Opt mainContainerSize, IntrinsicSize containerSizing) { // A NONE return here indicates a CONTENT case for the flex basis - auto getDefiniteFlexBasisSize = [](FlexProps& flexItemProps, FlexAxis& fa, Box* box) -> Opt>> { + auto getDefiniteFlexBasisSize = [](FlexProps& flexItemProps, FlexAxis& fa, Box* box) -> Opt> { if (flexItemProps.basis.is()) return NONE; // from now on flex basis is width - if (auto basisCalc = flexItemProps.basis.is>>()) + if (auto basisCalc = flexItemProps.basis.is>()) return *basisCalc; - if (not fa.mainAxis(box->style->sizing).is>>()) + if (not fa.mainAxis(box->style->sizing).is>()) return NONE; // TODO: solve definite values also min and max content - return fa.mainAxis(box->style->sizing).unwrap>>(); + return fa.mainAxis(box->style->sizing).unwrap>(); }; if (auto flexBasisDefiniteSize = getDefiniteFlexBasisSize(flexItemProps, fa, box)) { @@ -300,7 +300,7 @@ struct FlexItem { Au getMinAutoPrefMainSize(Tree& tree, Vec2Au containerSize) const { Opt definiteMaxMainSize; auto maxMainSize = box->style->sizing->maxSize(fa.isRowOriented ? Axis::HORIZONTAL : Axis::VERTICAL); - if (auto maxMainSizeCalc = maxMainSize.is>>()) { + if (auto maxMainSizeCalc = maxMainSize.is>()) { definiteMaxMainSize = resolve( tree, *box, @@ -315,7 +315,7 @@ struct FlexItem { contentSizeSuggestion = min(contentSizeSuggestion, definiteMaxMainSize.unwrap()); auto mainAxis = fa.mainAxis(box->style->sizing); - if (auto mainAxisCalc = mainAxis.is>>()) { + if (auto mainAxisCalc = mainAxis.is>()) { Au specifiedSizeSuggestion = resolve( tree, *box, @@ -338,7 +338,7 @@ struct FlexItem { MaxSize maxSizeToResolve = isWidth ? box->style->sizing->maxWidth : box->style->sizing->maxHeight; auto visitor = Visitor{ - [&](CalcValue> const& v) { + [&](Calc const& v) { return resolve( tree, *box, @@ -380,7 +380,7 @@ struct FlexItem { Au contentContribution = fa.mainAxis(isMin ? minContentSize : maxContentSize) + getMargin(BOTH_MAIN); auto mainAxis = fa.mainAxis(box->style->sizing); - if (auto mainAxisCalc = mainAxis.is>>()) { + if (auto mainAxisCalc = mainAxis.is>()) { contentContribution = max( contentContribution, resolve( @@ -425,7 +425,7 @@ struct FlexItem { ); auto crossAxis = fa.crossAxis(box->style->sizing); - if (auto crossAxisCalc = crossAxis.is>>()) { + if (auto crossAxisCalc = crossAxis.is>()) { contentContribution = max( contentContribution, resolve( @@ -702,11 +702,11 @@ struct FlexFormatingContext : FormatingContext { void _determineFlexBaseSizeAndHypotheticalMainSize(Tree& tree, Box& box, Input input) { Opt containerDefiniteMainSize = fa.mainAxis(input.knownSize); - if (fa.mainAxis(box.style->sizing).is>>()) { + if (fa.mainAxis(box.style->sizing).is>()) { containerDefiniteMainSize = resolve( tree, box, - fa.mainAxis(box.style->sizing).unwrap>>(), + fa.mainAxis(box.style->sizing).unwrap>(), fa.mainAxis(input.containingBlock) ); } diff --git a/src/vaev-engine/layout/layout-impl.cpp b/src/vaev-engine/layout/layout-impl.cpp index 130516cf..2e965bf5 100644 --- a/src/vaev-engine/layout/layout-impl.cpp +++ b/src/vaev-engine/layout/layout-impl.cpp @@ -174,7 +174,7 @@ Opt computeSpecifiedSize(Tree& tree, Box& box, Size size, Vec2Au containingB return clamp(stretchIntrinsicSize.y, minIntrinsicSize.y, maxIntrinsicSize.y); } else if (size.is()) { return NONE; - } else if (auto calc = size.is>>()) { + } else if (auto calc = size.is>()) { return resolve(tree, box, *calc, isWidth ? containingBlock.x : containingBlock.y); } else { logWarn("unknown specified size: {}", size); diff --git a/src/vaev-engine/layout/paint.cpp b/src/vaev-engine/layout/paint.cpp index 916b99f2..f0d5908e 100644 --- a/src/vaev-engine/layout/paint.cpp +++ b/src/vaev-engine/layout/paint.cpp @@ -240,7 +240,7 @@ static void _paintChildren(Frag& frag, Scene::Stack& stack, auto predicate) { } } -static Math::Radiif _resolveRadii(Resolver& resolver, Math::Radii>> const& baseRadii, RectAu const& referenceBox) { +static Math::Radiif _resolveRadii(Resolver& resolver, Math::Radii> const& baseRadii, RectAu const& referenceBox) { Math::Radiif radii; radii.a = resolver.resolve(baseRadii.a, referenceBox.height).cast(); radii.b = resolver.resolve(baseRadii.b, referenceBox.width).cast(); @@ -356,7 +356,7 @@ static Rc _applyClip(Frag const& frag, Rc content) { auto hSquared = Math::pow2(referenceBox.height.cast()); auto wSquared = Math::pow2(referenceBox.width.cast()); radius = resolver.resolve( - circle.radius.unwrap>>(), + circle.radius.unwrap>(), Au(Math::sqrt(hSquared + wSquared) / Math::sqrt(2.0)) ) .cast(); @@ -420,7 +420,7 @@ static Rc _applyClip(Frag const& frag, Rc content) { rx = max(Math::abs(referenceBox.width.cast() - center.x), center.x); } else { rx = resolver.resolve( - ellipse.rx.unwrap>>(), + ellipse.rx.unwrap>(), referenceBox.width ) .cast(); @@ -433,7 +433,7 @@ static Rc _applyClip(Frag const& frag, Rc content) { ry = max(Math::abs(referenceBox.height.cast() - center.y), center.y); } else { ry = resolver.resolve( - ellipse.ry.unwrap>>(), + ellipse.ry.unwrap>(), referenceBox.height ) .cast(); @@ -516,7 +516,7 @@ static Vec2Au _resolveTransformOrigin(RectAu referenceBox, TransformOrigin origi [&](Keywords::Center) { return referenceBox.center().x; }, - [&](CalcValue> value) { + [&](Calc value) { return referenceBox.start() + resolver.resolve(value, referenceBox.width); } } @@ -533,7 +533,7 @@ static Vec2Au _resolveTransformOrigin(RectAu referenceBox, TransformOrigin origi [&](Keywords::Center) { return referenceBox.center().y; }, - [&](CalcValue> value) { + [&](Calc value) { return referenceBox.top() + resolver.resolve(value, referenceBox.height); } } diff --git a/src/vaev-engine/layout/positioned.cpp b/src/vaev-engine/layout/positioned.cpp index 66870311..af811643 100644 --- a/src/vaev-engine/layout/positioned.cpp +++ b/src/vaev-engine/layout/positioned.cpp @@ -32,17 +32,17 @@ export void layoutPositioned(Tree& tree, Frag& frag, RectAu containingBlock) { auto start = metrics.position.x; auto topOffset = style.offsets->top; - if (auto topOffsetCalc = topOffset.is>>()) { + if (auto topOffsetCalc = topOffset.is>()) { top = origin.y + resolve(tree, *frag.box, *topOffsetCalc, relativeTo.height); } auto startOffset = style.offsets->start; - if (auto startOffsetCalc = startOffset.is>>()) { + if (auto startOffsetCalc = startOffset.is>()) { start = origin.x + resolve(tree, *frag.box, *startOffsetCalc, relativeTo.width); } auto endOffset = frag.style().offsets->end; - if (auto endOffsetCalc = endOffset.is>>()) { + if (auto endOffsetCalc = endOffset.is>()) { start = (origin.x + relativeTo.width) - resolve(tree, *frag.box, *endOffsetCalc, relativeTo.width) - metrics.borderSize.width; } diff --git a/src/vaev-engine/layout/svg.cpp b/src/vaev-engine/layout/svg.cpp index da117015..ce91f785 100644 --- a/src/vaev-engine/layout/svg.cpp +++ b/src/vaev-engine/layout/svg.cpp @@ -14,10 +14,10 @@ using namespace Karm; namespace Vaev::Layout { // SVG sizes shouldn't be defined using calc values -Opt> extractValueFromCalc(CalcValue> const& size) { +Opt> extractValueFromCalc(Calc const& size) { return size.visit( Visitor{ - [](CalcValue>::Value const& v) { + [](Calc::Value const& v) { return Opt>{v.unwrap>()}; }, [](auto const) { @@ -32,7 +32,7 @@ PercentOr fromSize(Size const& size) { if (size.is()) return PercentOr{Percent{100}}; - return extractValueFromCalc(size.unwrap>>()) + return extractValueFromCalc(size.unwrap>()) .unwrapOr(PercentOr{Percent{100}}); } @@ -158,7 +158,7 @@ Rc circleToSceneNode(Circle circle, Opt fill, Opt(path, stroke, fill); } -Circle> buildCircle(Style::SpecifiedValues const& style) { +Circle> buildCircle(Style::SpecifiedValues const& style) { return { style.svg->cx, style.svg->cy, @@ -166,7 +166,7 @@ Circle> buildCircle(Style::SpecifiedValues const& style) { }; } -Circle resolve(Circle> const& circle, Karm::Vec2Au const& relativeTo) { +Circle resolve(Circle> const& circle, Karm::Vec2Au const& relativeTo) { return { Vaev::Layout::resolve(circle.cx, relativeTo.x), Vaev::Layout::resolve(circle.cy, relativeTo.y), @@ -385,10 +385,10 @@ Opt intrinsicAspectRatio(Opt const& vb, Size const& width, Size // FIXME: again this should be targetted by the styling computation refactoring, // where Size will be resolved to a mix between Percent and Lengths auto absoluteValue = [](Size size) -> Opt { - if (not size.is>>()) + if (not size.is>()) return NONE; - auto calc = size.unwrap>>(); + auto calc = size.unwrap>(); auto percOrLength = extractValueFromCalc(calc); if (not percOrLength) diff --git a/src/vaev-engine/layout/table.cpp b/src/vaev-engine/layout/table.cpp index 33f65e2d..166fc5f1 100644 --- a/src/vaev-engine/layout/table.cpp +++ b/src/vaev-engine/layout/table.cpp @@ -446,13 +446,13 @@ struct TableFormatingContext : FormatingContext { // NOTE: The table does not automatically expand to fill its containing block. // (https://www.w3.org/TR/CSS22/tables.html#width-layout) - if (not(box.style->sizing->width.is() or box.style->sizing->width.is>>())) + if (not(box.style->sizing->width.is() or box.style->sizing->width.is>())) logWarn("width can't be anything other than 'auto' or a length in a table context"); tableUsedWidth = - not box.style->sizing->width.is>>() + not box.style->sizing->width.is>() ? 0_au // AUTO case - : resolve(tree, box, box.style->sizing->width.unwrap>>(), availableXSpace) - + : resolve(tree, box, box.style->sizing->width.unwrap>(), availableXSpace) - boxBorder.horizontal(); // NOTE: maybe remove this after borderbox param is clearer auto [columnBorders, sumBorders] = getColumnBorders(); @@ -465,10 +465,10 @@ struct TableFormatingContext : FormatingContext { auto const& width = col.el.style->sizing->width; - if (not(width.is() or width.is>>())) + if (not(width.is() or width.is>())) logWarn("width can't be anything other than 'auto' or a length in a table context"); - if (auto widthCalc = width.is>>()) { + if (auto widthCalc = width.is>()) { for (usize x = col.start; x <= col.end; ++x) { colWidthOrNone[x] = resolve(tree, col.el, *widthCalc, tableUsedWidth); } @@ -482,7 +482,7 @@ struct TableFormatingContext : FormatingContext { while (x < grid.size.x) { auto cell = grid.get(x, 0); - auto cellBoxWidthCalc = cell.box->style->sizing->width.is>>(); + auto cellBoxWidthCalc = cell.box->style->sizing->width.is>(); if (not(cell.box->style->sizing->width.is() or cellBoxWidthCalc)) logWarn("width can't be anything other than 'auto' or a length in a table context"); @@ -557,10 +557,10 @@ struct TableFormatingContext : FormatingContext { auto cellMinWidth = cellMinOutput.x; auto cellMaxWidth = cellMaxOutput.x; - if (not(cell.box->style->sizing->width.is() or cell.box->style->sizing->width.is>>())) + if (not(cell.box->style->sizing->width.is() or cell.box->style->sizing->width.is>())) logWarn("width can't be anything other than 'auto' or a length in a table context"); - if (auto cellBoxWidthCalc = cell.box->style->sizing->width.is>>()) { + if (auto cellBoxWidthCalc = cell.box->style->sizing->width.is>()) { auto cellPreferredWidth = resolve( tree, box, @@ -640,7 +640,7 @@ struct TableFormatingContext : FormatingContext { for (auto& group : colGroups) { auto columnGroupWidth = group.el.style->sizing->width; - auto columnGroupWidthCalc = columnGroupWidth.is>>(); + auto columnGroupWidthCalc = columnGroupWidth.is>(); if (not(columnGroupWidth.is() or columnGroupWidthCalc)) logWarn("width can't be anything other than 'auto' or a length in a table context"); @@ -668,7 +668,7 @@ struct TableFormatingContext : FormatingContext { void computeAutoWidthOfCols(Tree& tree, Vec& minColWidth, Vec& maxColWidth, Au tableWidth) { for (auto& [start, end, el] : cols) { auto width = el.style->sizing->width; - auto widthCalc = width.is>>(); + auto widthCalc = width.is>(); if (not(width.is() or widthCalc)) logWarn("width can't be anything other than 'auto' or a length in a table context"); @@ -713,7 +713,7 @@ struct TableFormatingContext : FormatingContext { // https://www.w3.org/TR/css-tables-3/#intrinsic-percentage-width-of-a-column-based-on-cells-of-span-up-to-1 // We will need a way to retrieve the percentage value, which is also not yet implemented. - if (auto boxWidthCalc = box.style->sizing->width.is>>()) { + if (auto boxWidthCalc = box.style->sizing->width.is>()) { auto [minWithoutPerc, maxWithoutPerc] = computeMinMaxAutoWidths(tree, grid.size.x, 0_au); Au tableComputedWidth = resolve(tree, box, *boxWidthCalc, containingBlockX); @@ -791,7 +791,7 @@ struct TableFormatingContext : FormatingContext { for (auto& row : rows) { auto& height = row.el.style->sizing->height; - auto heightCalc = height.is>>(); + auto heightCalc = height.is>(); if (not(height.is() or heightCalc)) logWarn("height can't be anything other than 'auto' or a length in a table context"); @@ -815,11 +815,11 @@ struct TableFormatingContext : FormatingContext { // [A] CSS 2.2 does not specify how cells that span more than one row affect row height calculations except // that the sum of the row heights involved must be great enough to encompass the cell spanning the rows. - if (not(cell.box->style->sizing->height.is() or cell.box->style->sizing->height.is>>())) + if (not(cell.box->style->sizing->height.is() or cell.box->style->sizing->height.is>())) logWarn("height can't be anything other than 'auto' or a length in a table context"); auto rowSpan = cell.box->attrs.rowSpan; - if (auto cellBoxHeightCalc = cell.box->style->sizing->height.is>>()) { + if (auto cellBoxHeightCalc = cell.box->style->sizing->height.is>()) { auto computedHeight = resolve( tree, *cell.box, diff --git a/src/vaev-engine/layout/values.cpp b/src/vaev-engine/layout/values.cpp index c569ad9e..752c52cb 100644 --- a/src/vaev-engine/layout/values.cpp +++ b/src/vaev-engine/layout/values.cpp @@ -262,7 +262,7 @@ export struct Resolver { Au resolve(Width const& value, Au relative) { if (value.is()) return 0_au; - return resolve(value.unwrap>>(), relative); + return resolve(value.unwrap>(), relative); } Rad resolve(Angle const& value) { @@ -328,12 +328,12 @@ export struct Resolver { } template - Resolved resolve(CalcValue const& calc, Args... args) { + Resolved resolve(Calc const& calc, Args... args) { auto resolveUnion = Visitor{ [&](T const& v) { return resolve(v, args...); }, - [&](CalcValue::Leaf const& v) { + [&](Calc::Leaf const& v) { return resolve(*v, args...); }, [&](Number const& v) @@ -344,16 +344,16 @@ export struct Resolver { }; return calc.visit(Visitor{ - [&](typename CalcValue::Value const& v) { + [&](typename Calc::Value const& v) { return v.visit(resolveUnion); }, - [&](typename CalcValue::Unary const& u) { + [&](typename Calc::Unary const& u) { return _resolveUnary( u.op, u.val.visit(resolveUnion) ); }, - [&](typename CalcValue::Binary const& b) { + [&](typename Calc::Binary const& b) { return _resolveInfix( b.op, b.lhs.visit(resolveUnion), @@ -367,11 +367,11 @@ export struct Resolver { // MARK: Resolve during layout ------------------------------------------------- // HACK: Temporary workaround while we don't properly evaluate computed values -export bool isPurePercentage(CalcValue> calcValue) { - if (not calcValue._inner.is>::Value>()) +export bool isPurePercentage(Calc calcValue) { + if (not calcValue._inner.is::Value>()) return false; - auto const& value = calcValue._inner.unwrap>::Value>(); + auto const& value = calcValue._inner.unwrap::Value>(); if (not value.is>()) return false; @@ -399,7 +399,7 @@ export Au resolve(Tree const& tree, Box const& box, FontSize const& value) { } export template -auto resolve(Tree const& tree, Box const& box, CalcValue const& value, Args... args) -> Resolved { +auto resolve(Tree const& tree, Box const& box, Calc const& value, Args... args) -> Resolved { return Resolver::from(tree, box).resolve(value, args...); } diff --git a/src/vaev-engine/loader/loader-impl.cpp b/src/vaev-engine/loader/loader-impl.cpp index 3e7a7d58..29053e04 100644 --- a/src/vaev-engine/loader/loader-impl.cpp +++ b/src/vaev-engine/loader/loader-impl.cpp @@ -41,8 +41,8 @@ Async::Task> _fetchImageContentAsync(Http::Client& client, Ref:: // NOSPEC: The spec references a “default object size” but does not define explicit values. // Historically, browsers (including Chrome) default to 300x150, as mentioned in older drafts: // https://www.w3.org/TR/2011/WD-css3-images-20110908/#default-object-size - auto width = resolver.resolve(root->specifiedValues()->sizing->width.unwrapOr>>(Length{300_au}), 300_au); - auto height = resolver.resolve(root->specifiedValues()->sizing->height.unwrapOr>>(Length{300_au}), 300_au); + auto width = resolver.resolve(root->specifiedValues()->sizing->width.unwrapOr>(Length{300_au}), 300_au); + auto height = resolver.resolve(root->specifiedValues()->sizing->height.unwrapOr>(Length{300_au}), 300_au); window->changeMedia(Style::Media::forRender({width, height}, Resolution::fromDppx(1))); co_return Ok(window->render()); diff --git a/src/vaev-engine/style/computer.cpp b/src/vaev-engine/style/computer.cpp index f4b17b78..a66696e8 100644 --- a/src/vaev-engine/style/computer.cpp +++ b/src/vaev-engine/style/computer.cpp @@ -155,7 +155,7 @@ export struct Computer { if (auto size = el->getAttribute(Html::SIZE_ATTR)) { auto value = parseValue(size.unwrap()); if (value) - res.pushBack(WidthProp{CalcValue>{Length{static_cast(value.take()), Length::CH}}}); + res.pushBack(WidthProp{Calc{Length{static_cast(value.take()), Length::CH}}}); } return res; @@ -174,10 +174,10 @@ export struct Computer { // height to '150px' (using CSS 2.1 replaced elements size calculation). if (not svgEl->hasAttribute(Svg::VIEW_BOX_ATTR)) { if (not svgEl->hasAttribute(Svg::WIDTH_ATTR)) { - styleProps.pushBack(WidthProp{CalcValue>{PercentOr{Length{Au{300}}}}}); + styleProps.pushBack(WidthProp{Calc{Length{Au{300}}}}); } if (not svgEl->hasAttribute(Svg::HEIGHT_ATTR)) { - styleProps.pushBack(HeightProp{CalcValue>{PercentOr{Length{Au{150}}}}}); + styleProps.pushBack(HeightProp{Calc{Length{Au{150}}}}); } } } diff --git a/src/vaev-engine/style/decls.cpp b/src/vaev-engine/style/decls.cpp index cc89c40e..212c3392 100644 --- a/src/vaev-engine/style/decls.cpp +++ b/src/vaev-engine/style/decls.cpp @@ -276,8 +276,8 @@ export void parseSVGPresentationAttribute(Symbol presentationAttr, Str style, Ve if constexpr (Meta::Constructible) { propAsNumber.value = Length{Au{maybeNumber.take()}}; - } else if constexpr (Meta::Constructible>>) { - propAsNumber.value = CalcValue>{Length{Au{maybeNumber.take()}}}; + } else if constexpr (Meta::Constructible>) { + propAsNumber.value = Calc{Length{Au{maybeNumber.take()}}}; } else { return true; } diff --git a/src/vaev-engine/style/props.cpp b/src/vaev-engine/style/props.cpp index 678bc6b3..dbc0e9f4 100644 --- a/src/vaev-engine/style/props.cpp +++ b/src/vaev-engine/style/props.cpp @@ -812,7 +812,7 @@ export struct BorderBottomWidthProp { } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; @@ -841,12 +841,12 @@ export struct BorderLeftWidthProp { // https://drafts.csswg.org/css-backgrounds/#the-border-radius export struct BorderRadiusTopRight { - Array>, 2> value = initial(); + Array, 2> value = initial(); static constexpr Str name() { return "border-top-right-radius"; } - static constexpr Array>, 2> initial() { - return makeArray>, 2>(Length{}); + static constexpr Array, 2> initial() { + return makeArray, 2>(Length{}); } void apply(SpecifiedValues& c) const { @@ -854,7 +854,7 @@ export struct BorderRadiusTopRight { c.borders.cow().radii.d = value[1]; } - static Array>, 2> load(SpecifiedValues const& c) { + static Array, 2> load(SpecifiedValues const& c) { return { c.borders->radii.c, c.borders->radii.d, @@ -862,11 +862,11 @@ export struct BorderRadiusTopRight { } Res<> parse(Cursor& c) { - value[0] = try$(parseValue>>(c)); + value[0] = try$(parseValue>(c)); if (c.ended()) { value[1] = value[0]; } else { - value[1] = try$(parseValue>>(c)); + value[1] = try$(parseValue>(c)); } return Ok(); @@ -875,12 +875,12 @@ export struct BorderRadiusTopRight { // https://drafts.csswg.org/css-backgrounds/#the-border-radius export struct BorderRadiusTopLeft { - Array>, 2> value = initial(); + Array, 2> value = initial(); static constexpr Str name() { return "border-top-left-radius"; } - static constexpr Array>, 2> initial() { - return makeArray>, 2>(Length{}); + static constexpr Array, 2> initial() { + return makeArray, 2>(Length{}); } void apply(SpecifiedValues& c) const { @@ -888,7 +888,7 @@ export struct BorderRadiusTopLeft { c.borders.cow().radii.b = value[0]; } - static Array>, 2> load(SpecifiedValues const& c) { + static Array, 2> load(SpecifiedValues const& c) { return { c.borders->radii.a, c.borders->radii.b, @@ -896,12 +896,12 @@ export struct BorderRadiusTopLeft { } Res<> parse(Cursor& c) { - value[0] = try$(parseValue>>(c)); + value[0] = try$(parseValue>(c)); eatWhitespace(c); if (c.ended()) { value[1] = value[0]; } else { - value[1] = try$(parseValue>>(c)); + value[1] = try$(parseValue>(c)); } return Ok(); @@ -910,12 +910,12 @@ export struct BorderRadiusTopLeft { // https://drafts.csswg.org/css-backgrounds/#the-border-radius export struct BorderRadiusBottomRight { - Array>, 2> value = initial(); + Array, 2> value = initial(); static constexpr Str name() { return "border-bottom-right-radius"; } - static constexpr Array>, 2> initial() { - return makeArray>, 2>(Length{}); + static constexpr Array, 2> initial() { + return makeArray, 2>(Length{}); } void apply(SpecifiedValues& c) const { @@ -923,7 +923,7 @@ export struct BorderRadiusBottomRight { c.borders.cow().radii.f = value[0]; } - static Array>, 2> load(SpecifiedValues const& c) { + static Array, 2> load(SpecifiedValues const& c) { return { c.borders->radii.e, c.borders->radii.f, @@ -931,11 +931,11 @@ export struct BorderRadiusBottomRight { } Res<> parse(Cursor& c) { - value[0] = try$(parseValue>>(c)); + value[0] = try$(parseValue>(c)); if (c.ended()) { value[1] = value[0]; } else { - value[1] = try$(parseValue>>(c)); + value[1] = try$(parseValue>(c)); } return Ok(); @@ -944,12 +944,12 @@ export struct BorderRadiusBottomRight { // https://drafts.csswg.org/css-backgrounds/#the-border-radius export struct BorderRadiusBottomLeft { - Array>, 2> value = initial(); + Array, 2> value = initial(); static constexpr Str name() { return "border-bottom-left-radius"; } - static constexpr Array>, 2> initial() { - return makeArray>, 2>(Length{}); + static constexpr Array, 2> initial() { + return makeArray, 2>(Length{}); } void apply(SpecifiedValues& c) const { @@ -957,7 +957,7 @@ export struct BorderRadiusBottomLeft { c.borders.cow().radii.h = value[1]; } - static Array>, 2> load(SpecifiedValues const& c) { + static Array, 2> load(SpecifiedValues const& c) { return { c.borders->radii.g, c.borders->radii.h, @@ -965,11 +965,11 @@ export struct BorderRadiusBottomLeft { } Res<> parse(Cursor& c) { - value[0] = try$(parseValue>>(c)); + value[0] = try$(parseValue>(c)); if (c.ended()) { value[1] = value[0]; } else { - value[1] = try$(parseValue>>(c)); + value[1] = try$(parseValue>(c)); } return Ok(); @@ -978,22 +978,22 @@ export struct BorderRadiusBottomLeft { // https://drafts.csswg.org/css-backgrounds/#the-border-radius export struct BorderRadius { - Math::Radii>> value = initial(); + Math::Radii> value = initial(); static constexpr Str name() { return "border-radius"; } - static Math::Radii>> initial() { return {CalcValue>(Length{})}; } + static Math::Radii>> initial() { return {Calc(Length{})}; } void apply(SpecifiedValues& c) const { c.borders.cow().radii = value; } - static Math::Radii>> load(SpecifiedValues const& c) { + static Math::Radii> load(SpecifiedValues const& c) { return c.borders->radii; } Res<> parse(Cursor& c) { - value = try$(parseValue>>>(c)); + value = try$(parseValue>>(c)); return Ok(); } }; @@ -1014,7 +1014,7 @@ export struct BorderTopProp { Res<> parse(Cursor& c) { while (not c.ended()) { - auto width = parseValue>(c); + auto width = parseValue>(c); if (width) { value.width = width.unwrap(); continue; @@ -1055,7 +1055,7 @@ export struct BorderRightProp { Res<> parse(Cursor& c) { while (not c.ended()) { - auto width = parseValue>(c); + auto width = parseValue>(c); if (width) { value.width = width.unwrap(); continue; @@ -1096,7 +1096,7 @@ export struct BorderBottomProp { Res<> parse(Cursor& c) { while (not c.ended()) { - auto width = parseValue>(c); + auto width = parseValue>(c); if (width) { value.width = width.unwrap(); continue; @@ -1137,7 +1137,7 @@ export struct BorderLeftProp { Res<> parse(Cursor& c) { while (not c.ended()) { - auto width = parseValue>(c); + auto width = parseValue>(c); if (width) { value.width = width.unwrap(); continue; @@ -1585,7 +1585,7 @@ export struct FlexProp { // deafult values if these parameters are omitted value.flexGrow = value.flexShrink = 1; - value.flexBasis = CalcValue>(Length{}); + value.flexBasis = Calc(Length{}); auto parseGrowShrink = [](Cursor& c, FlexItemProps& value) -> Res<> { auto grow = parseValue(c); @@ -1911,7 +1911,7 @@ export struct MarginTopProp { static Str name() { return "margin-top"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { c.margin.cow().top = value; @@ -1932,7 +1932,7 @@ export struct MarginRightProp { static Str name() { return "margin-right"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { c.margin.cow().end = value; @@ -1953,7 +1953,7 @@ export struct MarginBottomProp { static constexpr Str name() { return "margin-bottom"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { c.margin.cow().bottom = value; @@ -1974,7 +1974,7 @@ export struct MarginLeftProp { static Str name() { return "margin-left"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { c.margin.cow().start = value; @@ -1995,7 +1995,7 @@ export struct MarginProp { static Str name() { return "margin"; } - static Math::Insets initial() { return {CalcValue>(Length{})}; } + static Math::Insets initial() { return {Calc(Length{})}; } void apply(SpecifiedValues& c) const { c.margin.cow() = value; @@ -2018,7 +2018,7 @@ export struct MarginInlineStartProp { static Str name() { return "margin-inline-start"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { // FIXME: Take writing mode into account @@ -2040,7 +2040,7 @@ export struct MarginInlineEndProp { static Str name() { return "margin-inline-end"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { // FIXME: Take writing mode into account @@ -2062,7 +2062,7 @@ export struct MarginInlineProp { static Str name() { return "margin-inline"; } - static Math::Insets initial() { return {CalcValue>(Length{})}; } + static Math::Insets initial() { return {Calc(Length{})}; } void apply(SpecifiedValues& c) const { // FIXME: Take writing mode into account @@ -2088,7 +2088,7 @@ export struct MarginBlockStartProp { static Str name() { return "margin-block-start"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { // FIXME: Take writing mode into account @@ -2110,7 +2110,7 @@ export struct MarginBlockEndProp { static Str name() { return "margin-block-end"; } - static Width initial() { return CalcValue>(Length{}); } + static Width initial() { return Calc(Length{}); } void apply(SpecifiedValues& c) const { // FIXME: Take writing mode into account @@ -2132,7 +2132,7 @@ export struct MarginBlockProp { static Str name() { return "margin-block"; } - static Math::Insets initial() { return {CalcValue>(Length{})}; } + static Math::Insets initial() { return {Calc(Length{})}; } void apply(SpecifiedValues& c) const { // FIXME: Take writing mode into account @@ -2199,7 +2199,7 @@ export struct OutlineProp { Res<> parse(Cursor& c) { bool styleSet = false; while (not c.ended()) { - auto width = parseValue>(c); + auto width = parseValue>(c); if (width) { value.width = width.unwrap(); continue; @@ -2302,7 +2302,7 @@ export struct OutlineColorProp { // https://drafts.csswg.org/css-ui/#outline-offset export struct OutlineOffsetProp { - CalcValue value = initial(); + Calc value = initial(); static Str name() { return "outline-offset"; } @@ -2312,12 +2312,12 @@ export struct OutlineOffsetProp { c.outline.cow().offset = value; } - static CalcValue load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.outline->offset; } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; @@ -2452,7 +2452,7 @@ export struct OverflowProp { // https://www.w3.org/TR/css-box-3/#propdef-padding export struct PaddingTopProp { - CalcValue> value = initial(); + Calc value = initial(); static Str name() { return "padding-top"; } @@ -2462,18 +2462,18 @@ export struct PaddingTopProp { c.padding.cow().top = value; } - static CalcValue> load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.padding->top; } Res<> parse(Cursor& c) { - value = try$(parseValue>>(c)); + value = try$(parseValue>(c)); return Ok(); } }; export struct PaddingRightProp { - CalcValue> value = initial(); + Calc value = initial(); static Str name() { return "padding-right"; } @@ -2483,18 +2483,18 @@ export struct PaddingRightProp { c.padding.cow().end = value; } - static CalcValue> load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.padding->end; } Res<> parse(Cursor& c) { - value = try$(parseValue>>(c)); + value = try$(parseValue>(c)); return Ok(); } }; export struct PaddingBottomProp { - CalcValue> value = initial(); + Calc value = initial(); static Str name() { return "padding-bottom"; } @@ -2504,18 +2504,18 @@ export struct PaddingBottomProp { c.padding.cow().bottom = value; } - static CalcValue> load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.padding->bottom; } Res<> parse(Cursor& c) { - value = try$(parseValue>>(c)); + value = try$(parseValue>(c)); return Ok(); } }; export struct PaddingLeftProp { - CalcValue> value = initial(); + Calc value = initial(); static Str name() { return "padding-left"; } @@ -2525,18 +2525,18 @@ export struct PaddingLeftProp { c.padding.cow().start = value; } - static CalcValue> load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.padding->start; } Res<> parse(Cursor& c) { - value = try$(parseValue>>(c)); + value = try$(parseValue>(c)); return Ok(); } }; export struct PaddingInlineStart { - CalcValue> value = initial(); + Calc value = initial(); static Str name() { return "padding-inline-start"; } @@ -2546,18 +2546,18 @@ export struct PaddingInlineStart { c.padding.cow().start = value; } - static CalcValue> load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.padding->start; } Res<> parse(Cursor& c) { - value = try$(parseValue>>(c)); + value = try$(parseValue>(c)); return Ok(); } }; export struct PaddingInlineEnd { - CalcValue> value = initial(); + Calc value = initial(); static Str name() { return "padding-inline-end"; } @@ -2567,33 +2567,33 @@ export struct PaddingInlineEnd { c.padding.cow().end = value; } - static CalcValue> load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.padding->end; } Res<> parse(Cursor& c) { - value = try$(parseValue>>(c)); + value = try$(parseValue>(c)); return Ok(); } }; export struct PaddingProp { - Math::Insets>> value = initial(); + Math::Insets> value = initial(); static Str name() { return "padding"; } - static Math::Insets>> initial() { return {Length{}}; } + static Math::Insets> initial() { return {Length{}}; } void apply(SpecifiedValues& c) const { c.padding.cow() = value; } - static Math::Insets>> load(SpecifiedValues const& c) { + static Math::Insets> load(SpecifiedValues const& c) { return *c.padding; } Res<> parse(Cursor& c) { - value = try$(parseValue>>>(c)); + value = try$(parseValue>>(c)); return Ok(); } }; @@ -2987,8 +2987,8 @@ export struct TransformOriginProp { static TransformOrigin initial() { return { - .xOffset = CalcValue>{Percent{50}}, - .yOffset = CalcValue>{Percent{50}}, + .xOffset = Calc{Percent{50}}, + .yOffset = Calc{Percent{50}}, }; } @@ -3150,7 +3150,7 @@ export struct ZIndexProp { // https://svgwg.org/svg2-draft/geometry.html#XProperty export struct SVGXProp { - PercentOr value = initial(); + Calc value = initial(); static constexpr Str name() { return "x"; } @@ -3160,19 +3160,19 @@ export struct SVGXProp { c.svg.cow().x = value; } - static PercentOr load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.svg->x; } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; // https://svgwg.org/svg2-draft/geometry.html#YProperty export struct SVGYProp { - PercentOr value = initial(); + Calc value = initial(); static constexpr Str name() { return "y"; } @@ -3182,19 +3182,19 @@ export struct SVGYProp { c.svg.cow().y = value; } - static PercentOr load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.svg->y; } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; // https://svgwg.org/svg2-draft/geometry.html#CXProperty export struct SVGCXProp { - PercentOr value = initial(); + Calc value = initial(); static constexpr Str name() { return "cx"; } @@ -3204,19 +3204,19 @@ export struct SVGCXProp { c.svg.cow().cx = value; } - static PercentOr load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.svg->cx; } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; // https://svgwg.org/svg2-draft/geometry.html#CYProperty export struct SVGCYProp { - PercentOr value = initial(); + Calc value = initial(); static constexpr Str name() { return "cy"; } @@ -3226,19 +3226,19 @@ export struct SVGCYProp { c.svg.cow().cy = value; } - static PercentOr load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.svg->cy; } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; // https://svgwg.org/svg2-draft/geometry.html#RProperty export struct SVGRProp { - PercentOr value = initial(); + Calc value = initial(); static constexpr Str name() { return "r"; } @@ -3248,12 +3248,12 @@ export struct SVGRProp { c.svg.cow().r = value; } - static PercentOr load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.svg->r; } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; @@ -3397,7 +3397,7 @@ export struct FillOpacityProp { // https://svgwg.org/svg2-draft/painting.html#StrokeWidth export struct StrokeWidthProp { - PercentOr value = initial(); + Calc value = initial(); static constexpr Str name() { return "stroke-width"; } @@ -3407,12 +3407,12 @@ export struct StrokeWidthProp { c.svg.cow().strokeWidth = value; } - static PercentOr load(SpecifiedValues const& c) { + static Calc load(SpecifiedValues const& c) { return c.svg->strokeWidth; } Res<> parse(Cursor& c) { - value = try$(parseValue>(c)); + value = try$(parseValue>(c)); return Ok(); } }; diff --git a/src/vaev-engine/style/specified.cpp b/src/vaev-engine/style/specified.cpp index d23c9b46..16d49e5e 100644 --- a/src/vaev-engine/style/specified.cpp +++ b/src/vaev-engine/style/specified.cpp @@ -14,8 +14,8 @@ namespace Vaev::Style { struct TransformProps { Transform transform = Keywords::NONE; TransformOrigin origin = { - .xOffset = CalcValue>{Percent{0}}, - .yOffset = CalcValue>{Percent{0}}, + .xOffset = Calc{Percent{0}}, + .yOffset = Calc{Percent{0}}, }; TransformBox box = Keywords::BORDER_BOX; @@ -39,7 +39,7 @@ export struct SpecifiedValues { Cow backgrounds; Cow borders; - Cow margin = makeCow(Width(CalcValue>(Length(0_au)))); // FIXME + Cow margin = makeCow(Width(Calc(Length(0_au)))); // FIXME Cow outline; Cow padding = makeCow(Length(0_au)); // FIXME BoxSizing boxSizing; diff --git a/src/vaev-engine/style/tests/test-parse-value.cpp b/src/vaev-engine/style/tests/test-parse-value.cpp index 2ecb82ff..d87a6ba4 100644 --- a/src/vaev-engine/style/tests/test-parse-value.cpp +++ b/src/vaev-engine/style/tests/test-parse-value.cpp @@ -86,33 +86,33 @@ test$("vaev-css-build-margin") { try$(testCase( "margin: 30px;", - Margin{Width{CalcValue>{Length{30_au}}}} + Margin{Width{Calc{Length{30_au}}}} )); try$(testCase( "margin: 1px 2px;", Margin{ - Width{CalcValue>{Length{1_au}}}, - Width{CalcValue>{Length{2_au}}}, + Width{Calc{Length{1_au}}}, + Width{Calc{Length{2_au}}}, } )); try$(testCase( "margin: 1px 2px 3px;", Margin{ - Width{CalcValue>{Length{1_au}}}, - Width{CalcValue>{Length{2_au}}}, - Width{CalcValue>{Length{3_au}}}, + Width{Calc{Length{1_au}}}, + Width{Calc{Length{2_au}}}, + Width{Calc{Length{3_au}}}, } )); try$(testCase( "margin: 1px 2px 3px 4px;", Margin{ - Width{CalcValue>{Length{1_au}}}, - Width{CalcValue>{Length{2_au}}}, - Width{CalcValue>{Length{3_au}}}, - Width{CalcValue>{Length{4_au}}}, + Width{Calc{Length{1_au}}}, + Width{Calc{Length{2_au}}}, + Width{Calc{Length{3_au}}}, + Width{Calc{Length{4_au}}}, } )); diff --git a/src/vaev-engine/values/background.cpp b/src/vaev-engine/values/background.cpp index 36803395..3bc7e643 100644 --- a/src/vaev-engine/values/background.cpp +++ b/src/vaev-engine/values/background.cpp @@ -47,9 +47,9 @@ export struct BackgroundPosition { using VerticalAnchor = Union; HorizontalAnchor horizontalAnchor; - CalcValue> horizontal; + Calc horizontal; VerticalAnchor verticalAnchor; - CalcValue> vertical; + Calc vertical; constexpr BackgroundPosition() : horizontalAnchor(Keywords::LEFT), @@ -58,11 +58,11 @@ export struct BackgroundPosition { vertical(Percent{0}) { } - constexpr BackgroundPosition(CalcValue> horizontal, CalcValue> vertical) + constexpr BackgroundPosition(Calc horizontal, Calc vertical) : horizontalAnchor(Keywords::LEFT), horizontal(horizontal), verticalAnchor(Keywords::TOP), vertical(vertical) { } - constexpr BackgroundPosition(HorizontalAnchor horizontalAnchor, CalcValue> horizontal, VerticalAnchor verticalAnchor, CalcValue> vertical) + constexpr BackgroundPosition(HorizontalAnchor horizontalAnchor, Calc horizontal, VerticalAnchor verticalAnchor, Calc vertical) : horizontalAnchor(horizontalAnchor), horizontal(horizontal), verticalAnchor(verticalAnchor), vertical(vertical) { } @@ -80,7 +80,7 @@ struct ValueParser { if (c.ended()) return Error::invalidData("unexpected end of input"); - using Item = FlatUnion>>; + using Item = FlatUnion>; InlineVec items; for (int i = 0; i < 4 && not c.ended(); ++i) { @@ -108,16 +108,16 @@ struct ValueParser { items.pushBack(items.popFront()); BackgroundPosition::HorizontalAnchor hAnchor = Keywords::LEFT; - CalcValue> hValue = {Percent(0)}; + Calc hValue = {Percent(0)}; BackgroundPosition::VerticalAnchor vAnchor = Keywords::TOP; - CalcValue> vValue = {Percent(0)}; + Calc vValue = {Percent(0)}; try$(items[0].visit(Visitor{ [&](Meta::Contains auto& t) -> Res<> { hAnchor = t; return Ok(); }, - [&](CalcValue>& t) -> Res<> { + [&](Calc& t) -> Res<> { hValue = t; return Ok(); }, @@ -131,7 +131,7 @@ struct ValueParser { vAnchor = t; return Ok(); }, - [&](CalcValue>& t) -> Res<> { + [&](Calc& t) -> Res<> { vValue = t; return Ok(); }, @@ -145,11 +145,11 @@ struct ValueParser { // case 3 BackgroundPosition::HorizontalAnchor hAnchor = Keywords::LEFT; - CalcValue> hValue = {Percent(0)}; + Calc hValue = {Percent(0)}; bool hSet = false; BackgroundPosition::VerticalAnchor vAnchor = Keywords::TOP; - CalcValue> vValue = {Percent(0)}; + Calc vValue = {Percent(0)}; usize secondPairIndex = 2; @@ -158,7 +158,7 @@ struct ValueParser { hAnchor = t; hSet = true; - if (auto mesure = items[1].is>>()) { + if (auto mesure = items[1].is>()) { hValue = *mesure; } else { secondPairIndex = 1; @@ -177,7 +177,7 @@ struct ValueParser { [&](Meta::Contains auto& t) -> Res<> { vAnchor = t; - if (auto mesure = items[1].is>>()) { + if (auto mesure = items[1].is>()) { vValue = *mesure; } else { secondPairIndex = 1; @@ -204,7 +204,7 @@ struct ValueParser { hAnchor = t; if (secondPairIndex + 1 < items.len()) { - if (auto mesure = items[secondPairIndex + 1].is>>()) + if (auto mesure = items[secondPairIndex + 1].is>()) hValue = *mesure; else { return Error::invalidData("expected percent or length"); @@ -217,7 +217,7 @@ struct ValueParser { vAnchor = t; if (secondPairIndex + 1 < items.len()) { - if (auto mesure = items[secondPairIndex + 1].is>>()) + if (auto mesure = items[secondPairIndex + 1].is>()) vValue = *mesure; else { return Error::invalidData("unexpected last value"); diff --git a/src/vaev-engine/values/basic-shape.cpp b/src/vaev-engine/values/basic-shape.cpp index 897fc5ef..a94cab36 100644 --- a/src/vaev-engine/values/basic-shape.cpp +++ b/src/vaev-engine/values/basic-shape.cpp @@ -51,7 +51,7 @@ export Gfx::FillRule fillRuleToGfx(FillRule rule) { } export using ShapeRadius = Union< - CalcValue>, + Calc, Keywords::ClosestSide, Keywords::FarthestSide>; @@ -152,8 +152,8 @@ struct ValueParser { // https://www.w3.org/TR/css-shapes-1/#funcdef-basic-shape-inset export struct Inset { - Math::Insets>> insets = {Percent(0)}; - Math::Radii>> borderRadius = {Percent(0)}; + Math::Insets> insets = {Percent(0)}; + Math::Radii> borderRadius = {Percent(0)}; void repr(Io::Emit& e) const { e("(inset {} {})", insets, borderRadius); @@ -170,7 +170,7 @@ struct ValueParser { Inset result; Cursor scan = c->content; - if (auto insets = parseValue>>>(scan)) { + if (auto insets = parseValue>>(scan)) { result.insets = insets.unwrap(); } else { return Error::invalidData("expected insets"); @@ -179,7 +179,7 @@ struct ValueParser { eatWhitespace(scan); if (scan.skip(Css::Token::ident("round"))) { eatWhitespace(scan); - if (auto radii = parseValue>>>(scan)) { + if (auto radii = parseValue>>(scan)) { result.borderRadius = radii.unwrap(); } eatWhitespace(scan); @@ -249,7 +249,7 @@ struct ValueParser { export struct Polygon { Gfx::FillRule fillRule = Gfx::FillRule::NONZERO; - Vec>>> points; + Vec>> points; void repr(Io::Emit& e) const { e("(polygon {} {})", fillRule, points); @@ -276,9 +276,9 @@ struct ValueParser { begin = false; eatWhitespace(scan); - auto x = try$(parseValue>>(scan)); + auto x = try$(parseValue>(scan)); eatWhitespace(scan); - auto y = try$(parseValue>>(scan)); + auto y = try$(parseValue>(scan)); eatWhitespace(scan); result.points.emplaceBack(x, y); } @@ -297,8 +297,8 @@ struct ValueParser { // https://www.w3.org/TR/css-shapes-1/#funcdef-basic-shape-rect export struct Rect { - Math::Insets>> insets = {Percent(0), Percent(100), Percent(100), Percent(0)}; - Math::Radii>> borderRadius = {Percent(0)}; + Math::Insets> insets = {Percent(0), Percent(100), Percent(100), Percent(0)}; + Math::Radii> borderRadius = {Percent(0)}; void repr(Io::Emit& e) const { e("(rect {} {})", insets, borderRadius); @@ -317,24 +317,24 @@ struct ValueParser { eatWhitespace(scan); if (not parseValue(scan)) - result.insets.top = try$(parseValue>>(scan)); + result.insets.top = try$(parseValue>(scan)); eatWhitespace(scan); if (not parseValue(scan)) - result.insets.end = try$(parseValue>>(scan)); + result.insets.end = try$(parseValue>(scan)); eatWhitespace(scan); if (not parseValue(scan)) - result.insets.bottom = try$(parseValue>>(scan)); + result.insets.bottom = try$(parseValue>(scan)); eatWhitespace(scan); if (not parseValue(scan)) - result.insets.start = try$(parseValue>>(scan)); + result.insets.start = try$(parseValue>(scan)); eatWhitespace(scan); if (scan.skip(Css::Token::ident("round"))) { eatWhitespace(scan); - if (auto radii = parseValue>>>(scan)) { + if (auto radii = parseValue>>(scan)) { result.borderRadius = radii.unwrap(); } eatWhitespace(scan); @@ -353,8 +353,8 @@ struct ValueParser { // https://www.w3.org/TR/css-shapes-1/#funcdef-basic-shape-xywh export struct Xywh { - Math::Rect>> rect = {Percent(0), Percent(0), Percent(0), Percent(0)}; - Math::Radii>> borderRadius = {Percent(0)}; + Math::Rect> rect = {Percent(0), Percent(0), Percent(0), Percent(0)}; + Math::Radii> borderRadius = {Percent(0)}; void repr(Io::Emit& e) const { e("(xywh {} {})", rect, borderRadius); @@ -372,21 +372,21 @@ struct ValueParser { Cursor scan = c->content; eatWhitespace(scan); - result.rect.x = try$(parseValue>>(scan)); + result.rect.x = try$(parseValue>(scan)); eatWhitespace(scan); - result.rect.y = try$(parseValue>>(scan)); + result.rect.y = try$(parseValue>(scan)); eatWhitespace(scan); - result.rect.width = try$(parseValue>>(scan)); + result.rect.width = try$(parseValue>(scan)); eatWhitespace(scan); - result.rect.height = try$(parseValue>>(scan)); + result.rect.height = try$(parseValue>(scan)); eatWhitespace(scan); if (scan.skip(Css::Token::ident("round"))) { eatWhitespace(scan); - if (auto radii = parseValue>>>(scan)) { + if (auto radii = parseValue>>(scan)) { result.borderRadius = radii.unwrap(); } eatWhitespace(scan); diff --git a/src/vaev-engine/values/borders.cpp b/src/vaev-engine/values/borders.cpp index 336f39c3..bf7ef664 100644 --- a/src/vaev-engine/values/borders.cpp +++ b/src/vaev-engine/values/borders.cpp @@ -92,7 +92,7 @@ struct ValueParser { export struct BorderProps { Border top, start, bottom, end; - Math::Radii>> radii = {Length(0_au)}; + Math::Radii> radii = {Length(0_au)}; void all(Border b) { top = start = bottom = end = b; @@ -115,19 +115,19 @@ struct ValueParser> { if (c.ended()) return Error::invalidData("unexpected end of input"); - auto value1 = parseValue>(c); + auto value1 = parseValue>(c); if (not value1) return Ok(parsePostSlash(c, Math::Radii{Length{}})); - auto value2 = parseValue>(c); + auto value2 = parseValue>(c); if (not value2) return Ok(parsePostSlash(c, Math::Radii{value1.take()})); - auto value3 = parseValue>(c); + auto value3 = parseValue>(c); if (not value3) return Ok(parsePostSlash(c, Math::Radii{value1.take(), value2.take()})); - auto value4 = parseValue>(c); + auto value4 = parseValue>(c); if (not value4) return Ok(parsePostSlash(c, Math::Radii{value1.take(), value2.take(), value3.take(), value2.take()})); @@ -144,12 +144,12 @@ struct ValueParser> { if (not c.ended() and c.peek().token.data == "/"s) { c.next(); eatWhitespace(c); - auto value1 = parseValue>(c); + auto value1 = parseValue>(c); if (not value1) { return radii; } - auto value2 = parseValue>(c); + auto value2 = parseValue>(c); if (not value2) { radii.a = value1.take(); radii.d = value1.take(); @@ -159,7 +159,7 @@ struct ValueParser> { } eatWhitespace(c); - auto value3 = parseValue>(c); + auto value3 = parseValue>(c); if (not value3) { radii.a = value1.take(); radii.d = value2.take(); @@ -169,7 +169,7 @@ struct ValueParser> { } eatWhitespace(c); - auto value4 = parseValue>(c); + auto value4 = parseValue>(c); if (not value4) { radii.a = value1.take(); radii.d = value2.take(); diff --git a/src/vaev-engine/values/calc.cpp b/src/vaev-engine/values/calc.cpp index 194d360f..8f882a20 100644 --- a/src/vaev-engine/values/calc.cpp +++ b/src/vaev-engine/values/calc.cpp @@ -10,6 +10,7 @@ import :css; import :values.base; import :values.length; import :values.primitives; +import :values.percent; using namespace Karm; @@ -32,11 +33,12 @@ export enum struct CalcOp { // 10. Mathematical Expressions // https://drafts.csswg.org/css-values/#math export template -struct CalcValue { - using Leaf = Box>; +struct Calc { + using Leaf = Box; using Value = Union< T, + Percent, Leaf, Number>; @@ -58,23 +60,23 @@ struct CalcValue { Inner _inner; - constexpr CalcValue() - : CalcValue(T{}) { + constexpr Calc() + : Calc(T{}) { } - constexpr CalcValue(Meta::Convertible auto val) + constexpr Calc(Meta::Convertible auto val) : _inner(Value{T{val}}) { } - constexpr CalcValue(Value val) + constexpr Calc(Value val) : _inner(val) { } - constexpr CalcValue(CalcOp op, Value val) + constexpr Calc(CalcOp op, Value val) : _inner(makeBox(op, val)) { } - constexpr CalcValue(CalcOp op, Value lhs, Value rhs) + constexpr Calc(CalcOp op, Value lhs, Value rhs) : _inner(makeBox(op, lhs, rhs)) { } @@ -108,8 +110,8 @@ struct CalcValue { }; export template -struct ValueParser> { - static Res> parse(Cursor& c) { +struct ValueParser> { + static Res> parse(Cursor& c) { if (c.ended()) return Error::invalidData("unexpected end of input"); @@ -123,13 +125,13 @@ struct ValueParser> { auto op = parseOp(content); if (not op) - return Ok(CalcValue{lhs}); + return Ok(Calc{lhs}); if (content.peek() == Css::Token::WHITESPACE) { content.next(); } auto rhs = try$(parseVal(content)); - return Ok(CalcValue{op.unwrap(), lhs, rhs}); + return Ok(Calc{op.unwrap(), lhs, rhs}); } } @@ -161,7 +163,7 @@ struct ValueParser> { return Error::invalidData("unexpected operator"); } - static Res::Value> parseVal(Cursor& c) { + static Res::Value> parseVal(Cursor& c) { if (c.ended()) return Error::invalidData("unexpected end of input"); diff --git a/src/vaev-engine/values/font.cpp b/src/vaev-engine/values/font.cpp index 0feceb3a..9e168b29 100644 --- a/src/vaev-engine/values/font.cpp +++ b/src/vaev-engine/values/font.cpp @@ -260,13 +260,13 @@ export struct FontSize { using enum _Named; _Named _named; - PercentOr _value; + Calc _value; constexpr FontSize(_Named named = MEDIUM) : _named(named), _value(Length{}) { } - constexpr FontSize(PercentOr size) + constexpr FontSize(Calc size) : _named(LENGTH), _value(size) { } @@ -274,7 +274,7 @@ export struct FontSize { return _named; } - PercentOr value() const { + Calc value() const { if (_named != LENGTH) panic("not a length"); return _value; @@ -314,7 +314,7 @@ struct ValueParser { else if (c.skip(Css::Token::ident("larger"))) return Ok(FontSize::LARGER); else - return Ok(try$(parseValue>(c))); + return Ok(try$(parseValue>(c))); } }; diff --git a/src/vaev-engine/values/insets.cpp b/src/vaev-engine/values/insets.cpp index 8dc04404..a5363d55 100644 --- a/src/vaev-engine/values/insets.cpp +++ b/src/vaev-engine/values/insets.cpp @@ -51,7 +51,7 @@ struct ValueParser { export using Margin = Math::Insets; -export using Padding = Math::Insets>>; +export using Padding = Math::Insets>; // https://www.w3.org/TR/CSS22/visuren.html#propdef-top // https://www.w3.org/TR/CSS22/visuren.html#propdef-right @@ -87,7 +87,7 @@ struct ValueParser> { export using Gap = Union< Keywords::Normal, - CalcValue>>; + Calc>; export struct Gaps { Gap x = Keywords::NORMAL; diff --git a/src/vaev-engine/values/line-height.cpp b/src/vaev-engine/values/line-height.cpp index 5cbe4525..76df6adb 100644 --- a/src/vaev-engine/values/line-height.cpp +++ b/src/vaev-engine/values/line-height.cpp @@ -16,15 +16,16 @@ using namespace Karm; namespace Vaev { +// https://drafts.csswg.org/css-inline/#line-height-property export struct LineHeight { struct _Normal {}; static constexpr _Normal NORMAL = {}; - Union, Number> _value; + Union, Number> _value; LineHeight(_Normal) : _value(1.2) {} - LineHeight(PercentOr value) : _value(value) {} + LineHeight(Calc value) : _value(value) {} LineHeight(Number value) : _value(value) {} @@ -52,7 +53,7 @@ struct ValueParser { } } - return Ok(LineHeight{try$(parseValue>(c))}); + return Ok(LineHeight{try$(parseValue>(c))}); } }; diff --git a/src/vaev-engine/values/line-width.cpp b/src/vaev-engine/values/line-width.cpp index 3c47a0c2..914e0be4 100644 --- a/src/vaev-engine/values/line-width.cpp +++ b/src/vaev-engine/values/line-width.cpp @@ -25,7 +25,7 @@ export using LineWidth = Union< Keywords::Thin, Keywords::Medium, Keywords::Thick, - CalcValue>; + Calc>; export template <> struct ValueParser { @@ -46,7 +46,7 @@ struct ValueParser { return Ok(Keywords::THICK); } - return Ok(try$(parseValue>(c))); + return Ok(try$(parseValue>(c))); } }; diff --git a/src/vaev-engine/values/outline.cpp b/src/vaev-engine/values/outline.cpp index d7816ac6..631840df 100644 --- a/src/vaev-engine/values/outline.cpp +++ b/src/vaev-engine/values/outline.cpp @@ -11,7 +11,7 @@ namespace Vaev { // https://drafts.csswg.org/css-ui/#outline export struct Outline { LineWidth width = Keywords::MEDIUM; - CalcValue offset = 0_au; + Calc offset = 0_au; Union style = Gfx::BorderStyle::NONE; Union color = Keywords::AUTO; diff --git a/src/vaev-engine/values/percent.cpp b/src/vaev-engine/values/percent.cpp index 97ef3919..23d1a51a 100644 --- a/src/vaev-engine/values/percent.cpp +++ b/src/vaev-engine/values/percent.cpp @@ -32,14 +32,6 @@ struct ValueParser { } }; -export template -using PercentOr = Union; - -export template -struct _Resolved> { - using Type = Resolved; -}; - } // namespace Vaev export template <> diff --git a/src/vaev-engine/values/sizing.cpp b/src/vaev-engine/values/sizing.cpp index 373ff647..052ce8ec 100644 --- a/src/vaev-engine/values/sizing.cpp +++ b/src/vaev-engine/values/sizing.cpp @@ -28,7 +28,7 @@ export enum struct BoxSizing : u8 { // https://drafts.csswg.org/css-sizing-3/#preferred-size-properties export struct FitContent { - CalcValue> value = {Length{}}; + Calc value = {Length{}}; void repr(Io::Emit& e) const { e("(fit-content {})", value); @@ -44,7 +44,7 @@ struct ValueParser { if (c->prefix == Css::Token::function("fit-content(")) { FitContent result; Cursor scan = c->content; - result.value = try$(parseValue>(scan)); + result.value = try$(parseValue>(scan)); c.next(); return Ok(result); } @@ -54,8 +54,8 @@ struct ValueParser { // https://www.w3.org/TR/css-sizing-3/#propdef-width // https://www.w3.org/TR/css-sizing-3/#propdef-height -export using Size = FlatUnion>, Keywords::MinContent, Keywords::MaxContent, FitContent>; -export using MaxSize = FlatUnion>, Keywords::MinContent, Keywords::MaxContent, FitContent>; +export using Size = FlatUnion, Keywords::MinContent, Keywords::MaxContent, FitContent>; +export using MaxSize = FlatUnion, Keywords::MinContent, Keywords::MaxContent, FitContent>; export struct SizingProps { Size width = Keywords::AUTO, height = Keywords::AUTO; diff --git a/src/vaev-engine/values/svg.cpp b/src/vaev-engine/values/svg.cpp index b0a94d9e..8ead9548 100644 --- a/src/vaev-engine/values/svg.cpp +++ b/src/vaev-engine/values/svg.cpp @@ -56,14 +56,14 @@ export struct ViewBox { }; export struct SVGProps { - PercentOr x = Length{0_au}; - PercentOr y = Length{0_au}; - PercentOr cx = Length{0_au}; - PercentOr cy = Length{0_au}; - PercentOr r = Length{0_au}; + Calc x = Length{0_au}; + Calc y = Length{0_au}; + Calc cx = Length{0_au}; + Calc cy = Length{0_au}; + Calc r = Length{0_au}; Number fillOpacity = 1; - PercentOr strokeWidth = Length{1_au}; + Calc strokeWidth = Length{1_au}; Union d = NONE; diff --git a/src/vaev-engine/values/transform.cpp b/src/vaev-engine/values/transform.cpp index aea77233..338297aa 100644 --- a/src/vaev-engine/values/transform.cpp +++ b/src/vaev-engine/values/transform.cpp @@ -24,12 +24,12 @@ namespace Vaev { // https://drafts.csswg.org/css-transforms/#transform-origin-property export struct TransformOrigin { - using OneValue = Union>>; + using OneValue = Union>; using XOffsetKeyword = Union; - using XOffset = FlatUnion>>; + using XOffset = FlatUnion>; using YOffsetKeyword = Union; - using YOffset = FlatUnion>>; + using YOffset = FlatUnion>; XOffset xOffset; YOffset yOffset; @@ -105,7 +105,7 @@ struct ValueParser { }); }, - [&](CalcValue> value) -> Res { + [&](Calc value) -> Res { return Ok(TransformOrigin{ .xOffset = std::move(value), .yOffset = Keywords::CENTER, // default y-offset @@ -130,7 +130,7 @@ export using TransformBox = Union< // https://www.w3.org/TR/css-transforms-1/#funcdef-transform-matrix export struct MatrixTransform { - Array, 6> values; + Array, 6> values; void repr(Io::Emit& e) const { e("matrix({}, {}, {}, {}, {}, {})", values[0], values[1], values[2], values[3], values[4], values[5]); @@ -148,13 +148,13 @@ struct ValueParser { Cursor content = c->content; eatWhitespace(content); - Array, 6> values; + Array, 6> values; for (usize i = 0; i < 6; ++i) { if (content.ended()) return Error::invalidData("unexpected end of input"); - auto value = try$(parseValue>(content)); + auto value = try$(parseValue>(content)); values[i] = std::move(value); if (i < 5) skipOmmitableComma(content); @@ -167,8 +167,8 @@ struct ValueParser { // https://www.w3.org/TR/css-transforms-1/#funcdef-transform-translate export struct TranslateTransform { - CalcValue> x; - CalcValue> y; + Calc x; + Calc y; void repr(Io::Emit& e) const { e("translate({}, {})", x, y); @@ -184,7 +184,7 @@ struct ValueParser { if (c->prefix == Css::Token::function("translateX(")) { Cursor content = c->content; eatWhitespace(content); - auto tx = try$(parseValue>>(content)); + auto tx = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) { return Error::invalidData("unexpected content after translateX function"); @@ -196,7 +196,7 @@ struct ValueParser { if (c->prefix == Css::Token::function("translateY(")) { Cursor content = c->content; eatWhitespace(content); - auto ty = try$(parseValue>>(content)); + auto ty = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) return Error::invalidData("unexpected content after translateY function"); @@ -210,7 +210,7 @@ struct ValueParser { Cursor content = c->content; eatWhitespace(content); - auto tx = try$(parseValue>>(content)); + auto tx = try$(parseValue>(content)); skipOmmitableComma(content); if (content.ended()) { @@ -219,7 +219,7 @@ struct ValueParser { return Ok(TranslateTransform{std::move(tx), Length{0_au}}); } - auto ty = try$(parseValue>>(content)); + auto ty = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) return Error::invalidData("unexpected content after scale function"); @@ -231,8 +231,8 @@ struct ValueParser { // https://www.w3.org/TR/css-transforms-1/#funcdef-transform-scale export struct ScaleTransform { - CalcValue x; - CalcValue y; + Calc x; + Calc y; void repr(Io::Emit& e) const { e("scale({}, {})", x, y); @@ -248,7 +248,7 @@ struct ValueParser { if (c->prefix == Css::Token::function("scaleX(")) { Cursor content = c->content; eatWhitespace(content); - auto sx = try$(parseValue>(content)); + auto sx = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) { return Error::invalidData("unexpected content after scaleX function"); @@ -260,7 +260,7 @@ struct ValueParser { if (c->prefix == Css::Token::function("scaleY(")) { Cursor content = c->content; eatWhitespace(content); - auto sy = try$(parseValue>(content)); + auto sy = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) return Error::invalidData("unexpected content after scaleY function"); @@ -274,7 +274,7 @@ struct ValueParser { Cursor content = c->content; eatWhitespace(content); - auto x = try$(parseValue>(content)); + auto x = try$(parseValue>(content)); skipOmmitableComma(content); // If the second parameter is not provided, it takes a value equal to the first. @@ -284,7 +284,7 @@ struct ValueParser { return Ok(ScaleTransform{std::move(x), std::move(y)}); } - auto y = try$(parseValue>(content)); + auto y = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) return Error::invalidData("unexpected content after scale function"); @@ -296,7 +296,7 @@ struct ValueParser { // https://www.w3.org/TR/css-transforms-1/#funcdef-transform-rotate export struct RotateTransform { - CalcValue value; + Calc value; void repr(Io::Emit& e) const { e("rotate({})", value); @@ -315,7 +315,7 @@ struct ValueParser { Cursor content = c->content; eatWhitespace(content); - auto value = try$(parseValue>(content)); + auto value = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) @@ -328,8 +328,8 @@ struct ValueParser { // https://www.w3.org/TR/css-transforms-1/#funcdef-transform-skew export struct SkewTransform { - CalcValue x; - CalcValue y; + Calc x; + Calc y; void repr(Io::Emit& e) const { e("skew({}, {})", x, y); @@ -348,7 +348,7 @@ struct ValueParser { Cursor content = c->content; eatWhitespace(content); - auto x = try$(parseValue>(content)); + auto x = try$(parseValue>(content)); skipOmmitableComma(content); // If the second parameter is not provided, it has a zero value. @@ -357,7 +357,7 @@ struct ValueParser { return Ok(SkewTransform{std::move(x), Angle::fromDegree(0.)}); } - auto y = try$(parseValue>(content)); + auto y = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) @@ -370,7 +370,7 @@ struct ValueParser { // https://www.w3.org/TR/css-transforms-1/#funcdef-transform-skewx export struct SkewXTransform { - CalcValue value; + Calc value; void repr(Io::Emit& e) const { e("skewX({})", value); @@ -389,7 +389,7 @@ struct ValueParser { Cursor content = c->content; eatWhitespace(content); - auto value = try$(parseValue>(content)); + auto value = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) @@ -402,7 +402,7 @@ struct ValueParser { // https://www.w3.org/TR/css-transforms-1/#funcdef-transform-skewy export struct SkewYTransform { - CalcValue value; + Calc value; void repr(Io::Emit& e) const { e("skewY({})", value); @@ -421,7 +421,7 @@ struct ValueParser { Cursor content = c->content; eatWhitespace(content); - auto value = try$(parseValue>(content)); + auto value = try$(parseValue>(content)); eatWhitespace(content); if (not content.ended()) diff --git a/src/vaev-engine/values/width.cpp b/src/vaev-engine/values/width.cpp index 09408825..5bf60983 100644 --- a/src/vaev-engine/values/width.cpp +++ b/src/vaev-engine/values/width.cpp @@ -13,6 +13,6 @@ namespace Vaev { export using Width = FlatUnion< Keywords::Auto, - CalcValue>>; + Calc>; } // namespace Vaev