diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-03 23:10:44 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-03 23:18:25 +0100 |
commit | 15d5ad451bdc456e80e7468a76fb2eac6feb4a4e (patch) | |
tree | 941481cc2795e1dd191b928737a323362e298b16 /src/layout/engine.nim | |
parent | fb04a7e96ff68b4516ea483ca4fbe9c4976bb7d2 (diff) | |
download | chawan-15d5ad451bdc456e80e7468a76fb2eac6feb4a4e.tar.gz |
strwidth, renderdocument: small refactoring
* put attrs pointer in state * simplify width() * use unsigned int as ptint to avoid UB
Diffstat (limited to 'src/layout/engine.nim')
-rw-r--r-- | src/layout/engine.nim | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 4c56ffd9..d2d22ab9 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -15,7 +15,7 @@ import utils/widthconv type LayoutState = ref object - attrs: WindowAttributes + attrsp: ptr WindowAttributes positioned: seq[AvailableSpace] # min-content: box width is longest word's width @@ -45,6 +45,9 @@ type minHeight: LayoutUnit maxHeight: LayoutUnit +template attrs(state: LayoutState): WindowAttributes = + state.attrsp[] + func maxContent(): SizeConstraint = return SizeConstraint(t: MAX_CONTENT) @@ -2774,13 +2777,13 @@ proc generateTableBox(styledNode: StyledNode, lctx: LayoutState, box.generateTableChildWrappers() return box -proc renderLayout*(root: StyledNode, attrs: WindowAttributes): BlockBox = +proc renderLayout*(root: StyledNode, attrsp: ptr WindowAttributes): BlockBox = let space = AvailableSpace( - w: stretch(attrs.width_px), - h: stretch(attrs.height_px) + w: stretch(attrsp[].width_px), + h: stretch(attrsp[].height_px) ) let lctx = LayoutState( - attrs: attrs, + attrsp: attrsp, positioned: @[space] ) let builder = root.generateBlockBox(lctx) |