Skip to content

Commit 9030075

Browse files
committed
vaev-layout: Refact builder reflecting block/inline outside-display behaviour and better inline handling.
1 parent ba23a85 commit 9030075

File tree

9 files changed

+858
-76
lines changed

9 files changed

+858
-76
lines changed

src/libs/karm-text/prose.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,28 @@ void Prose::clear() {
4646
_cells.clear();
4747
_blocks.clear();
4848
_blocksMeasured = false;
49-
_beginBlock();
5049
_lines.clear();
50+
51+
_beginBlock();
52+
}
53+
54+
void Prose::copySpanStack(Prose const& prose) {
55+
Vec<Box<Text::Prose::Span>> spans;
56+
auto currSpan = prose._currentSpan;
57+
while (currSpan) {
58+
spans.pushBack(*currSpan);
59+
currSpan = currSpan->parent;
60+
}
61+
62+
reverse(mutSub(spans));
63+
_spans = std::move(spans);
64+
65+
for (usize i = 0; i + 1 < _spans.len(); ++i) {
66+
_spans[i + 1]->parent = &*_spans[i];
67+
}
68+
69+
if (_spans.len())
70+
_currentSpan = &*last(_spans);
5171
}
5272

5373
void Prose::append(Slice<Rune> runes) {

src/libs/karm-text/prose.h

+4
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ struct Prose : public Meta::Pinned {
189189

190190
void pushSpan() {
191191
_spans.pushBack(makeBox<Span>(_currentSpan));
192+
auto parentSpan = _currentSpan;
192193
_currentSpan = &*last(_spans);
194+
_currentSpan->parent = parentSpan;
193195
}
194196

195197
void spanColor(Gfx::Color color) {
@@ -204,6 +206,8 @@ struct Prose : public Meta::Pinned {
204206
_currentSpan = _currentSpan->parent;
205207
}
206208

209+
void copySpanStack(Prose const& prose);
210+
207211
// MARK: Layout ------------------------------------------------------------
208212

209213
void _measureBlocks();

src/web/vaev-layout/base.cpp

+42-1
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,51 @@ export struct BreakpointTraverser {
232232
export struct FormatingContext;
233233
export struct Box;
234234

235+
export struct InlineBox {
236+
/* NOTE:
237+
This is a sketch implementation of the data model for InlineBox. We should be able to:
238+
- add different inline elements to it, from different types (Prose, Image, inline-block)
239+
- retrieve the added data to be displayed in the same Inline Formatting Context (break lines and display
240+
into line boxes)
241+
- respect different styling for the same line (font, fontsize, color, etc)
242+
*/
243+
Text::ProseStyle const _style;
244+
Rc<Text::Prose> prose;
245+
246+
InlineBox(Text::ProseStyle style) : _style(style), prose(makeRc<Text::Prose>(_style)) {}
247+
248+
InlineBox(Rc<Text::Prose> prose) : _style(prose->_style), prose(prose) {}
249+
250+
void startInlineBox(Text::ProseStyle proseStyle) {
251+
// FIXME: ugly workaround while we dont fix the Prose data structure
252+
prose->pushSpan();
253+
if (proseStyle.color)
254+
prose->spanColor(proseStyle.color.unwrap());
255+
}
256+
257+
void endInlineBox() {
258+
prose->popSpan();
259+
}
260+
261+
void add(Box&&) {}
262+
263+
bool active() {
264+
return prose->_runes.len();
265+
}
266+
267+
void clear() {
268+
auto oldProse = prose;
269+
270+
prose = makeRc<Text::Prose>(_style);
271+
272+
prose->copySpanStack(*oldProse);
273+
}
274+
};
275+
235276
export using Content = Union<
236277
None,
237278
Vec<Box>,
238-
Rc<Text::Prose>,
279+
InlineBox,
239280
Karm::Image::Picture>;
240281

241282
export struct Attrs {

0 commit comments

Comments
 (0)