From 4a40c1096229d8fd8be67042b7f6be2909c50c8b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 28 Oct 2026 11:44:43 +0100 Subject: [PATCH] :bug: Keep single-child flex spacing finite Compute a space-between gap only when a line has at least two children. A one-child line keeps its configured gap instead of dividing by zero. Cover both row and column directions, including reversed layouts, finite spacing fields and unchanged two-child distribution. AI-assisted-by: GPT-6 --- .../geom/shapes/flex_layout/layout_data.cljc | 4 ++-- .../test/common_tests/geom_flex_layout_test.cljc | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc b/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc index c960d4414d..226412d816 100644 --- a/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/layout_data.cljc @@ -361,7 +361,7 @@ (and row? space-around?) (/ (max layout-gap-col (/ (- width line-width) num-children)) 2) - (and row? space-between? (not auto-width?)) + (and row? space-between? (not auto-width?) (> num-children 1)) (max layout-gap-col (/ (- width line-width) (dec num-children))) :else @@ -374,7 +374,7 @@ (and col? space-around?) (/ (max layout-gap-row (/ (- height line-height) num-children)) 2) - (and col? space-between? (not auto-height?)) + (and col? space-between? (not auto-height?) (> num-children 1)) (max layout-gap-row (/ (- height line-height) (dec num-children))) :else diff --git a/common/test/common_tests/geom_flex_layout_test.cljc b/common/test/common_tests/geom_flex_layout_test.cljc index 2746ead5ed..725a0bb1cb 100644 --- a/common/test/common_tests/geom_flex_layout_test.cljc +++ b/common/test/common_tests/geom_flex_layout_test.cljc @@ -44,6 +44,22 @@ bounds (rect->bounds (grc/make-rect 0 0 200 200))] (t/is (= [] (:layout-lines (fld/calc-layout-data frame bounds [] {} {}))))))) +(t/deftest space-between-distributes-gap-only-between-several-children + (doseq [direction [:row :row-reverse :column :column-reverse] + children [1 2]] + (let [row? (#{:row :row-reverse} direction) + frame (make-col-frame :layout-flex-dir direction + :layout-justify-content :space-between + :layout-gap {:row-gap 11 :column-gap 7}) + bounds (rect->bounds (grc/make-rect 0 0 200 200)) + line (fld/add-line-spacing frame bounds false + {:num-children children + :line-width (if row? (* 50 children) 50) + :line-height (if row? 30 (* 30 children))}) + gap (get line (if row? :layout-gap-col :layout-gap-row))] + (t/is (== (if (= children 1) (if row? 7 11) (if row? 100 140)) gap)) + (t/is (every? mth/finite? (map line [:layout-gap-col :layout-gap-row :margin-x :margin-y])))))) + ;; ---- get-base-line (around? branch) ---- ;; ;; Bug: in positions.cljc the col? + around? branch had a mis-parenthesised