From 775fd9f989a15c5ee7ef2b8e2c41c4f7adbc2ed8 Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 1 Nov 2024 16:20:09 +0100 Subject: layout: simplify a bit, fix some inline float bugs * simplify "positioned" value calculation: - don't include it in ResolvedSizes, since it's unused in most layouts - resolvePositioned for both absolute and relative positioning - use "size" instead of "space" for absolute positioning - include parent width in layout so that renderdocument does not have to account for it * return bottom margins as regular return values instead of var * fix child bottom margins being discarded in inline floats * fix inline float not including the parent block position in its BFC position --- src/layout/renderdocument.nim | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/layout/renderdocument.nim') diff --git a/src/layout/renderdocument.nim b/src/layout/renderdocument.nim index ad0ea739..74f7fafc 100644 --- a/src/layout/renderdocument.nim +++ b/src/layout/renderdocument.nim @@ -233,14 +233,10 @@ type height*: int bmp*: NetworkBitmap - AbsolutePos = object - offset: Offset - size: Size - RenderState = object # Position of the absolute positioning containing block: # https://drafts.csswg.org/css-position/#absolute-positioning-containing-block - absolutePos: seq[AbsolutePos] + absolutePos: seq[Offset] bgcolor: CellColor attrsp: ptr WindowAttributes images: seq[PosBitmap] @@ -339,10 +335,7 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState; bgcolor0.rgb.cellColor()) if fragment.computed{"position"} != PositionStatic: if stSplitStart in fragment.splitType: - state.absolutePos.add(AbsolutePos( - offset: offset + fragment.state.startOffset, - # looks like it's OK to set size to 0 here - )) + state.absolutePos.add(offset + fragment.state.startOffset) if fragment.t == iftParent: for child in fragment.children: grid.renderInlineFragment(state, child, offset, bgcolor0) @@ -386,20 +379,13 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState; discard state.absolutePos.pop() continue if box.computed{"position"} in {PositionAbsolute, PositionFixed}: - if not box.computed{"left"}.auto: - offset.x = state.absolutePos[^1].offset.x - elif not box.computed{"right"}.auto: - offset.x = state.absolutePos[^1].offset.x + state.absolutePos[^1].size.w - if not box.computed{"top"}.auto: - offset.y = state.absolutePos[^1].offset.y - elif not box.computed{"bottom"}.auto: - offset.y = state.absolutePos[^1].offset.y + state.absolutePos[^1].size.h + if not box.computed{"left"}.auto or not box.computed{"right"}.auto: + offset.x = state.absolutePos[^1].x + if not box.computed{"top"}.auto or not box.computed{"bottom"}.auto: + offset.y = state.absolutePos[^1].y offset += box.state.offset if box.computed{"position"} != PositionStatic: - state.absolutePos.add(AbsolutePos( - offset: offset, - size: box.state.size - )) + state.absolutePos.add(offset) stack.add((nil, offset(-1, -1))) if box.computed{"visibility"} == VisibilityVisible: #TODO maybe blend with the terminal background? @@ -446,7 +432,7 @@ proc renderDocument*(grid: var FlexibleGrid; bgcolor: var CellColor; # no HTML element when we run cascade; just clear all lines. return var state = RenderState( - absolutePos: @[AbsolutePos()], + absolutePos: @[offset(0, 0)], attrsp: attrsp, bgcolor: defaultColor ) -- cgit