Skip to content

Commit ceb3fb2

Browse files
committed
wip
1 parent 5fb926d commit ceb3fb2

27 files changed

+277
-282
lines changed

src/vaev-engine/layout/flex.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,21 @@ struct FlexItem {
240240
// https://www.w3.org/TR/css-flexbox-1/#valdef-flex-basis-auto
241241
void computeFlexBaseSize(Tree& tree, Opt<Au> mainContainerSize, IntrinsicSize containerSizing) {
242242
// A NONE return here indicates a CONTENT case for the flex basis
243-
auto getDefiniteFlexBasisSize = [](FlexProps& flexItemProps, FlexAxis& fa, Box* box) -> Opt<CalcValue<PercentOr<Length>>> {
243+
auto getDefiniteFlexBasisSize = [](FlexProps& flexItemProps, FlexAxis& fa, Box* box) -> Opt<Calc<Length>> {
244244
if (flexItemProps.basis.is<Keywords::Content>())
245245
return NONE;
246246

247247
// from now on flex basis is width
248248

249-
if (auto basisCalc = flexItemProps.basis.is<CalcValue<PercentOr<Length>>>())
249+
if (auto basisCalc = flexItemProps.basis.is<Calc<Length>>())
250250
return *basisCalc;
251251

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

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

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

260260
if (auto flexBasisDefiniteSize = getDefiniteFlexBasisSize(flexItemProps, fa, box)) {
@@ -300,7 +300,7 @@ struct FlexItem {
300300
Au getMinAutoPrefMainSize(Tree& tree, Vec2Au containerSize) const {
301301
Opt<Au> definiteMaxMainSize;
302302
auto maxMainSize = box->style->sizing->maxSize(fa.isRowOriented ? Axis::HORIZONTAL : Axis::VERTICAL);
303-
if (auto maxMainSizeCalc = maxMainSize.is<CalcValue<PercentOr<Length>>>()) {
303+
if (auto maxMainSizeCalc = maxMainSize.is<Calc<Length>>()) {
304304
definiteMaxMainSize = resolve(
305305
tree,
306306
*box,
@@ -315,7 +315,7 @@ struct FlexItem {
315315
contentSizeSuggestion = min(contentSizeSuggestion, definiteMaxMainSize.unwrap());
316316

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

340340
auto visitor = Visitor{
341-
[&](CalcValue<PercentOr<Length>> const& v) {
341+
[&](Calc<Length> const& v) {
342342
return resolve(
343343
tree,
344344
*box,
@@ -380,7 +380,7 @@ struct FlexItem {
380380
Au contentContribution = fa.mainAxis(isMin ? minContentSize : maxContentSize) + getMargin(BOTH_MAIN);
381381

382382
auto mainAxis = fa.mainAxis(box->style->sizing);
383-
if (auto mainAxisCalc = mainAxis.is<CalcValue<PercentOr<Length>>>()) {
383+
if (auto mainAxisCalc = mainAxis.is<Calc<Length>>()) {
384384
contentContribution = max(
385385
contentContribution,
386386
resolve(
@@ -425,7 +425,7 @@ struct FlexItem {
425425
);
426426

427427
auto crossAxis = fa.crossAxis(box->style->sizing);
428-
if (auto crossAxisCalc = crossAxis.is<CalcValue<PercentOr<Length>>>()) {
428+
if (auto crossAxisCalc = crossAxis.is<Calc<Length>>()) {
429429
contentContribution = max(
430430
contentContribution,
431431
resolve(
@@ -702,11 +702,11 @@ struct FlexFormatingContext : FormatingContext {
702702

703703
void _determineFlexBaseSizeAndHypotheticalMainSize(Tree& tree, Box& box, Input input) {
704704
Opt<Au> containerDefiniteMainSize = fa.mainAxis(input.knownSize);
705-
if (fa.mainAxis(box.style->sizing).is<CalcValue<PercentOr<Length>>>()) {
705+
if (fa.mainAxis(box.style->sizing).is<Calc<Length>>()) {
706706
containerDefiniteMainSize = resolve(
707707
tree,
708708
box,
709-
fa.mainAxis(box.style->sizing).unwrap<CalcValue<PercentOr<Length>>>(),
709+
fa.mainAxis(box.style->sizing).unwrap<Calc<Length>>(),
710710
fa.mainAxis(input.containingBlock)
711711
);
712712
}

src/vaev-engine/layout/layout-impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Opt<Au> computeSpecifiedSize(Tree& tree, Box& box, Size size, Vec2Au containingB
174174
return clamp(stretchIntrinsicSize.y, minIntrinsicSize.y, maxIntrinsicSize.y);
175175
} else if (size.is<Keywords::Auto>()) {
176176
return NONE;
177-
} else if (auto calc = size.is<CalcValue<PercentOr<Length>>>()) {
177+
} else if (auto calc = size.is<Calc<Length>>()) {
178178
return resolve(tree, box, *calc, isWidth ? containingBlock.x : containingBlock.y);
179179
} else {
180180
logWarn("unknown specified size: {}", size);

src/vaev-engine/layout/paint.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void _paintChildren(Frag& frag, Scene::Stack& stack, auto predicate) {
240240
}
241241
}
242242

243-
static Math::Radiif _resolveRadii(Resolver& resolver, Math::Radii<CalcValue<PercentOr<Length>>> const& baseRadii, RectAu const& referenceBox) {
243+
static Math::Radiif _resolveRadii(Resolver& resolver, Math::Radii<Calc<Length>> const& baseRadii, RectAu const& referenceBox) {
244244
Math::Radiif radii;
245245
radii.a = resolver.resolve(baseRadii.a, referenceBox.height).cast<f64>();
246246
radii.b = resolver.resolve(baseRadii.b, referenceBox.width).cast<f64>();
@@ -356,7 +356,7 @@ static Rc<Scene::Clip> _applyClip(Frag const& frag, Rc<Scene::Node> content) {
356356
auto hSquared = Math::pow2(referenceBox.height.cast<f64>());
357357
auto wSquared = Math::pow2(referenceBox.width.cast<f64>());
358358
radius = resolver.resolve(
359-
circle.radius.unwrap<CalcValue<PercentOr<Length>>>(),
359+
circle.radius.unwrap<Calc<Length>>(),
360360
Au(Math::sqrt(hSquared + wSquared) / Math::sqrt(2.0))
361361
)
362362
.cast<f64>();
@@ -420,7 +420,7 @@ static Rc<Scene::Clip> _applyClip(Frag const& frag, Rc<Scene::Node> content) {
420420
rx = max(Math::abs(referenceBox.width.cast<f64>() - center.x), center.x);
421421
} else {
422422
rx = resolver.resolve(
423-
ellipse.rx.unwrap<CalcValue<PercentOr<Length>>>(),
423+
ellipse.rx.unwrap<Calc<Length>>(),
424424
referenceBox.width
425425
)
426426
.cast<f64>();
@@ -433,7 +433,7 @@ static Rc<Scene::Clip> _applyClip(Frag const& frag, Rc<Scene::Node> content) {
433433
ry = max(Math::abs(referenceBox.height.cast<f64>() - center.y), center.y);
434434
} else {
435435
ry = resolver.resolve(
436-
ellipse.ry.unwrap<CalcValue<PercentOr<Length>>>(),
436+
ellipse.ry.unwrap<Calc<Length>>(),
437437
referenceBox.height
438438
)
439439
.cast<f64>();
@@ -516,7 +516,7 @@ static Vec2Au _resolveTransformOrigin(RectAu referenceBox, TransformOrigin origi
516516
[&](Keywords::Center) {
517517
return referenceBox.center().x;
518518
},
519-
[&](CalcValue<PercentOr<Length>> value) {
519+
[&](Calc<Length> value) {
520520
return referenceBox.start() + resolver.resolve(value, referenceBox.width);
521521
}
522522
}
@@ -533,7 +533,7 @@ static Vec2Au _resolveTransformOrigin(RectAu referenceBox, TransformOrigin origi
533533
[&](Keywords::Center) {
534534
return referenceBox.center().y;
535535
},
536-
[&](CalcValue<PercentOr<Length>> value) {
536+
[&](Calc<Length> value) {
537537
return referenceBox.top() + resolver.resolve(value, referenceBox.height);
538538
}
539539
}

src/vaev-engine/layout/positioned.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ export void layoutPositioned(Tree& tree, Frag& frag, RectAu containingBlock) {
3232
auto start = metrics.position.x;
3333

3434
auto topOffset = style.offsets->top;
35-
if (auto topOffsetCalc = topOffset.is<CalcValue<PercentOr<Length>>>()) {
35+
if (auto topOffsetCalc = topOffset.is<Calc<Length>>()) {
3636
top = origin.y + resolve(tree, *frag.box, *topOffsetCalc, relativeTo.height);
3737
}
3838

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

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

src/vaev-engine/layout/svg.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ using namespace Karm;
1414
namespace Vaev::Layout {
1515

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

35-
return extractValueFromCalc(size.unwrap<CalcValue<PercentOr<Length>>>())
35+
return extractValueFromCalc(size.unwrap<Calc<Length>>())
3636
.unwrapOr(PercentOr<Length>{Percent{100}});
3737
}
3838

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

161-
Circle<PercentOr<Length>> buildCircle(Style::SpecifiedValues const& style) {
161+
Circle<Calc<Length>> buildCircle(Style::SpecifiedValues const& style) {
162162
return {
163163
style.svg->cx,
164164
style.svg->cy,
165165
style.svg->r,
166166
};
167167
}
168168

169-
Circle<Au> resolve(Circle<PercentOr<Length>> const& circle, Karm::Vec2Au const& relativeTo) {
169+
Circle<Au> resolve(Circle<Calc<Length>> const& circle, Karm::Vec2Au const& relativeTo) {
170170
return {
171171
Vaev::Layout::resolve(circle.cx, relativeTo.x),
172172
Vaev::Layout::resolve(circle.cy, relativeTo.y),
@@ -385,10 +385,10 @@ Opt<Number> intrinsicAspectRatio(Opt<ViewBox> const& vb, Size const& width, Size
385385
// FIXME: again this should be targetted by the styling computation refactoring,
386386
// where Size will be resolved to a mix between Percent and Lengths
387387
auto absoluteValue = [](Size size) -> Opt<Length> {
388-
if (not size.is<CalcValue<PercentOr<Length>>>())
388+
if (not size.is<Calc<Length>>())
389389
return NONE;
390390

391-
auto calc = size.unwrap<CalcValue<PercentOr<Length>>>();
391+
auto calc = size.unwrap<Calc<Length>>();
392392

393393
auto percOrLength = extractValueFromCalc(calc);
394394
if (not percOrLength)

src/vaev-engine/layout/table.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,13 @@ struct TableFormatingContext : FormatingContext {
446446
// NOTE: The table does not automatically expand to fill its containing block.
447447
// (https://www.w3.org/TR/CSS22/tables.html#width-layout)
448448

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

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

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

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

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

471-
if (auto widthCalc = width.is<CalcValue<PercentOr<Length>>>()) {
471+
if (auto widthCalc = width.is<Calc<Length>>()) {
472472
for (usize x = col.start; x <= col.end; ++x) {
473473
colWidthOrNone[x] = resolve(tree, col.el, *widthCalc, tableUsedWidth);
474474
}
@@ -482,7 +482,7 @@ struct TableFormatingContext : FormatingContext {
482482
while (x < grid.size.x) {
483483
auto cell = grid.get(x, 0);
484484

485-
auto cellBoxWidthCalc = cell.box->style->sizing->width.is<CalcValue<PercentOr<Length>>>();
485+
auto cellBoxWidthCalc = cell.box->style->sizing->width.is<Calc<Length>>();
486486

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

560-
if (not(cell.box->style->sizing->width.is<Keywords::Auto>() or cell.box->style->sizing->width.is<CalcValue<PercentOr<Length>>>()))
560+
if (not(cell.box->style->sizing->width.is<Keywords::Auto>() or cell.box->style->sizing->width.is<Calc<Length>>()))
561561
logWarn("width can't be anything other than 'auto' or a length in a table context");
562562

563-
if (auto cellBoxWidthCalc = cell.box->style->sizing->width.is<CalcValue<PercentOr<Length>>>()) {
563+
if (auto cellBoxWidthCalc = cell.box->style->sizing->width.is<Calc<Length>>()) {
564564
auto cellPreferredWidth = resolve(
565565
tree,
566566
box,
@@ -640,7 +640,7 @@ struct TableFormatingContext : FormatingContext {
640640
for (auto& group : colGroups) {
641641

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

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

673673
if (not(width.is<Keywords::Auto>() or widthCalc))
674674
logWarn("width can't be anything other than 'auto' or a length in a table context");
@@ -713,7 +713,7 @@ struct TableFormatingContext : FormatingContext {
713713
// https://www.w3.org/TR/css-tables-3/#intrinsic-percentage-width-of-a-column-based-on-cells-of-span-up-to-1
714714
// We will need a way to retrieve the percentage value, which is also not yet implemented.
715715

716-
if (auto boxWidthCalc = box.style->sizing->width.is<CalcValue<PercentOr<Length>>>()) {
716+
if (auto boxWidthCalc = box.style->sizing->width.is<Calc<Length>>()) {
717717
auto [minWithoutPerc, maxWithoutPerc] = computeMinMaxAutoWidths(tree, grid.size.x, 0_au);
718718

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

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

796796
if (not(height.is<Keywords::Auto>() or heightCalc))
797797
logWarn("height can't be anything other than 'auto' or a length in a table context");
@@ -815,11 +815,11 @@ struct TableFormatingContext : FormatingContext {
815815
// [A] CSS 2.2 does not specify how cells that span more than one row affect row height calculations except
816816
// that the sum of the row heights involved must be great enough to encompass the cell spanning the rows.
817817

818-
if (not(cell.box->style->sizing->height.is<Keywords::Auto>() or cell.box->style->sizing->height.is<CalcValue<PercentOr<Length>>>()))
818+
if (not(cell.box->style->sizing->height.is<Keywords::Auto>() or cell.box->style->sizing->height.is<Calc<Length>>()))
819819
logWarn("height can't be anything other than 'auto' or a length in a table context");
820820

821821
auto rowSpan = cell.box->attrs.rowSpan;
822-
if (auto cellBoxHeightCalc = cell.box->style->sizing->height.is<CalcValue<PercentOr<Length>>>()) {
822+
if (auto cellBoxHeightCalc = cell.box->style->sizing->height.is<Calc<Length>>()) {
823823
auto computedHeight = resolve(
824824
tree,
825825
*cell.box,

0 commit comments

Comments
 (0)