-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vaev-layout: Split some headers down.
- Loading branch information
1 parent
02e77c1
commit 0d9ef84
Showing
8 changed files
with
293 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "block.h" | ||
|
||
#include "sizing.h" | ||
|
||
namespace Vaev::Layout { | ||
|
||
void BlockFlow::placeChildren(Context &ctx, Box box) { | ||
Frag::placeChildren(ctx, box); | ||
|
||
Axis mainAxis = Axis::VERTICAL; | ||
|
||
Px res = box.contentBox().start(); | ||
|
||
for (auto &c : _frags) { | ||
auto childcontext = ctx.subContext( | ||
*c, | ||
mainAxis, | ||
box.contentBox() | ||
); | ||
|
||
auto blockSize = computePreferredOuterSize( | ||
childcontext, | ||
mainAxis, | ||
max(Px{0}, box.contentBox().height - res) | ||
); | ||
|
||
auto inlineSize = computePreferredBorderSize( | ||
childcontext, | ||
mainAxis.cross(), | ||
box.contentBox().width | ||
); | ||
|
||
RectPx borderBox = RectPx{ | ||
box.contentBox().start(), | ||
res, | ||
inlineSize, | ||
blockSize, | ||
}; | ||
|
||
auto box = computeBox(childcontext, borderBox); | ||
c->placeChildren(childcontext, box); | ||
|
||
res += blockSize; | ||
} | ||
} | ||
|
||
Px BlockFlow::computeIntrinsicSize(Context &ctx, Axis axis, IntrinsicSize intrinsic, Px) { | ||
Px res = Px{}; | ||
|
||
for (auto &c : _frags) { | ||
auto childCtx = ctx.subContext( | ||
*c, | ||
axis, | ||
Vec2Px::ZERO | ||
); | ||
|
||
if (axis == Axis::VERTICAL) { | ||
auto size = computePreferredOuterSize(childCtx, axis); | ||
if (intrinsic == IntrinsicSize::MAX_CONTENT) { | ||
res += size; | ||
} else { | ||
res = max(res, size); | ||
} | ||
} else { | ||
auto size = computePreferredOuterSize(childCtx, axis); | ||
res = max(res, size); | ||
} | ||
} | ||
|
||
return res; | ||
} | ||
|
||
} // namespace Vaev::Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include "flex.h" | ||
|
||
#include "sizing.h" | ||
|
||
namespace Vaev::Layout { | ||
|
||
void FlexFlow::_clear() { | ||
_items.clear(); | ||
_lines.clear(); | ||
} | ||
|
||
void FlexFlow::_createItems() { | ||
for (usize i = 0; i < _frags.len(); i++) | ||
_items.pushBack({i}); | ||
} | ||
|
||
void FlexFlow::_sortByOrder() { | ||
stableSort(_items, [&](auto a, auto b) { | ||
return styleAt(a.frag).order < styleAt(b.frag).order; | ||
}); | ||
} | ||
|
||
void FlexFlow::placeChildren(Context &ctx, Box box) { | ||
Frag::placeChildren(ctx, box); | ||
|
||
_clear(); | ||
_createItems(); | ||
_sortByOrder(); | ||
|
||
Axis mainAxis = Axis::HORIZONTAL; | ||
|
||
Px res = box.contentBox().start(); | ||
auto blockSize = computePreferredBorderSize( | ||
ctx, | ||
mainAxis.cross(), | ||
box.contentBox().height | ||
); | ||
|
||
for (auto &c : _frags) { | ||
auto childcontext = ctx.subContext( | ||
*c, | ||
mainAxis, | ||
box.contentBox() | ||
); | ||
|
||
auto inlineSize = computePreferredOuterSize( | ||
childcontext, mainAxis, | ||
max(Px{0}, box.contentBox().width - res) | ||
); | ||
|
||
RectPx borderBox = RectPx{ | ||
res, | ||
box.contentBox().top(), | ||
inlineSize, | ||
blockSize, | ||
}; | ||
|
||
auto box = computeBox(childcontext, borderBox); | ||
c->placeChildren(childcontext, box); | ||
|
||
res += inlineSize; | ||
} | ||
} | ||
|
||
Px FlexFlow::computeIntrinsicSize(Context &ctx, Axis axis, IntrinsicSize intrinsic, Px) { | ||
Px res = Px{}; | ||
|
||
for (auto &c : _frags) { | ||
auto childCtx = ctx.subContext( | ||
*c, | ||
axis, | ||
Vec2Px::ZERO | ||
); | ||
|
||
if (axis == Axis::HORIZONTAL) { | ||
auto size = computePreferredOuterSize(childCtx, axis); | ||
if (intrinsic == IntrinsicSize::MAX_CONTENT) { | ||
res += size; | ||
} else { | ||
res = max(res, size); | ||
} | ||
} else { | ||
auto size = computePreferredOuterSize(childCtx, axis); | ||
res = max(res, size); | ||
} | ||
} | ||
|
||
return res; | ||
} | ||
|
||
} // namespace Vaev::Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "flow.h" | ||
|
||
namespace Vaev::Layout { | ||
|
||
void Flow::placeChildren(Context &ctx, Box box) { | ||
Frag::placeChildren(ctx, box); | ||
|
||
for (auto &c : _frags) { | ||
c->placeChildren(ctx, box); | ||
} | ||
} | ||
|
||
void Flow::makePaintables(Paint::Stack &stack) { | ||
Frag::makePaintables(stack); | ||
|
||
for (auto &c : _frags) { | ||
c->makePaintables(stack); | ||
} | ||
} | ||
|
||
void Flow::paintWireframe(Gfx::Context &g) { | ||
for (auto &c : _frags) { | ||
c->paintWireframe(g); | ||
} | ||
|
||
g.strokeStyle({ | ||
.paint = Gfx::BLACK, | ||
.width = 1, | ||
.align = Gfx::INSIDE_ALIGN, | ||
}); | ||
g.stroke(_box.borderBox.cast<f64>()); | ||
} | ||
|
||
void Flow::repr(Io::Emit &e) const { | ||
e("({} {}", type(), _box.borderBox); | ||
if (_frags) { | ||
e.indentNewline(); | ||
for (auto &c : _frags) { | ||
c->repr(e); | ||
e.newline(); | ||
} | ||
e.deindent(); | ||
} | ||
e(")"); | ||
} | ||
|
||
} // namespace Vaev::Layout |
Oops, something went wrong.