about summary refs log tree commit diff stats
path: root/src/layout/engine.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-25 18:34:30 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-25 18:34:30 +0200
commitbd436a52825bc5423de5cf13fd64b4e0af844afb (patch)
tree068ce8d481eca7a572b4edde17dcbb3a3efadbaa /src/layout/engine.nim
parentedf8d22ca950f23ede001891516e7ca09ad080a0 (diff)
downloadchawan-bd436a52825bc5423de5cf13fd64b4e0af844afb.tar.gz
layout: fix incorrect absolute positioning
It was broken for parent boxes with indefinite sizes.
Diffstat (limited to 'src/layout/engine.nim')
-rw-r--r--src/layout/engine.nim11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 68685f11..8cd94c7d 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -1572,19 +1572,16 @@ proc layoutRootInline(bctx: var BlockContext; root: RootInlineFragment;
 
 proc positionAbsolute(lctx: LayoutContext; box: BlockBox;
     margin: RelativeRect) =
-  let last = lctx.positioned[^1]
-  let parentWidth = applySizeConstraint(lctx.attrs.width_px, last.w)
-  let parentHeight = applySizeConstraint(lctx.attrs.height_px, last.h)
   if not box.computed{"left"}.auto:
     box.state.offset.x = box.state.positioned.left + margin.left
   elif not box.computed{"right"}.auto:
-    box.state.offset.x = parentWidth - box.state.positioned.right -
-      box.state.size.w - margin.right
+    box.state.offset.x = -box.state.positioned.right - box.state.size.w -
+      margin.right
   if not box.computed{"top"}.auto:
     box.state.offset.y = box.state.positioned.top + margin.top
   elif not box.computed{"bottom"}.auto:
-    box.state.offset.y = parentHeight - box.state.positioned.bottom -
-      box.state.size.h - margin.bottom
+    box.state.offset.y = -box.state.positioned.bottom - box.state.size.h -
+      margin.bottom
 
 proc positionRelative(parent, box: BlockBox) =
   if not box.computed{"left"}.auto: