aboutsummaryrefslogtreecommitdiffstats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-27 17:17:48 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-27 17:17:48 +0200
commitd8679af92bf88896a033238a1b0bea0648632b4c (patch)
tree90679172a6138b2081a9d6e6f62fe2d2670604fb /src/layout
parentdfc0b6c73f263876c10e56aee18e8ecabd1465c3 (diff)
downloadchawan-d8679af92bf88896a033238a1b0bea0648632b4c.tar.gz
layout: fix float size in table cells; remove redundant positioning
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/engine.nim21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index e5093084..3c831afd 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -1427,7 +1427,7 @@ proc addInlineBlock(ictx: var InlineContext; state: var InlineState;
bctx.layoutFlex(box, builder, sizes)
else:
assert false, $builder.computed{"display"}
- bctx.positionFloats()
+ assert bctx.unpositionedFloats.len == 0
bctx.marginTodo.append(sizes.margin.bottom)
let marginTop = box.offset.y
let marginBottom = bctx.marginTodo.sum()
@@ -1522,9 +1522,6 @@ proc layoutInline(ictx: var InlineContext; box: InlineBoxBuilder):
ictx.currentLine.size.w += paddingRight
let marginRight = box.computed{"margin-right"}.px(lctx, ictx.space.w)
ictx.currentLine.size.w += marginRight
- #TODO we verticalAlignLine here to know line height, but this is incredibly
- # ugly. Maybe figure out some incremental line alignment scheme instead?
- ictx.verticalAlignLine()
if state.firstLine:
fragment.startOffset = Offset(
x: state.startOffsetTop.x,
@@ -1665,10 +1662,14 @@ proc buildTableCell(lctx: LayoutState; builder: TableCellBoxBuilder;
node: builder.node,
margin: sizes.margin
)
- var ctx = BlockContext(lctx: lctx)
- ctx.layoutFlow(box, builder, sizes)
+ var bctx = BlockContext(lctx: lctx)
+ bctx.layoutFlow(box, builder, sizes)
+ assert bctx.unpositionedFloats.len == 0
# Table cells ignore margins.
box.offset.y = 0
+ # If the highest float edge is higher than the box itself, set that as
+ # the box height.
+ box.size.h = max(box.size.h, bctx.maxFloatHeight)
return box
# Sort growing cells, and filter out cells that have grown to their intended
@@ -2035,6 +2036,7 @@ proc addTableCaption(ctx: TableContext; table: BlockBox) =
)
var bctx = BlockContext(lctx: ctx.lctx)
bctx.layoutFlow(box, builder, sizes)
+ assert bctx.unpositionedFloats.len == 0
let outerHeight = box.offset.y + box.size.h + bctx.marginTodo.sum()
table.size.h += outerHeight
table.size.w = max(table.size.w, box.size.w)
@@ -2111,6 +2113,11 @@ proc layoutFlexChild(lctx: LayoutState; builder: BoxBuilder;
margin: sizes.margin
)
bctx.layout(box, builder, sizes)
+ assert bctx.unpositionedFloats.len == 0
+ # If the highest float edge is higher than the box itself, set that as
+ # the box height.
+ if bctx.maxFloatHeight > box.offset.y + box.size.h:
+ box.size.h = bctx.maxFloatHeight - box.offset.y
return box
type
@@ -2393,7 +2400,7 @@ proc layoutRootBlock(lctx: LayoutState; builder: BoxBuilder;
BlockBox =
var bctx = BlockContext(lctx: lctx)
let box = bctx.layoutBlockChild(builder, space, offset, appendMargins = false)
- bctx.positionFloats()
+ assert bctx.unpositionedFloats.len == 0
marginBottomOut = bctx.marginTodo.sum()
# If the highest float edge is higher than the box itself, set that as
# the box height.