about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-19 19:13:59 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-19 19:13:59 +0100
commit58a833789dacd6577fc23c382614652033209d76 (patch)
tree0224ea71fc4667cd322f240385c37a168fa1d740
parent15b0afc98c0cfb685379b3680552bbe5d0f7a003 (diff)
downloadchawan-58a833789dacd6577fc23c382614652033209d76.tar.gz
layout: fix indefinitely sized flex items with bounds
maybe I'll get it right one of these days
-rw-r--r--src/css/layout.nim9
-rw-r--r--test/layout/flex-item-indefinite-size-with-min-max-bounds.color.expected3
-rw-r--r--test/layout/flex-item-indefinite-size-with-min-max-bounds.html4
3 files changed, 15 insertions, 1 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim
index 411fb38a..c5347af2 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -174,6 +174,9 @@ func outerSize(box: BlockBox; dim: DimensionType; sizes: ResolvedSizes):
     LayoutUnit =
   return sizes.margin[dim].sum() + box.state.size[dim]
 
+func max(span: Span): LayoutUnit =
+  return max(span.start, span.send)
+
 # In CSS, "min" beats "max".
 func minClamp(x: LayoutUnit; span: Span): LayoutUnit =
   return max(min(x, span.send), span.start)
@@ -1100,6 +1103,8 @@ proc resolveFlexItemSizes(lctx: LayoutContext; space: AvailableSpace;
       t: sizes.space[dim].t,
       u: minClamp(u, sizes.minMaxSizes[dim])
     )
+  elif sizes.minMaxSizes[dim].send < LayoutUnit.high:
+    sizes.space[dim] = fitContent(sizes.minMaxSizes[dim].max())
   else:
     # Ensure that space is indefinite in the first pass if no width has
     # been specified.
@@ -1115,6 +1120,8 @@ proc resolveFlexItemSizes(lctx: LayoutContext; space: AvailableSpace;
       t: sizes.space[odim].t,
       u: minClamp(u, sizes.minMaxSizes[odim])
     )
+  elif sizes.minMaxSizes[odim].send < LayoutUnit.high:
+    sizes.space[odim] = fitContent(sizes.minMaxSizes[odim].max())
   return sizes
 
 proc resolveBlockSizes(lctx: LayoutContext; space: AvailableSpace;
@@ -2282,7 +2289,7 @@ proc redistributeMainSize(mctx: var FlexMainContext; diff: LayoutUnit;
           it.weights[wt] = 0
           mctx.shrinkSize -= it.child.state.size[dim]
         u = minu
-      let maxu = it.sizes.minMaxSizes[dim].send
+      let maxu = it.sizes.minMaxSizes[dim].max()
       if maxu < u:
         # max violation
         if wt == fwtGrow: # freeze
diff --git a/test/layout/flex-item-indefinite-size-with-min-max-bounds.color.expected b/test/layout/flex-item-indefinite-size-with-min-max-bounds.color.expected
new file mode 100644
index 00000000..00b23149
--- /dev/null
+++ b/test/layout/flex-item-indefinite-size-with-min-max-bounds.color.expected
@@ -0,0 +1,3 @@
+test test test
+test test test
+
diff --git a/test/layout/flex-item-indefinite-size-with-min-max-bounds.html b/test/layout/flex-item-indefinite-size-with-min-max-bounds.html
new file mode 100644
index 00000000..c2904684
--- /dev/null
+++ b/test/layout/flex-item-indefinite-size-with-min-max-bounds.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<div style="display: flex; background: green; width: 10ch">
+<div style="max-width: 100%; min-width: 15ch">
+test test test test test test