Skip to content

Commit

Permalink
vaev: Update from upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Dec 22, 2024
1 parent 834f0de commit 5a5b214
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/web/vaev-driver/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ RenderResult render(Markup::Document const &dom, Style::Media const &media, Layo
std::move(stylebook),
makeStrong<Layout::Box>(std::move(tree.root)),
sceneRoot,
makeStrong<Layout::Frag>(root)
makeStrong<Layout::Frag>(std::move(root))
};
}

Expand Down
37 changes: 24 additions & 13 deletions src/web/vaev-layout/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,31 @@ Res<None, Output> processBreakpointsBeforeChild(usize endAt, Vec2Px currentSize,
Output fragmentEmptyBox(Tree &tree, Input input) {
// put this here instead of in layout.py since we want to know if its the empty box case
Vec2Px knownSize{input.knownSize.x.unwrapOr(0_px), input.knownSize.y.unwrapOr(0_px)};
if (tree.fc.acceptsFit(
input.position.y,
knownSize.y,
input.pendingVerticalSizes
)) {
return Output{
.size = knownSize,
.completelyLaidOut = true,
};
if (tree.fc.isDiscoveryMode()) {
if (tree.fc.acceptsFit(
input.position.y,
knownSize.y,
input.pendingVerticalSizes
)) {
return Output{
.size = knownSize,
.completelyLaidOut = true,
};
} else {
return Output{
.size = {},
.completelyLaidOut = false,
.breakpoint = Breakpoint::buildOverflow()
};
}
} else {
// FIXME: we should be breaking empty boxes using pixels or percentages, this behaviour is not compliant
Px verticalSpaceLeft = tree.fc.leftVerticalSpace(
input.position.y, input.pendingVerticalSizes
);
return Output{
.size = {},
.completelyLaidOut = false,
.breakpoint = Breakpoint::buildOverflow()
.size = {knownSize.x, min(knownSize.y, verticalSpaceLeft)},
.completelyLaidOut = verticalSpaceLeft >= knownSize.y,
};
}
}
Expand Down Expand Up @@ -149,7 +160,7 @@ struct BlockFormatingContext {

usize endChildren = stopAt.unwrapOr(box.children().len());

bool blockWasCompletelyLaidOut = box.children().len() == 0;
bool blockWasCompletelyLaidOut = false;

for (usize i = startAt; i < endChildren; ++i) {
auto &c = box.children()[i];
Expand Down
5 changes: 5 additions & 0 deletions src/web/vaev-layout/fragmentainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ struct FragmentationContext {
}

bool acceptsFit(Px verticalPosition, Px verticalSize, Px pendingVerticalSizes) {
// TODO: consider apply this check only when in discovery mode
return verticalPosition + verticalSize + pendingVerticalSizes <= currSize.y;
}

Px leftVerticalSpace(Px verticalPosition, Px pendingVerticalSizes) {
return currSize.y - verticalPosition - pendingVerticalSizes;
}
};

} // namespace Vaev::Layout
20 changes: 14 additions & 6 deletions src/web/vaev-layout/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Output _contentLayout(Tree &tree, Box &box, Input input, usize startAt, Opt<usiz
} else if (auto run = box.content.is<Strong<Text::Prose>>()) {
auto out = inlineLayout(tree, box, input);

if (not tree.fc.acceptsFit(
if (tree.fc.allowBreak() and
not tree.fc.acceptsFit(
input.position.y,
out.size.y,
input.pendingVerticalSizes
Expand Down Expand Up @@ -225,17 +226,18 @@ Output layout(Tree &tree, Box &box, Input input) {
input.position = input.position + borders.topStart() + padding.topStart();
input.pendingVerticalSizes += borders.bottom + padding.bottom;

bool isMonolticDisplay =
box.style->display == Display::Inside::FLEX or
box.style->display == Display::Inside::GRID;

usize startAt = tree.fc.allowBreak() ? input.breakpointTraverser.getStart().unwrapOr(0) : 0;
if (tree.fc.isDiscoveryMode()) {
bool isMonolticDisplay =
box.style->display == Display::Inside::FLEX or
box.style->display == Display::Inside::GRID;

try$(shouldAbortFragmentingBeforeLayout(tree.fc, input));

if (isMonolticDisplay)
tree.fc.enterMonolithicBox();

try$(shouldAbortFragmentingBeforeLayout(tree.fc, input));

// TODO: Class C breakpoint

auto out = _contentLayout(tree, box, input, startAt, NONE);
Expand Down Expand Up @@ -275,6 +277,9 @@ Output layout(Tree &tree, Box &box, Input input) {
Frag currFrag(&box);
input.fragment = input.fragment ? &currFrag : nullptr;

if (isMonolticDisplay)
tree.fc.enterMonolithicBox();

auto out = _contentLayout(tree, box, input, startAt, stopAt);

auto size = out.size;
Expand All @@ -283,6 +288,9 @@ Output layout(Tree &tree, Box &box, Input input) {
size.height = input.knownSize.height.unwrapOr(size.height);
}

if (isMonolticDisplay)
tree.fc.leaveMonolithicBox();

size = size + padding.all() + borders.all();

if (parentFrag) {
Expand Down

0 comments on commit 5a5b214

Please sign in to comment.