aboutsummaryrefslogtreecommitdiffstats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-07 16:43:56 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-07 16:43:56 +0200
commit724f196225b5351724f0018b2fc78d744891fb17 (patch)
tree73a96c57bca6856eb256ccd8271922d43cc31edf /src/layout
parent93848e0c93ef0203393c48c8d9b48a2b51743107 (diff)
downloadchawan-724f196225b5351724f0018b2fc78d744891fb17.tar.gz
layout: fix min-height/max-height handling
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/box.nim2
-rw-r--r--src/layout/engine.nim40
2 files changed, 22 insertions, 20 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index 48f1a8de..5acc7ef6 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -131,6 +131,8 @@ type
padding_right*: int
min_width*: Option[int]
max_width*: Option[int]
+ min_height*: Option[int]
+ max_height*: Option[int]
# This is the (specified) content width/height. Actual dimensions may
# differ (i.e. overflow)
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 19937d92..92eeabbc 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -12,6 +12,11 @@ import utils/twtstr
func px(l: CSSLength, viewport: Viewport, p = 0): int {.inline.} =
return px(l, viewport.window, p)
+func px(l: CSSLength, viewport: Viewport, p: Option[int]): Option[int] {.inline.} =
+ if l.unit == UNIT_PERC and p.isNone:
+ return none(int)
+ return some(px(l, viewport.window, p.get(0)))
+
type InlineState = object
ictx: InlineContext
skip: bool
@@ -446,28 +451,19 @@ proc resolveDimensions(box: BlockBox, availableWidth: int, availableHeight: Opti
# Height
let pheight = computed{"height"}
if not pheight.auto:
- if pheight.unit != UNIT_PERC:
- box.contentHeight = some(pheight.px(viewport))
- elif availableHeight.isSome:
- box.contentHeight = some(pheight.px(viewport, availableHeight.get))
+ box.contentHeight = pheight.px(viewport, availableHeight)
if not computed{"max-height"}.auto:
- if computed{"max-height"}.unit != UNIT_PERC:
- let maxHeight = computed{"max-height"}.px(viewport)
- if box.contentHeight.isSome and maxHeight < box.contentHeight.get:
- box.contentHeight = some(maxHeight)
- elif availableHeight.isSome:
- let maxHeight = computed{"max-height"}.px(viewport, availableHeight.get)
- if box.contentHeight.isSome and maxHeight < box.contentHeight.get:
- box.contentHeight = some(maxHeight)
+ let max_height = computed{"max-height"}.px(viewport, availableHeight)
+ box.max_height = max_height
+ if max_height.isSome and box.contentHeight.isSome and
+ max_height.get < box.contentHeight.get:
+ box.contentHeight = max_height
if not computed{"min-height"}.auto:
- if computed{"min-height"}.unit != UNIT_PERC:
- let minHeight = computed{"min-height"}.px(viewport)
- if minHeight > box.contentHeight.get(0):
- box.contentHeight = some(minHeight)
- elif availableHeight.isSome:
- let minHeight = computed{"min-height"}.px(viewport, availableHeight.get)
- if minHeight > box.contentHeight.get(0):
- box.contentHeight = some(minHeight)
+ let min_height = computed{"min-height"}.px(viewport, availableHeight)
+ box.min_height = min_height
+ if min_height.isSome and box.contentHeight.isSome and
+ min_height.get > box.contentHeight.get:
+ box.contentHeight = min_height
# if no max content width is supplied, just use regular content width.
box.maxContentWidth = maxContentWidth.get(box.contentWidth)
@@ -910,6 +906,10 @@ proc positionBlocks(box: BlockBox) =
if box.contentHeight.isSome:
box.height = box.contentHeight.get
+ if box.max_height.isSome and box.height > box.max_height.get:
+ box.height = box.max_height.get
+ if box.min_height.isSome and box.height < box.min_height.get:
+ box.height = box.min_height.get
box.width += box.padding_left
box.width += box.padding_right