diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-04-06 19:52:57 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-04-06 20:07:21 +0200 |
| commit | 27fb1388b0644da1e733b07042e0cf30eea8d7b9 (patch) | |
| tree | 9ff40bf2a4c124e5133d074667afc3bfc2d9be32 /src | |
| parent | 55da4b6f458f5b80ad242bf6088a119bb05531c1 (diff) | |
| download | chawan-27fb1388b0644da1e733b07042e0cf30eea8d7b9.tar.gz | |
layout: fix cleared floats not flushing previous exclusions
Well, I was trying to reproduce *another* float bug when I accidentally
stumbled upon this...
The fix is somewhat ugly, but not as bad as I expected.
Diffstat (limited to 'src')
| -rw-r--r-- | src/css/layout.nim | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim index ac64f6be..e2b04e6d 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -693,6 +693,8 @@ type # * flush margins and position floats # * check the relevant exclusions and resize the line appropriately init: LineInitState + # float values currently included in unpositionedFloats. + floatsSeen: set[CSSFloat] InlineAtomState = object vertalign: CSSVerticalAlign @@ -1570,6 +1572,13 @@ proc positionRelative(lctx: LayoutContext; space: AvailableSpace; elif box.computed{"bottom"}.canpx(space.h): box.state.offset.y -= box.computed{"bottom"}.px(space.h) +func clearedBy(floats: set[CSSFloat]; clear: CSSClear): bool = + return case clear + of ClearNone: false + of ClearBoth: floats != {} + of ClearInlineStart, ClearLeft: FloatLeft in floats + of ClearInlineEnd, ClearRight: FloatRight in floats + proc layoutFloat(fstate: var FlowState; child: BlockBox) = let lctx = fstate.lctx let sizes = lctx.resolveFloatSizes(fstate.space, child.computed) @@ -1589,17 +1598,19 @@ proc layoutFloat(fstate: var FlowState; child: BlockBox) = fstate.maxChildWidth = max(fstate.maxChildWidth, outerSize.w) fstate.initLine(flag = ilfFloat) var newLine = true - if fstate.lbstate.size.w + outerSize.w <= - fstate.lbstate.availableWidth and + let float = child.computed{"float"} + if not fstate.lbstate.floatsSeen.clearedBy(child.computed{"clear"}) and + fstate.lbstate.size.w + outerSize.w <= fstate.lbstate.availableWidth and (fstate.lbstate.unpositionedFloats.len == 0 or not fstate.lbstate.unpositionedFloats[^1].newLine): # We can still cram floats into the line. - if child.computed{"float"} == FloatLeft: + if float == FloatLeft: fstate.lbstate.size.w += outerSize.w for iastate in fstate.lbstate.iastates.mitems: iastate.offset.x += outerSize.w else: fstate.lbstate.availableWidth -= outerSize.w + fstate.lbstate.floatsSeen.incl(float) newLine = false fstate.lbstate.unpositionedFloats.add(UnpositionedFloat( space: fstate.space, |