diff options
author | bptato <nincsnevem662@gmail.com> | 2025-01-30 20:43:41 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-01-30 20:56:48 +0100 |
commit | 77acb5d5953fb585cd0ce5724ddad3190fbf46b6 (patch) | |
tree | dea3355168b04e9bed60dbbe6ea9d7d3ede4d222 | |
parent | fa8fe9ed2b350a48422fe223a17b6218fe752b32 (diff) | |
download | chawan-77acb5d5953fb585cd0ce5724ddad3190fbf46b6.tar.gz |
layout: fix absolute sizing order with floats
Also removed the redundant pushPositioned/popPositioned calls in popPositioned.
-rw-r--r-- | src/css/layout.nim | 12 | ||||
-rw-r--r-- | test/layout/absolute-size-depends-on-float-sibling.color.expected | 2 | ||||
-rw-r--r-- | test/layout/absolute-size-depends-on-float-sibling.html | 4 |
3 files changed, 15 insertions, 3 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim index 1629e457..0e0edb88 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -1293,7 +1293,6 @@ proc popPositioned(lctx: LayoutContext; size: Size) = let item = lctx.positioned.pop() for it in item.queue: let child = it.child - lctx.pushPositioned() var positioned: RelativeRect var size = size #TODO this is very ugly. @@ -1325,7 +1324,6 @@ proc popPositioned(lctx: LayoutContext; size: Size) = sizes.margin.bottom else: child.state.offset.y += sizes.margin.top - lctx.popPositioned(child.state.size) proc queueAbsolute(lctx: LayoutContext; box: BlockBox; offset: Offset) = case box.computed{"position"} @@ -1557,7 +1555,15 @@ proc layoutFlow(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes; # Reset parentBps to the previous node. bctx.parentBps = fstate.prevParentBps if box.computed{"position"} != PositionStatic: - bctx.lctx.popPositioned(box.state.size) + var size = box.state.size + if bctx.parentBps == nil: + # We have a bit of an ordering problem here: layoutRootBlock + # computes our final height, but we already want to pop the + # positioned box here. + # I'll just replicate what layoutRootBlock is doing until I find a + # better solution... + size.h = max(size.h, bctx.maxFloatHeight) + bctx.lctx.popPositioned(size) proc layoutListItem(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) = diff --git a/test/layout/absolute-size-depends-on-float-sibling.color.expected b/test/layout/absolute-size-depends-on-float-sibling.color.expected new file mode 100644 index 00000000..ace9adb1 --- /dev/null +++ b/test/layout/absolute-size-depends-on-float-sibling.color.expected @@ -0,0 +1,2 @@ +[48;2;255;0;0m [49m test +[48;2;255;0;0m [49m diff --git a/test/layout/absolute-size-depends-on-float-sibling.html b/test/layout/absolute-size-depends-on-float-sibling.html new file mode 100644 index 00000000..cf005c73 --- /dev/null +++ b/test/layout/absolute-size-depends-on-float-sibling.html @@ -0,0 +1,4 @@ +<!DOCTYPE html> +<div style="position: absolute; width: 10ch"> +<div style="float: right; margin-bottom: 1em">test</div> +<div style="position: absolute; background: red; width: 2ch; top: 0; bottom: 0"></div> |