aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-16 09:27:45 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-16 09:27:45 +0200
commit191d71795c5a56b0e517fa8b888a06cade77641b (patch)
treef1dafe2fc2fb2555c55ff2a7cc3b3d06b3a3df58 /src
parentaebf28ff0be104f97e5eaf8e61126bed132ad04b (diff)
downloadchawan-191d71795c5a56b0e517fa8b888a06cade77641b.tar.gz
layout: fix list-item positioning
we also have to move the inner box offset to the parent
Diffstat (limited to 'src')
-rw-r--r--src/layout/box.nim7
-rw-r--r--src/layout/engine.nim8
2 files changed, 12 insertions, 3 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index bbb3d91e..79f927ef 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -76,3 +76,10 @@ type
firstBaseline*: LayoutUnit
# baseline of the last line box of all descendants
baseline*: LayoutUnit
+
+func `+`*(a, b: Offset): Offset =
+ return Offset(x: a.x + b.x, y: a.y + b.y)
+
+proc `+=`*(a: var Offset; b: Offset) =
+ a.x += b.x
+ a.y += b.y
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index aea9f2c8..788824da 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -1348,7 +1348,7 @@ proc layoutListItem(bctx: var BlockContext; box: BlockBox;
if builder.marker != nil:
# wrap marker + main box in a new box
let innerBox = BlockBox(
- computed: builder.computed,
+ computed: builder.content.computed,
node: builder.node,
offset: Offset(x: sizes.margin.left),
margin: sizes.margin
@@ -1373,9 +1373,11 @@ proc layoutListItem(bctx: var BlockContext; box: BlockBox;
box.baseline = innerBox.baseline
box.firstBaseline = innerBox.firstBaseline
box.size = innerBox.size
- # innerBox can keep its margin without double margin, it won't be used
- # anymore.
+ # move innerBox margin & offset to outer box
+ box.offset += innerBox.offset
box.margin = innerBox.margin
+ innerBox.offset = Offset()
+ innerBox.margin = RelativeRect()
box.nested = @[marker, innerBox]
else:
bctx.layoutFlow(box, builder.content, sizes)