diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-11 00:06:21 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-11 01:37:37 +0100 |
commit | c4b421daf0a516852fc670826dceffb5c0d38ea8 (patch) | |
tree | 7d22ee07ba4a62b0d4b5817d2f294c5540b4c58c /src/layout | |
parent | 3d6767aeca9393238aaaceccac4f292553bb3dc2 (diff) | |
download | chawan-c4b421daf0a516852fc670826dceffb5c0d38ea8.tar.gz |
Add support for margin-left/right: auto
Diffstat (limited to 'src/layout')
-rw-r--r-- | src/layout/engine.nim | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 717ea900..69316406 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -663,9 +663,25 @@ proc positionBlocks(box: BlockBox) = template apply_child(child: BlockBox) = child.offset.y = y - child.offset.x = x + child.margin_left + child.offset.x = x if box.computed{"text-align"} == TEXT_ALIGN_CHA_CENTER: child.offset.x -= child.width div 2 + elif not child.computed{"width"}.auto and child.compwidth < box.compwidth: + let margin_left = child.computed{"margin-left"} + let margin_right = child.computed{"margin-right"} + if margin_left.auto and margin_right.auto: + child.margin_left += box.compwidth div 2 + child.margin_left -= child.compwidth div 2 + child.margin_right += box.compwidth div 2 + child.margin_right -= child.compwidth div 2 + elif margin_left.auto: + child.margin_left += box.compwidth + child.margin_left -= child.compwidth + elif margin_right.auto: + child.margin_right += box.compwidth + child.margin_right -= child.compwidth + child.offset.x += child.margin_left + if box.computed{"position"} == POSITION_RELATIVE: box.positionRelative(child) y += child.height |