diff options
author | bptato <nincsnevem662@gmail.com> | 2024-06-23 13:30:56 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-06-23 13:40:06 +0200 |
commit | 041ebc4534088e5d550e9cc628a17c93ca087d2b (patch) | |
tree | d8ac9c99c4c6dff5bbced837d5126eb30ec05611 /src | |
parent | 5f6e6630bf853550b09388c75d605da376adc88a (diff) | |
download | chawan-041ebc4534088e5d550e9cc628a17c93ca087d2b.tar.gz |
layout: avoid shrink-to-fit padding/margin overflow
Diffstat (limited to 'src')
-rw-r--r-- | src/layout/engine.nim | 19 |
1 files changed, 12 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(): |