aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-23 13:30:56 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-23 13:40:06 +0200
commit041ebc4534088e5d550e9cc628a17c93ca087d2b (patch)
treed8ac9c99c4c6dff5bbced837d5126eb30ec05611
parent5f6e6630bf853550b09388c75d605da376adc88a (diff)
downloadchawan-041ebc4534088e5d550e9cc628a17c93ca087d2b.tar.gz
layout: avoid shrink-to-fit padding/margin overflow
-rw-r--r--src/layout/engine.nim19
-rw-r--r--test/layout/flex-column-child-padding.expected8
-rw-r--r--test/layout/flex-column-child-padding.html7
3 files changed, 27 insertions, 7 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index e8f8a02b..f98035c2 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -1119,17 +1119,22 @@ proc resolveFloatSizes(lctx: LayoutContext; space: AvailableSpace;
minMaxSizes: lctx.resolveMinMaxSizes(space, inlinePadding, blockPadding,
computed)
)
- if not preserveHeight: # Note: preserveHeight is only true for flex.
- sizes.space.h = maxContent()
- if computed{"width"}.canpx(sizes.space.w):
- let widthpx = computed{"width"}.spx(lctx, sizes.space.w, computed,
- inlinePadding)
+ for dim in DimensionType: # prevent overflow
+ if sizes.space[dim].isDefinite() and space[dim].isDefinite():
+ let overflow = sizes.space[dim].u + sizes.margin[dim].sum() +
+ sizes.padding[dim].sum() - space[dim].u
+ if overflow > 0:
+ sizes.space[dim].u = max(0, sizes.space[dim].u - overflow)
+ if computed{"width"}.canpx(space.w):
+ let widthpx = computed{"width"}.spx(lctx, space.w, computed, inlinePadding)
sizes.space.w = stretch(clamp(widthpx, sizes.minWidth, sizes.maxWidth))
elif sizes.space.w.isDefinite():
sizes.space.w = fitContent(clamp(sizes.space.w.u, sizes.minWidth,
sizes.maxWidth))
- if computed{"height"}.canpx(sizes.space.h):
- let heightpx = computed{"height"}.spx(lctx, sizes.space.h, computed,
+ if not preserveHeight: # Note: preserveHeight is only true for flex.
+ sizes.space.h = maxContent()
+ if computed{"height"}.canpx(space.h):
+ let heightpx = computed{"height"}.spx(lctx, space.h, computed,
blockPadding)
sizes.space.h = stretch(clamp(heightpx, sizes.minHeight, sizes.maxHeight))
elif sizes.space.h.isDefinite():
diff --git a/test/layout/flex-column-child-padding.expected b/test/layout/flex-column-child-padding.expected
new file mode 100644
index 00000000..feb78570
--- /dev/null
+++ b/test/layout/flex-column-child-padding.expected
@@ -0,0 +1,8 @@
+ test test test test test test
+ test test test test test test
+ test test test test test test
+ test test test test test test
+ test test test test test test
+ test test test test test test
+ test test test test test test
+ test test test test test test
diff --git a/test/layout/flex-column-child-padding.html b/test/layout/flex-column-child-padding.html
new file mode 100644
index 00000000..4ee79b55
--- /dev/null
+++ b/test/layout/flex-column-child-padding.html
@@ -0,0 +1,7 @@
+<div style="display: flex; flex-direction: column">
+<div style="padding-left: 50ch">
+test test test test test test test test test test test test test test test test test test test test test test test test
+</div>
+</div>
+<div style="display: inline-block; margin-left: 50ch">
+test test test test test test test test test test test test test test test test test test test test test test test test