about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-10 23:46:12 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-10 23:49:13 +0200
commit3a18dbf932ed9d9595099c59d4e01d2915734e36 (patch)
treec36f3539fc1c0b6188ce40fd246152c1c7283946
parentf981b996808394cb46a4e154ba51525b6574fddf (diff)
downloadchawan-3a18dbf932ed9d9595099c59d4e01d2915734e36.tar.gz
Fix -cha-center moving by negative x
In other words, if the element is wider than it's container, we
don't do anything at all.
-rw-r--r--src/layout/engine.nim6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index edc6c2b2..b5da155e 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -832,12 +832,10 @@ proc applyChildPosition(parent, child: BlockBox, spec: bool, x, y: var int, marg
 proc postAlignChild(box, child: BlockBox, width: int, spec: bool) =
   case box.computed{"text-align"}
   of TEXT_ALIGN_CHA_CENTER:
-    child.offset.x += width div 2
-    child.offset.x -= child.width div 2
+    child.offset.x += max(width div 2 - child.width div 2, 0)
   of TEXT_ALIGN_CHA_LEFT: discard
   of TEXT_ALIGN_CHA_RIGHT:
-    child.offset.x += width
-    child.offset.x -= child.width
+    child.offset.x += max(width - child.width, 0)
   else:
     child.offset.x += child.margin_left