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 226412d816..25346519b6 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 @@ -142,8 +142,10 @@ (defn add-space-to-items ;; Distributes the remainder space between the lines [prop prop-min prop-max to-share items] - (let [num-items (->> items (remove #(mth/close? (get % prop) (get % prop-max))) count) - per-line-target (/ to-share num-items)] + (let [num-items (->> items + (remove #(mth/close? (or (get % prop) (get % prop-min) 0) (get % prop-max))) + count) + per-line-target (if (pos? num-items) (/ to-share num-items) 0)] (loop [items (seq items) remainder to-share diff --git a/common/test/common_tests/geom_flex_layout_test.cljc b/common/test/common_tests/geom_flex_layout_test.cljc index 725a0bb1cb..e727c2abc3 100644 --- a/common/test/common_tests/geom_flex_layout_test.cljc +++ b/common/test/common_tests/geom_flex_layout_test.cljc @@ -176,3 +176,18 @@ {(:id frame) bounds (:id child) child-bounds} objects false)] (t/is (= 1 (count lines))) (t/is (= 1 (:num-children (first lines))))))) + +(t/deftest flex-space-distribution-starts-at-the-minimum-and-stops-at-the-maximum + (t/is (= [{:min-size 20 :max-size 30 :size 30} + {:min-size 10 :max-size 100 :size 40}] + (fld/distribute-space :size :min-size :max-size 30 70 + [{:min-size 20 :max-size 30} + {:min-size 10 :max-size 100}]))) + (t/is (= [{:min-size 20 :max-size 30 :size 30} + {:min-size 10 :max-size 40 :size 40}] + (fld/distribute-space :size :min-size :max-size 30 100 + [{:min-size 20 :max-size 30} + {:min-size 10 :max-size 40}]))) + (t/is (= [[{:min-size 10 :max-size 10 :size 10}] 5] + (fld/add-space-to-items :size :min-size :max-size 5 + [{:min-size 10 :max-size 10 :size 10}]))))