From e066acad98c510cfd9bd2593affcbb9673c93dca Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 6 Jan 2025 16:31:10 +0100 Subject: layout: wrap on inline floats that exceed the line's length In this case, it seems we have to wrap. (It's still not quite there; replace flow-root with inline-box to see another interesting bug...) --- src/css/layout.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/css/layout.nim b/src/css/layout.nim index 2cbf5190..6fea80e3 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -1414,9 +1414,6 @@ proc layoutInline(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) = # rarely enough. let floats = move(ictx.unpositionedFloats) var space = sizes.space - #TODO there is still a bug here: if the parent's size is - # fit-content, then floats should trigger a re-layout in the - # *parent*. if space.w.t != scStretch: space.w = stretch(ictx.state.size.w) ictx = bctx.initInlineContext(space, bfcOffset, sizes.padding, box.computed) @@ -1493,12 +1490,15 @@ proc addInlineFloat(ictx: var InlineContext; state: var InlineState; box: BlockBox) = let lctx = ictx.lctx let sizes = lctx.resolveFloatSizes(ictx.space, box.computed) - box.state = BoxLayoutState() let offset = offset( x = sizes.margin.left, y = ictx.lbstate.offsety + sizes.margin.top ) lctx.layoutRootBlock(box, offset, sizes) + if ictx.space.w.t == scStretch and + ictx.lbstate.size.w + box.state.size.w > ictx.space.w.u: + ictx.finishLine(state, wrap = true) + box.state.offset.y = ictx.lbstate.offsety + sizes.margin.top ictx.lbstate.size.w += box.state.size.w # Note that by now, the top y offset is always resolved. ictx.unpositionedFloats.add(InlineUnpositionedFloat( -- cgit 1.4.1-2-gfad0