diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-11-01 16:20:09 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-11-01 16:20:09 +0100 |
| commit | 775fd9f989a15c5ee7ef2b8e2c41c4f7adbc2ed8 (patch) | |
| tree | e036c96ec636214024d864dc6ee1fdb1ba783d1a /src/layout/renderdocument.nim | |
| parent | 6e1a873be5415a54d77a7202e4a8d1e7211a9f50 (diff) | |
| download | chawan-775fd9f989a15c5ee7ef2b8e2c41c4f7adbc2ed8.tar.gz | |
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
Diffstat (limited to 'src/layout/renderdocument.nim')
| -rw-r--r-- | src/layout/renderdocument.nim | 30 |
1 files changed, 8 insertions, 22 deletions
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 ) |