From 47b597a5da9f432c5579355c1768c98cafdccf27 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 17 Nov 2026 01:04:52 +0100 Subject: [PATCH] :bug: Measure a layout's content with the paddings it uses The content bounds of a grid or flex layout, which size a fill child that is itself a layout and a layout that hugs, read the four stored paddings. A simple padding type repeats the top and right values on the bottom and left, so a layout whose sides were edited one by one before its type was set to simple measured its content with the stale left and bottom values: a fill grid with paddings 3, 6, 9 and 12 came out 6 px wider than its content. Both use `ctl/paddings`, as the layouts themselves do. Test: `geom-grid-layout-test/grid-content-bounds-take-simple-paddings` (fails before the fix). Benchmark (bench-components, alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 22.925 | 23.239 | 0.65 | | edit-through-a-chain-of-dependents | 68.931 | 45.225 | 46.994 | 0.66 | | library-update-into-copies | 83.083 | 54.842 | 57.554 | 0.66 | | main-edit-among-many-shapes | 4.837 | 2.528 | 2.705 | 0.52 | | main-edit-into-10-copies | 1.79 | 1.136 | 1.163 | 0.63 | | main-edit-into-100-copies | 15.415 | 10.746 | 11.596 | 0.7 | | main-edit-into-1000-copies | 153.086 | 109.63 | 113.323 | 0.72 | | variant-switch-into-copies | 32.052 | 23.103 | 24.367 | 0.72 | AI-assisted-by: claude-opus-5-5 --- .../app/common/geom/shapes/flex_layout/bounds.cljc | 13 +++++++------ .../app/common/geom/shapes/grid_layout/bounds.cljc | 12 +++++------- common/test/common_tests/geom_grid_layout_test.cljc | 12 ++++++++++++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/common/src/app/common/geom/shapes/flex_layout/bounds.cljc b/common/src/app/common/geom/shapes/flex_layout/bounds.cljc index 4f4cc1895c..be48e3e8b6 100644 --- a/common/src/app/common/geom/shapes/flex_layout/bounds.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/bounds.cljc @@ -158,7 +158,7 @@ correct-v)))))))) (defn layout-content-bounds - [bounds {:keys [layout-padding] :as parent} children objects] + [bounds parent children objects] (let [parent-id (:id parent) parent-bounds (get bounds parent-id)] @@ -182,11 +182,12 @@ layout-gap-col 0) - {pad-top :p1 pad-right :p2 pad-bottom :p3 pad-left :p4} layout-padding - pad-top (+ (or pad-top 0) row-pad) - pad-right (+ (or pad-right 0) col-pad) - pad-bottom (+ (or pad-bottom 0) row-pad) - pad-left (+ (or pad-left 0) col-pad) + ;; the paddings the layout uses: a simple type repeats top and right + [pad-top pad-right pad-bottom pad-left] (ctl/paddings parent) + pad-top (+ pad-top row-pad) + pad-right (+ pad-right col-pad) + pad-bottom (+ pad-bottom row-pad) + pad-left (+ pad-left col-pad) layout-points (layout-content-points bounds parent children objects)] diff --git a/common/src/app/common/geom/shapes/grid_layout/bounds.cljc b/common/src/app/common/geom/shapes/grid_layout/bounds.cljc index f92e365db6..c3be561a27 100644 --- a/common/src/app/common/geom/shapes/grid_layout/bounds.cljc +++ b/common/src/app/common/geom/shapes/grid_layout/bounds.cljc @@ -8,7 +8,8 @@ (:require [app.common.data :as d] [app.common.geom.point :as gpt] - [app.common.geom.shapes.points :as gpo])) + [app.common.geom.shapes.points :as gpo] + [app.common.types.shape.layout :as ctl])) (defn layout-content-points [bounds parent {:keys [row-tracks column-tracks]}] @@ -26,16 +27,13 @@ (gpt/add (:start-p %) (hv (:size %))))))))))) (defn layout-content-bounds - [bounds {:keys [layout-padding] :as parent} layout-data] + [bounds parent layout-data] (let [parent-id (:id parent) parent-bounds (get bounds parent-id)] (when-let [parent-bounds (some-> parent-bounds deref)] - (let [{pad-top :p1 pad-right :p2 pad-bottom :p3 pad-left :p4} layout-padding - pad-top (or pad-top 0) - pad-right (or pad-right 0) - pad-bottom (or pad-bottom 0) - pad-left (or pad-left 0) + (let [;; the paddings the layout uses: a simple type repeats top and right + [pad-top pad-right pad-bottom pad-left] (ctl/paddings parent) layout-points (layout-content-points bounds parent layout-data)] diff --git a/common/test/common_tests/geom_grid_layout_test.cljc b/common/test/common_tests/geom_grid_layout_test.cljc index a78facf3b7..cdbc72de23 100644 --- a/common/test/common_tests/geom_grid_layout_test.cljc +++ b/common/test/common_tests/geom_grid_layout_test.cljc @@ -11,8 +11,10 @@ [app.common.geom.modifiers :as gm] [app.common.geom.rect :as grc] [app.common.geom.shapes :as gsh] + [app.common.geom.shapes.grid-layout.bounds :as glb] [app.common.geom.shapes.grid-layout.layout-data :as gld] [app.common.geom.shapes.grid-layout.params :as glparams] + [app.common.geom.shapes.points :as gpo] [app.common.math :as mth] [app.common.types.modifiers :as ctm] [app.common.types.shape :as cts] @@ -175,6 +177,16 @@ result (gld/calc-layout-data frame (bounds-for frame) [] {} {})] (t/is (= 1 (count (:row-tracks result)))))) +(t/deftest grid-content-bounds-take-simple-paddings + ;; a simple padding type repeats the top and right values on the bottom + ;; and left: two 50 px columns and 6 px on each side + (let [frame (make-grid-frame :layout-padding-type :simple + :layout-padding {:p1 3 :p2 6 :p3 9 :p4 12}) + bounds {(:id frame) (delay (bounds-for frame))} + data (gld/calc-layout-data frame (bounds-for frame) [] bounds {}) + content (glb/layout-content-bounds bounds frame data)] + (t/is (mth/close? 112 (gpo/width-points content) 0.01)))) + (t/deftest grid-column-gap-space-between (t/testing "justify-content :space-between increases column-gap correctly" ;; free = 100; num-cols = 2; formula: 100 / (2-1) = 100