diff options
author | bptato <nincsnevem662@gmail.com> | 2022-05-29 16:11:32 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-05-29 16:11:32 +0200 |
commit | 616e60b76ccd91ee190114cba3cd2faa4f882448 (patch) | |
tree | 5694fcb10b99ad73299a0bd68c6b7a720143540d | |
parent | c5e57f02c9fe8e35f9bbc09525e268c33f6a3f33 (diff) | |
download | chawan-616e60b76ccd91ee190114cba3cd2faa4f882448.tar.gz |
Layout: insignificant changes regarding offset
-rw-r--r-- | src/layout/box.nim | 27 | ||||
-rw-r--r-- | src/layout/engine.nim | 11 | ||||
-rw-r--r-- | src/render/renderdocument.nim | 4 |
3 files changed, 35 insertions, 7 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim index 9ff94f53..b22a388a 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -5,6 +5,20 @@ import html/dom import io/term type + OffsetType* = enum + OFFSET_BLOCK_CONTEXT + +type + Position = object + x*: int + y*: int + + Offset* = ref object + case t*: OffsetType + of OFFSET_BLOCK_CONTEXT: + rel*: Position + prev_sibling*: Offset + Viewport* = ref object term*: TermAttributes root*: BlockBoxBuilder @@ -79,8 +93,7 @@ type nested*: seq[BlockContext] specified*: CSSComputedValues viewport*: Viewport - relx*: int - rely*: int + offset*: Offset width*: int height*: int margin_top*: int @@ -102,3 +115,13 @@ type # outside*: bool #ListItemBox* = ref object of BlockBox + +func absx*(offset: Offset): int {.inline.} = + offset.rel.x + +#TODO cache +func absy*(offset: Offset): int {.inline.} = + if offset.prev_sibling != nil: + offset.prev_sibling.absy + offset.rel.y + else: + offset.rel.y diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 3ca1c114..2144ac84 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -316,6 +316,9 @@ proc newBlockContext_common(parent: BlockContext, box: BoxBuilder): BlockContext proc newBlockContext(parent: BlockContext, box: BlockBoxBuilder): BlockContext = result = newBlockContext_common(parent, box) + result.offset = Offset(t: OFFSET_BLOCK_CONTEXT) + if parent.nested.len > 0: + result.offset.prev_sibling = parent.nested[^1].offset result.shrink = result.specified{"width"}.auto and parent.shrink proc newInlineBlockContext(parent: BlockContext, box: InlineBlockBoxBuilder): BlockContext = @@ -331,6 +334,7 @@ proc newBlockContext(parent: BlockContext): BlockContext = new(result) result.specified = parent.specified.inheritProperties() result.viewport = parent.viewport + result.offset = Offset(t: OFFSET_BLOCK_CONTEXT) result.computedDimensions(parent.compwidth, parent.compheight) result.shrink = result.specified{"width"}.auto and parent.shrink @@ -339,6 +343,7 @@ proc newBlockContext(viewport: Viewport): BlockContext = new(result) result.specified = rootProperties() result.viewport = viewport + result.offset = Offset(t: OFFSET_BLOCK_CONTEXT) result.computedDimensions(viewport.term.width_px, none(int)) proc newInlineContext(bctx: BlockContext): InlineContext = @@ -363,10 +368,10 @@ proc positionBlocks(bctx: BlockContext, selfcontained: bool) = x += bctx.compwidth div 2 template apply_child(child: BlockContext) = - child.rely = y - child.relx = x + child.margin_left + child.offset.rel.y = y + child.offset.rel.x = x + child.margin_left if bctx.specified{"text-align"} == TEXT_ALIGN_MOZ_CENTER: - child.relx -= child.width div 2 + child.offset.rel.x -= child.width div 2 y += child.height bctx.height += child.height bctx.width = max(bctx.width, child.width) diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim index ab7c906e..798709c4 100644 --- a/src/render/renderdocument.nim +++ b/src/render/renderdocument.nim @@ -232,8 +232,8 @@ proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockContext, x, y: int, te while stack.len > 0: var (ctx, x, y) = stack.pop() - x += ctx.relx - y += ctx.rely + x += ctx.offset.absx + y += ctx.offset.absy if ctx.specified{"background-color"}.rgba.a != 0: #TODO color blending grid.paintBackground(ctx.specified{"background-color"}, x, y, x + ctx.width, y + ctx.height, term) |