aboutsummaryrefslogtreecommitdiffstats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-31 16:57:23 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-31 16:57:48 +0200
commitee94caf0628730135c8bd4b46dc913a50d7ae2b6 (patch)
treed5102d02b605b0f85b91d350876c9c9d676bab83 /src/layout
parent27a39add498a9b1dca790c11a14cc3320cce2e31 (diff)
downloadchawan-ee94caf0628730135c8bd4b46dc913a50d7ae2b6.tar.gz
layout: line box sizing fixes
* do not use inline block computed values for wrapper fragment * fix minimum line box height calculation
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/engine.nim26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index ba9248ca..e81c4c25 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -144,6 +144,9 @@ func applySizeConstraint(u: LayoutUnit; availableSize: SizeConstraint):
of scFitContent:
return min(u, availableSize.u)
+func outerSize(box: BlockBox; dim: DimensionType): LayoutUnit =
+ return box.state.margin.dimSum(dim) + box.state.size[dim]
+
type
BlockContext = object
lctx: LayoutContext
@@ -400,13 +403,12 @@ proc positionAtoms(currentLine: LineBoxState; lctx: LayoutContext): LayoutUnit =
proc shiftAtoms(currentLine: var LineBoxState; marginTop: LayoutUnit;
cellHeight: int) =
- let paddingTop = currentLine.paddingTop
let offsety = currentLine.offsety
+ let shiftTop = marginTop + currentLine.paddingTop
for atom in currentLine.atoms:
- let atomy = atom.offset.y
- atom.offset.y = (atomy + marginTop + paddingTop + offsety).round(cellHeight)
- currentLine.minHeight = max(currentLine.minHeight,
- atomy - offsety + atom.size.h)
+ atom.offset.y = (atom.offset.y + shiftTop + offsety).round(cellHeight)
+ let minHeight = atom.offset.y - offsety + atom.size.h
+ currentLine.minHeight = max(currentLine.minHeight, minHeight)
# Align atoms (inline boxes, text, etc.) vertically (i.e. along the block/y
# axis) inside the line.
@@ -1393,7 +1395,7 @@ proc addInlineBlock(ictx: var InlineContext; state: var InlineState;
innerbox: box,
offset: offset(x = sizes.margin.left, y = 0),
size: size(
- w = box.state.size.w + sizes.margin.dimSum(dtHorizontal),
+ w = box.outerSize(dtHorizontal),
h = box.state.size.h
)
)
@@ -1416,10 +1418,7 @@ func calcLineHeight(computed: CSSComputedValues; lctx: LayoutContext):
proc layoutChildren(ictx: var InlineContext; state: var InlineState;
children: seq[InlineFragment]) =
for child in children:
- case child.computed{"display"}
- of DisplayInline:
- ictx.layoutInline(child)
- of DisplayInlineBlock, DisplayInlineTableWrapper, DisplayInlineFlex:
+ if child.box != nil:
child.state = InlineFragmentState()
var state = InlineState(
fragment: child,
@@ -1428,7 +1427,7 @@ proc layoutChildren(ictx: var InlineContext; state: var InlineState;
let space = availableSpace(w = fitContent(ictx.space.w), h = ictx.space.h)
ictx.addInlineBlock(state, child.box, space)
else:
- assert false
+ ictx.layoutInline(child)
proc layoutInline(ictx: var InlineContext; fragment: InlineFragment) =
let lctx = ictx.lctx
@@ -1531,9 +1530,6 @@ proc positionRelative(parent, box: BlockBox) =
box.state.offset.y += parent.state.size.h - box.state.positioned.bottom -
box.state.size.h
-func outerSize(box: BlockBox; dim: DimensionType): LayoutUnit =
- return box.state.margin.dimSum(dim) + box.state.size[dim]
-
# Note: caption is not included here
const RowGroupBox = {
DisplayTableRowGroup, DisplayTableHeaderGroup, DisplayTableFooterGroup
@@ -2697,7 +2693,7 @@ proc buildFromElem(ctx: var InnerBlockContext; styledNode: StyledNode) =
of DisplayInlineTable: ctx.buildTable(styledNode)
of DisplayInlineFlex: ctx.buildFlex(styledNode)
else: nil
- let wrapper = InlineFragment(computed: childBox.computed, box: childBox)
+ let wrapper = InlineFragment(computed: computed, box: childBox)
ctx.ibox.children.add(wrapper)
ctx.iflush()
of DisplayTable: