Skip to content

Commit

Permalink
vaev-layout+paint: Fix some positioned box related issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Sep 30, 2024
1 parent 1112e34 commit a28202a
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 25 deletions.
5 changes: 0 additions & 5 deletions src/vaev-layout/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ struct Input {

struct Output {
Vec2Px size;
InsetsPx margins = {};

static Output fromSize(Vec2Px size) {
return Output{size};
}

static Output fromSizeAndMargin(Vec2Px size, InsetsPx margins) {
return Output{size, margins};
}
};

/// Computed layout values.
Expand Down
25 changes: 17 additions & 8 deletions src/vaev-layout/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,29 @@ Output blockLayout(Tree &t, Frag &f, Input input) {
if (c.style->sizing->width == Size::AUTO)
childInlineSize = inlineSize;

Input childInput = {
.commit = input.commit,
.availableSpace = {inlineSize, Px{0}},
.containingBlock = {inlineSize, Px{0}},
};

auto margin = computeMargins(t, c, childInput);

if (c.style->position != Position::ABSOLUTE) {
blockSize += margin.top;
}

childInput.position = input.position + Vec2Px{Px{0}, blockSize} + margin.topStart();
childInput.knownSize = {childInlineSize, NONE};

auto ouput = layout(
t,
c,
{
.commit = input.commit,
.knownSize = {childInlineSize, NONE},
.position = input.position + Vec2Px{Px{0}, blockSize},
.availableSpace = {inlineSize, Px{0}},
.containingBlock = {inlineSize, Px{0}},
}
childInput
);

if (c.style->position != Position::ABSOLUTE) {
blockSize += ouput.size.y;
blockSize += ouput.size.y + margin.bottom + margin.top;
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/vaev-layout/frag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Output _contentLayout(Tree &t, Frag &f, Input input) {
}
}

static InsetsPx _computeMargins(Tree &t, Frag &f, Input input) {
InsetsPx computeMargins(Tree &t, Frag &f, Input input) {
InsetsPx res;
auto margin = f.style->margin;

Expand Down Expand Up @@ -229,7 +229,6 @@ static Cons<Opt<Px>, IntrinsicSize> _computeSpecifiedSize(Tree &t, Frag &f, Inpu
}

Output layout(Tree &t, Frag &f, Input input) {
auto margin = _computeMargins(t, f, input);
auto borders = _computeBorders(t, f);
auto padding = _computePaddings(t, f, input);
auto sizing = f.style->sizing;
Expand Down Expand Up @@ -257,7 +256,7 @@ Output layout(Tree &t, Frag &f, Input input) {

input.position = input.position + borders.topStart() + padding.topStart();

auto [size, _] = _contentLayout(t, f, input);
auto [size] = _contentLayout(t, f, input);

size.width = input.knownSize.width.unwrapOr(size.width);
size.height = input.knownSize.height.unwrapOr(size.height);
Expand All @@ -269,11 +268,10 @@ Output layout(Tree &t, Frag &f, Input input) {
f.layout.borderSize = size;
f.layout.padding = padding;
f.layout.borders = borders;
f.layout.margin = margin;
f.layout.radii = _computeRadii(t, f, size);
}

return Output::fromSizeAndMargin(size, margin);
return Output::fromSize(size);
}

void wireframe(Frag &frag, Gfx::Canvas &g) {
Expand Down
2 changes: 2 additions & 0 deletions src/vaev-layout/frag.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Frag build(Style::Computer &c, Markup::Document const &doc);

// MARK: Layout ----------------------------------------------------------------

InsetsPx computeMargins(Tree &t, Frag &f, Input input);

Output layout(Tree &t, Frag &f, Input input);

Px measure(Tree &t, Frag &f, Axis axis, IntrinsicSize intrinsic, Px availableSpace);
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-paint/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Node {
virtual void print(Print::Printer &) {}

virtual void repr(Io::Emit &e) const {
e("(node)");
e("(node z:{})", zIndex);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/vaev-paint/borders.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct Borders : public Node {
}

void repr(Io::Emit &e) const override {
e("(borders {} {} {}", bound, radii, collapse);
e("(borders z:{} {} {} {}", zIndex, bound, radii, collapse);
}

void paint(Gfx::Canvas &ctx) override {
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-paint/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Box : public Node {
}

void repr(Io::Emit &e) const override {
e("(box {} {} {})", bound, radii, backgrounds);
e("(box z:{} {} {} {})", zIndex, bound, radii, backgrounds);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/vaev-paint/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Vaev::Paint {

struct Image : public Node {
void repr(Io::Emit &e) const override {
e("(image)");
e("(image z:{})", zIndex);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/vaev-paint/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Stack : public Node {

void prepare() override {
stableSort(_children, [](auto &a, auto &b) {
return a->zIndex < b->zIndex;
return a->zIndex <=> b->zIndex;
});

for (auto &child : _children)
Expand All @@ -38,7 +38,7 @@ struct Stack : public Node {
}

void repr(Io::Emit &e) const override {
e("(stack");
e("(stack z:{}", zIndex);
if (_children) {
e.indentNewline();
for (auto &child : _children) {
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-paint/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Text : public Node {
}

void repr(Io::Emit &e) const override {
e("(text {})", baseline);
e("(text z:{} {})", zIndex, baseline);
}
};

Expand Down

0 comments on commit a28202a

Please sign in to comment.