aboutsummaryrefslogtreecommitdiffstats
path: root/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/engine.nim66
1 files changed, 32 insertions, 34 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index f116e440..47c293b6 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -8,7 +8,6 @@ import css/stylednode
import css/values
import io/window
import layout/box
-import types/color
import utils/twtstr
# Build phase
@@ -810,28 +809,10 @@ proc positionBlocks(box: BlockBox) =
box.height += box.padding_top
x += box.padding_left
- let needsMove = box.computed{"text-align"} in {TEXT_ALIGN_CHA_LEFT, TEXT_ALIGN_CHA_CENTER, TEXT_ALIGN_CHA_RIGHT}
template apply_child(child: BlockBox) =
child.offset.y = y
child.offset.x = x
- if not needsMove and spec and child.contentWidth < box.contentWidth:
- let margin_left = child.computed{"margin-left"}
- let margin_right = child.computed{"margin-right"}
- if margin_left.auto and margin_right.auto:
- child.margin_left += box.contentWidth div 2
- child.margin_left -= child.contentWidth div 2
- child.margin_right += box.contentWidth div 2
- child.margin_right -= child.contentWidth div 2
- elif margin_left.auto:
- child.margin_left += box.contentWidth
- child.margin_left -= child.contentWidth
- elif margin_right.auto:
- child.margin_right += box.contentWidth
- child.margin_right -= child.contentWidth
- child.offset.x += child.margin_left
- if box.computed{"position"} == POSITION_RELATIVE:
- box.positionRelative(child)
y += child.height
box.height += child.height
if not spec:
@@ -887,25 +868,42 @@ proc positionBlocks(box: BlockBox) =
margin_todo.append(box.margin_bottom)
box.margin_bottom = margin_todo.sum()
- if needsMove:
- # Re-position the children.
- # The x offset for values in shrink mode depends on the parent box's
- # width, so we can not just do this in the first pass.
- let width = if box.shrink:
- min(box.width, box.contentWidth)
- else:
- max(box.width, box.contentWidth)
+ # Re-position the children.
+ # The x offset for values in shrink mode depends on the parent box's
+ # width, so we can not just do this in the first pass.
+ let width = if box.shrink:
+ min(box.width, box.contentWidth)
+ else:
+ max(box.width, box.contentWidth)
+ for child in box.nested:
case box.computed{"text-align"}
of TEXT_ALIGN_CHA_CENTER:
- for child in box.nested:
- child.offset.x += width div 2
- child.offset.x -= child.width div 2
+ child.offset.x += width div 2
+ child.offset.x -= child.width div 2
of TEXT_ALIGN_CHA_LEFT: discard
of TEXT_ALIGN_CHA_RIGHT:
- for child in box.nested:
- child.offset.x += width
- child.offset.x -= child.width
- else: discard
+ child.offset.x += width
+ child.offset.x -= child.width
+ elif child.contentWidth < box.contentWidth:
+ let margin_left = child.computed{"margin-left"}
+ let margin_right = child.computed{"margin-right"}
+ if margin_left.auto and margin_right.auto:
+ child.margin_left += width div 2
+ child.margin_left -= child.width div 2
+ child.margin_right += width div 2
+ child.margin_right -= child.width div 2
+ elif margin_left.auto:
+ child.margin_left += width
+ child.margin_left -= child.width
+ elif margin_right.auto:
+ child.margin_right += width
+ child.margin_right -= child.width
+ if not spec:
+ let marginWidth = child.width + child.margin_left + child.margin_right
+ box.width = min(box.maxContentWidth, max(marginWidth, box.width))
+ child.offset.x += child.margin_left
+ if box.computed{"position"} == POSITION_RELATIVE:
+ box.positionRelative(child)
box.height += box.padding_bottom