diff options
author | bptato <nincsnevem662@gmail.com> | 2023-02-19 17:57:46 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-02-19 17:57:46 +0100 |
commit | d93761efa26ac50db377943ac70b8d93e6061d2c (patch) | |
tree | c00eea5356eaf39d9bacbf2a08a98780dfa013f5 /src/layout | |
parent | 89b63627036cb93737e84beac7ab9c516daf2fb0 (diff) | |
download | chawan-d93761efa26ac50db377943ac70b8d93e6061d2c.tar.gz |
layout/engine: fix double positioning absolute boxes
by checking if the box has been positioned before. Not a very good solution, but it works...
Diffstat (limited to 'src/layout')
-rw-r--r-- | src/layout/box.nim | 3 | ||||
-rw-r--r-- | src/layout/engine.nim | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim index c2b6a449..583e0d75 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -118,6 +118,9 @@ type viewport*: Viewport offset*: Offset + #TODO this should not be needed. + was_positioned*: bool + # This is the padding width/height. width*: int height*: int diff --git a/src/layout/engine.nim b/src/layout/engine.nim index eebc7ef0..02e7398e 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -839,6 +839,12 @@ proc positionBlocks(box: BlockBox) = template defer_out_of_flow() = # Skip absolute, fixed, sticky while i < box.nested.len: + if box.nested[i].was_positioned: # already positioned, ignore. + #TODO: this is actually an ugly hack to avoid absolute boxes being + # positioned twice. A proper fix would be to appropriately place + # them in the tree *before* positioning (i.e. in buildBlock.) + inc i + continue case box.nested[i].computed{"position"} of POSITION_STATIC, POSITION_RELATIVE: break @@ -916,6 +922,7 @@ proc positionBlocks(box: BlockBox) = child.offset.x += child.margin_left if box.computed{"position"} == POSITION_RELATIVE: box.positionRelative(child) + child.was_positioned = true #TODO see above box.height += box.padding_bottom @@ -926,6 +933,7 @@ proc positionBlocks(box: BlockBox) = box.width += box.padding_right for child in deferred: + child.was_positioned = true #TODO see above case child.computed{"position"} of POSITION_ABSOLUTE: positionAbsolute(child) |