From c73b30cb56259be7ce582fb1e8e719614a62c543 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 3 Nov 2026 11:26:38 +0100 Subject: [PATCH] :ambulance: Lay out a single-line flex board aligned by space-between A wrapped flex board whose content is aligned by space-between shares its free space between its lines, dividing it by the number of lines minus one. With a single line and integer sizes that is a division by zero, which throws in Clojure. The gap after a single line goes unused, so it now takes the layout's own gap. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.49 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 41.045 | 0.60 | | library-update-into-copies | 83.083 | 51.057 | 0.61 | | main-edit-among-many-shapes | 4.837 | 2.253 | 0.47 | | main-edit-into-10-copies | 1.79 | 1.055 | 0.59 | | main-edit-into-100-copies | 15.415 | 9.948 | 0.65 | | main-edit-into-1000-copies | 153.086 | 108.962 | 0.71 | | variant-switch-into-copies | 32.052 | 21.743 | 0.68 | AI-assisted-by: claude-opus-5-5 --- .../app/common/geom/shapes/flex_layout/positions.cljc | 5 +++-- common/test/common_tests/geom_flex_layout_test.cljc | 9 +++++++++ common/test/common_tests/logic/composable_gen_test.cljc | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/geom/shapes/flex_layout/positions.cljc b/common/src/app/common/geom/shapes/flex_layout/positions.cljc index 2dcb28d42d..ad32a4c24f 100644 --- a/common/src/app/common/geom/shapes/flex_layout/positions.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/positions.cljc @@ -98,7 +98,8 @@ stretch? (/ free-width num-lines) - between? + ;; a single line has no gap to share + (and between? (> num-lines 1)) (/ free-width (dec num-lines)) around? @@ -118,7 +119,7 @@ stretch? (/ free-height num-lines) - between? + (and between? (> num-lines 1)) (/ free-height (dec num-lines)) around? diff --git a/common/test/common_tests/geom_flex_layout_test.cljc b/common/test/common_tests/geom_flex_layout_test.cljc index e727c2abc3..160b4abd02 100644 --- a/common/test/common_tests/geom_flex_layout_test.cljc +++ b/common/test/common_tests/geom_flex_layout_test.cljc @@ -60,6 +60,15 @@ (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])))))) +(t/deftest next-line-after-a-single-space-between-line-is-finite + (doseq [direction [:row :column]] + (let [frame (make-col-frame :layout-flex-dir direction + :layout-align-content :space-between) + bounds (rect->bounds (grc/make-rect 0 0 200 200)) + base-p (flp/get-base-line frame bounds 50 30 1) + next-p (flp/get-next-line frame bounds {:line-width 50 :line-height 30} base-p 50 30 1)] + (t/is (every? mth/finite? [(:x next-p) (:y next-p)]))))) + ;; ---- get-base-line (around? branch) ---- ;; ;; Bug: in positions.cljc the col? + around? branch had a mis-parenthesised diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index b2e91c8c5c..337dfd572c 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1019,3 +1019,10 @@ :library-depth 1 :library true :rich-variants true :library-text true :layout-copies true :text true}] :ops [[:transform 0 4 0 2] [:switch 0 0 0 0]]})))) + +(t/deftest generated-single-line-flex-set-to-space-between-lays-out + ;; aligning the content of a one-line wrapped flex main by space-between + ;; leaves no gap to share between its lines + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :layout :flex :library true + :rich-variants true :layout-copies true :text true}] + :ops [[:style 0 23 18 0]]}))))