Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/vaev-engine/layout/flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,21 @@ struct FlexItem {
// https://www.w3.org/TR/css-flexbox-1/#valdef-flex-basis-auto
void computeFlexBaseSize(Tree& tree, Opt<Au> mainContainerSize, IntrinsicSize containerSizing) {
// A NONE return here indicates a CONTENT case for the flex basis
auto getDefiniteFlexBasisSize = [](FlexProps& flexItemProps, FlexAxis& fa, Box* box) -> Opt<CalcValue<PercentOr<Length>>> {
auto getDefiniteFlexBasisSize = [](FlexProps& flexItemProps, FlexAxis& fa, Box* box) -> Opt<Calc<Length>> {
if (flexItemProps.basis.is<Keywords::Content>())
return NONE;

// from now on flex basis is width

if (auto basisCalc = flexItemProps.basis.is<CalcValue<PercentOr<Length>>>())
if (auto basisCalc = flexItemProps.basis.is<Calc<Length>>())
return *basisCalc;

if (not fa.mainAxis(box->style->sizing).is<CalcValue<PercentOr<Length>>>())
if (not fa.mainAxis(box->style->sizing).is<Calc<Length>>())
return NONE;

// TODO: solve definite values also min and max content

return fa.mainAxis(box->style->sizing).unwrap<CalcValue<PercentOr<Length>>>();
return fa.mainAxis(box->style->sizing).unwrap<Calc<Length>>();
};

if (auto flexBasisDefiniteSize = getDefiniteFlexBasisSize(flexItemProps, fa, box)) {
Expand Down Expand Up @@ -300,7 +300,7 @@ struct FlexItem {
Au getMinAutoPrefMainSize(Tree& tree, Vec2Au containerSize) const {
Opt<Au> definiteMaxMainSize;
auto maxMainSize = box->style->sizing->maxSize(fa.isRowOriented ? Axis::HORIZONTAL : Axis::VERTICAL);
if (auto maxMainSizeCalc = maxMainSize.is<CalcValue<PercentOr<Length>>>()) {
if (auto maxMainSizeCalc = maxMainSize.is<Calc<Length>>()) {
definiteMaxMainSize = resolve(
tree,
*box,
Expand All @@ -315,7 +315,7 @@ struct FlexItem {
contentSizeSuggestion = min(contentSizeSuggestion, definiteMaxMainSize.unwrap());

auto mainAxis = fa.mainAxis(box->style->sizing);
if (auto mainAxisCalc = mainAxis.is<CalcValue<PercentOr<Length>>>()) {
if (auto mainAxisCalc = mainAxis.is<Calc<Length>>()) {
Au specifiedSizeSuggestion = resolve(
tree,
*box,
Expand All @@ -338,7 +338,7 @@ struct FlexItem {
MaxSize maxSizeToResolve = isWidth ? box->style->sizing->maxWidth : box->style->sizing->maxHeight;

auto visitor = Visitor{
[&](CalcValue<PercentOr<Length>> const& v) {
[&](Calc<Length> const& v) {
return resolve(
tree,
*box,
Expand Down Expand Up @@ -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<CalcValue<PercentOr<Length>>>()) {
if (auto mainAxisCalc = mainAxis.is<Calc<Length>>()) {
contentContribution = max(
contentContribution,
resolve(
Expand Down Expand Up @@ -425,7 +425,7 @@ struct FlexItem {
);

auto crossAxis = fa.crossAxis(box->style->sizing);
if (auto crossAxisCalc = crossAxis.is<CalcValue<PercentOr<Length>>>()) {
if (auto crossAxisCalc = crossAxis.is<Calc<Length>>()) {
contentContribution = max(
contentContribution,
resolve(
Expand Down Expand Up @@ -702,11 +702,11 @@ struct FlexFormatingContext : FormatingContext {

void _determineFlexBaseSizeAndHypotheticalMainSize(Tree& tree, Box& box, Input input) {
Opt<Au> containerDefiniteMainSize = fa.mainAxis(input.knownSize);
if (fa.mainAxis(box.style->sizing).is<CalcValue<PercentOr<Length>>>()) {
if (fa.mainAxis(box.style->sizing).is<Calc<Length>>()) {
containerDefiniteMainSize = resolve(
tree,
box,
fa.mainAxis(box.style->sizing).unwrap<CalcValue<PercentOr<Length>>>(),
fa.mainAxis(box.style->sizing).unwrap<Calc<Length>>(),
fa.mainAxis(input.containingBlock)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-engine/layout/layout-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Opt<Au> computeSpecifiedSize(Tree& tree, Box& box, Size size, Vec2Au containingB
return clamp(stretchIntrinsicSize.y, minIntrinsicSize.y, maxIntrinsicSize.y);
} else if (size.is<Keywords::Auto>()) {
return NONE;
} else if (auto calc = size.is<CalcValue<PercentOr<Length>>>()) {
} else if (auto calc = size.is<Calc<Length>>()) {
return resolve(tree, box, *calc, isWidth ? containingBlock.x : containingBlock.y);
} else {
logWarn("unknown specified size: {}", size);
Expand Down
12 changes: 6 additions & 6 deletions src/vaev-engine/layout/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static void _paintChildren(Frag& frag, Scene::Stack& stack, auto predicate) {
}
}

static Math::Radiif _resolveRadii(Resolver& resolver, Math::Radii<CalcValue<PercentOr<Length>>> const& baseRadii, RectAu const& referenceBox) {
static Math::Radiif _resolveRadii(Resolver& resolver, Math::Radii<Calc<Length>> const& baseRadii, RectAu const& referenceBox) {
Math::Radiif radii;
radii.a = resolver.resolve(baseRadii.a, referenceBox.height).cast<f64>();
radii.b = resolver.resolve(baseRadii.b, referenceBox.width).cast<f64>();
Expand Down Expand Up @@ -356,7 +356,7 @@ static Rc<Scene::Clip> _applyClip(Frag const& frag, Rc<Scene::Node> content) {
auto hSquared = Math::pow2(referenceBox.height.cast<f64>());
auto wSquared = Math::pow2(referenceBox.width.cast<f64>());
radius = resolver.resolve(
circle.radius.unwrap<CalcValue<PercentOr<Length>>>(),
circle.radius.unwrap<Calc<Length>>(),
Au(Math::sqrt(hSquared + wSquared) / Math::sqrt(2.0))
)
.cast<f64>();
Expand Down Expand Up @@ -420,7 +420,7 @@ static Rc<Scene::Clip> _applyClip(Frag const& frag, Rc<Scene::Node> content) {
rx = max(Math::abs(referenceBox.width.cast<f64>() - center.x), center.x);
} else {
rx = resolver.resolve(
ellipse.rx.unwrap<CalcValue<PercentOr<Length>>>(),
ellipse.rx.unwrap<Calc<Length>>(),
referenceBox.width
)
.cast<f64>();
Expand All @@ -433,7 +433,7 @@ static Rc<Scene::Clip> _applyClip(Frag const& frag, Rc<Scene::Node> content) {
ry = max(Math::abs(referenceBox.height.cast<f64>() - center.y), center.y);
} else {
ry = resolver.resolve(
ellipse.ry.unwrap<CalcValue<PercentOr<Length>>>(),
ellipse.ry.unwrap<Calc<Length>>(),
referenceBox.height
)
.cast<f64>();
Expand Down Expand Up @@ -516,7 +516,7 @@ static Vec2Au _resolveTransformOrigin(RectAu referenceBox, TransformOrigin origi
[&](Keywords::Center) {
return referenceBox.center().x;
},
[&](CalcValue<PercentOr<Length>> value) {
[&](Calc<Length> value) {
return referenceBox.start() + resolver.resolve(value, referenceBox.width);
}
}
Expand All @@ -533,7 +533,7 @@ static Vec2Au _resolveTransformOrigin(RectAu referenceBox, TransformOrigin origi
[&](Keywords::Center) {
return referenceBox.center().y;
},
[&](CalcValue<PercentOr<Length>> value) {
[&](Calc<Length> value) {
return referenceBox.top() + resolver.resolve(value, referenceBox.height);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/vaev-engine/layout/positioned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CalcValue<PercentOr<Length>>>()) {
if (auto topOffsetCalc = topOffset.is<Calc<Length>>()) {
top = origin.y + resolve(tree, *frag.box, *topOffsetCalc, relativeTo.height);
}

auto startOffset = style.offsets->start;
if (auto startOffsetCalc = startOffset.is<CalcValue<PercentOr<Length>>>()) {
if (auto startOffsetCalc = startOffset.is<Calc<Length>>()) {
start = origin.x + resolve(tree, *frag.box, *startOffsetCalc, relativeTo.width);
}

auto endOffset = frag.style().offsets->end;
if (auto endOffsetCalc = endOffset.is<CalcValue<PercentOr<Length>>>()) {
if (auto endOffsetCalc = endOffset.is<Calc<Length>>()) {
start = (origin.x + relativeTo.width) - resolve(tree, *frag.box, *endOffsetCalc, relativeTo.width) - metrics.borderSize.width;
}

Expand Down
14 changes: 7 additions & 7 deletions src/vaev-engine/layout/svg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ using namespace Karm;
namespace Vaev::Layout {

// SVG sizes shouldn't be defined using calc values
Opt<PercentOr<Length>> extractValueFromCalc(CalcValue<PercentOr<Length>> const& size) {
Opt<PercentOr<Length>> extractValueFromCalc(Calc<Length> const& size) {
return size.visit(
Visitor{
[](CalcValue<PercentOr<Length>>::Value const& v) {
[](Calc<Length>::Value const& v) {
return Opt<PercentOr<Length>>{v.unwrap<PercentOr<Length>>()};
},
[](auto const) {
Expand All @@ -32,7 +32,7 @@ PercentOr<Length> fromSize(Size const& size) {
if (size.is<Keywords::Auto>())
return PercentOr<Length>{Percent{100}};

return extractValueFromCalc(size.unwrap<CalcValue<PercentOr<Length>>>())
return extractValueFromCalc(size.unwrap<Calc<Length>>())
.unwrapOr(PercentOr<Length>{Percent{100}});
}

Expand Down Expand Up @@ -158,15 +158,15 @@ Rc<Scene::Node> circleToSceneNode(Circle<f64> circle, Opt<Gfx::Fill> fill, Opt<G
return makeRc<Scene::Shape>(path, stroke, fill);
}

Circle<PercentOr<Length>> buildCircle(Style::SpecifiedValues const& style) {
Circle<Calc<Length>> buildCircle(Style::SpecifiedValues const& style) {
return {
style.svg->cx,
style.svg->cy,
style.svg->r,
};
}

Circle<Au> resolve(Circle<PercentOr<Length>> const& circle, Karm::Vec2Au const& relativeTo) {
Circle<Au> resolve(Circle<Calc<Length>> const& circle, Karm::Vec2Au const& relativeTo) {
return {
Vaev::Layout::resolve(circle.cx, relativeTo.x),
Vaev::Layout::resolve(circle.cy, relativeTo.y),
Expand Down Expand Up @@ -385,10 +385,10 @@ Opt<Number> intrinsicAspectRatio(Opt<ViewBox> 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<Length> {
if (not size.is<CalcValue<PercentOr<Length>>>())
if (not size.is<Calc<Length>>())
return NONE;

auto calc = size.unwrap<CalcValue<PercentOr<Length>>>();
auto calc = size.unwrap<Calc<Length>>();

auto percOrLength = extractValueFromCalc(calc);
if (not percOrLength)
Expand Down
28 changes: 14 additions & 14 deletions src/vaev-engine/layout/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Keywords::Auto>() or box.style->sizing->width.is<CalcValue<PercentOr<Length>>>()))
if (not(box.style->sizing->width.is<Keywords::Auto>() or box.style->sizing->width.is<Calc<Length>>()))
logWarn("width can't be anything other than 'auto' or a length in a table context");

tableUsedWidth =
not box.style->sizing->width.is<CalcValue<PercentOr<Length>>>()
not box.style->sizing->width.is<Calc<Length>>()
? 0_au // AUTO case
: resolve(tree, box, box.style->sizing->width.unwrap<CalcValue<PercentOr<Length>>>(), availableXSpace) -
: resolve(tree, box, box.style->sizing->width.unwrap<Calc<Length>>(), availableXSpace) -
boxBorder.horizontal(); // NOTE: maybe remove this after borderbox param is clearer

auto [columnBorders, sumBorders] = getColumnBorders();
Expand All @@ -465,10 +465,10 @@ struct TableFormatingContext : FormatingContext {

auto const& width = col.el.style->sizing->width;

if (not(width.is<Keywords::Auto>() or width.is<CalcValue<PercentOr<Length>>>()))
if (not(width.is<Keywords::Auto>() or width.is<Calc<Length>>()))
logWarn("width can't be anything other than 'auto' or a length in a table context");

if (auto widthCalc = width.is<CalcValue<PercentOr<Length>>>()) {
if (auto widthCalc = width.is<Calc<Length>>()) {
for (usize x = col.start; x <= col.end; ++x) {
colWidthOrNone[x] = resolve(tree, col.el, *widthCalc, tableUsedWidth);
}
Expand All @@ -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<CalcValue<PercentOr<Length>>>();
auto cellBoxWidthCalc = cell.box->style->sizing->width.is<Calc<Length>>();

if (not(cell.box->style->sizing->width.is<Keywords::Auto>() or cellBoxWidthCalc))
logWarn("width can't be anything other than 'auto' or a length in a table context");
Expand Down Expand Up @@ -557,10 +557,10 @@ struct TableFormatingContext : FormatingContext {
auto cellMinWidth = cellMinOutput.x;
auto cellMaxWidth = cellMaxOutput.x;

if (not(cell.box->style->sizing->width.is<Keywords::Auto>() or cell.box->style->sizing->width.is<CalcValue<PercentOr<Length>>>()))
if (not(cell.box->style->sizing->width.is<Keywords::Auto>() or cell.box->style->sizing->width.is<Calc<Length>>()))
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<CalcValue<PercentOr<Length>>>()) {
if (auto cellBoxWidthCalc = cell.box->style->sizing->width.is<Calc<Length>>()) {
auto cellPreferredWidth = resolve(
tree,
box,
Expand Down Expand Up @@ -640,7 +640,7 @@ struct TableFormatingContext : FormatingContext {
for (auto& group : colGroups) {

auto columnGroupWidth = group.el.style->sizing->width;
auto columnGroupWidthCalc = columnGroupWidth.is<CalcValue<PercentOr<Length>>>();
auto columnGroupWidthCalc = columnGroupWidth.is<Calc<Length>>();

if (not(columnGroupWidth.is<Keywords::Auto>() or columnGroupWidthCalc))
logWarn("width can't be anything other than 'auto' or a length in a table context");
Expand Down Expand Up @@ -668,7 +668,7 @@ struct TableFormatingContext : FormatingContext {
void computeAutoWidthOfCols(Tree& tree, Vec<Au>& minColWidth, Vec<Au>& maxColWidth, Au tableWidth) {
for (auto& [start, end, el] : cols) {
auto width = el.style->sizing->width;
auto widthCalc = width.is<CalcValue<PercentOr<Length>>>();
auto widthCalc = width.is<Calc<Length>>();

if (not(width.is<Keywords::Auto>() or widthCalc))
logWarn("width can't be anything other than 'auto' or a length in a table context");
Expand Down Expand Up @@ -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<CalcValue<PercentOr<Length>>>()) {
if (auto boxWidthCalc = box.style->sizing->width.is<Calc<Length>>()) {
auto [minWithoutPerc, maxWithoutPerc] = computeMinMaxAutoWidths(tree, grid.size.x, 0_au);

Au tableComputedWidth = resolve(tree, box, *boxWidthCalc, containingBlockX);
Expand Down Expand Up @@ -791,7 +791,7 @@ struct TableFormatingContext : FormatingContext {

for (auto& row : rows) {
auto& height = row.el.style->sizing->height;
auto heightCalc = height.is<CalcValue<PercentOr<Length>>>();
auto heightCalc = height.is<Calc<Length>>();

if (not(height.is<Keywords::Auto>() or heightCalc))
logWarn("height can't be anything other than 'auto' or a length in a table context");
Expand All @@ -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<Keywords::Auto>() or cell.box->style->sizing->height.is<CalcValue<PercentOr<Length>>>()))
if (not(cell.box->style->sizing->height.is<Keywords::Auto>() or cell.box->style->sizing->height.is<Calc<Length>>()))
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<CalcValue<PercentOr<Length>>>()) {
if (auto cellBoxHeightCalc = cell.box->style->sizing->height.is<Calc<Length>>()) {
auto computedHeight = resolve(
tree,
*cell.box,
Expand Down
Loading
Loading