From a95f26b601275e1bb22ca4ab2d77cbacdb03e25b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 5 Nov 2026 18:18:02 +0100 Subject: [PATCH] :bug: Let a grid's fill alone size a child turned in the grid A fill child of a grid takes the size of its content along its own axes, and the grid's fill then scales its box to the cell along the grid's axes. For a child turned in the grid the two disagree: each scale along the grid's axes skews the turned child and leaves it narrower than its content, and the next reflow widens it again. A grid board that fills its cell and is turned 45 degrees grew and skewed on every reflow, and its layout never settled. A fill child turned in its grid no longer takes its content's size; the grid's fill alone sizes it along the grid's axes. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.311 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 39.017 | 0.57 | | library-update-into-copies | 83.083 | 47.52 | 0.57 | | main-edit-among-many-shapes | 4.837 | 2.313 | 0.48 | | main-edit-into-10-copies | 1.79 | 1.039 | 0.58 | | main-edit-into-100-copies | 15.415 | 10.063 | 0.65 | | main-edit-into-1000-copies | 153.086 | 94.681 | 0.62 | | variant-switch-into-copies | 32.052 | 22.649 | 0.71 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/geom/modifiers.cljc | 26 ++++++++++++++----- .../logic/composable_gen_test.cljc | 8 ++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/geom/modifiers.cljc b/common/src/app/common/geom/modifiers.cljc index c40828ba69..8aef13a3c0 100644 --- a/common/src/app/common/geom/modifiers.cljc +++ b/common/src/app/common/geom/modifiers.cljc @@ -10,6 +10,7 @@ [app.common.data.macros :as dm] [app.common.files.helpers :as cfh] [app.common.geom.bounds-map :as cgb] + [app.common.geom.matrix :as gmt] [app.common.geom.modif-tree :as cgt] [app.common.geom.point :as gpt] [app.common.geom.shapes.common :as gco] @@ -21,6 +22,7 @@ [app.common.geom.shapes.points :as gpo] [app.common.geom.shapes.transforms :as gtr] [app.common.geom.shapes.tree-seq :as cgst] + [app.common.math :as mth] [app.common.types.modifiers :as ctm] [app.common.types.shape.layout :as ctl] [app.common.uuid :as uuid])) @@ -195,8 +197,19 @@ ([objects bounds ignore-constraints modif-tree shapes] (reduce #(set-modifiers-layout objects bounds ignore-constraints %1 %2) modif-tree shapes))) +(defn- turned-in-parent? + "Whether the axes of `shape` are turned against those of `parent`, so that + a size along one of them does not follow a size along the other." + [shape parent] + (let [{:keys [b c]} (gmt/multiply (or (:transform-inverse parent) (gmt/matrix)) + (or (:transform shape) (gmt/matrix)))] + (not (and (mth/close? b 0 0.0001) (mth/close? c 0 0.0001))))) + (defn- calc-auto-modifiers - "Calculates the modifiers to adjust the bounds for auto-width/auto-height shapes" + "Calculates the modifiers to adjust the bounds for auto-width/auto-height + shapes. A fill child of a grid takes the size of its content, unless it + is turned in the grid: the grid's fill then sizes it along the grid's + axes, and its content's size counts as its minimum there." [objects bounds parent] (let [parent-id (:id parent) parent-bounds (get bounds parent-id) @@ -221,15 +234,14 @@ (remove ctl/position-absolute?) (remove gco/invalid-geometry?)) + grid-fill? (and (ctl/grid-layout? objects (:parent-id parent)) + (not (turned-in-parent? parent (get objects (:parent-id parent))))) auto? (or (ctl/auto? parent) - (and (ctl/grid-layout? objects (:parent-id parent)) - (ctl/fill? parent))) + (and grid-fill? (ctl/fill? parent))) auto-width? (or (ctl/auto-width? parent) - (and (ctl/grid-layout? objects (:parent-id parent)) - (ctl/fill-width? parent))) + (and grid-fill? (ctl/fill-width? parent))) auto-height? (or (ctl/auto-height? parent) - (and (ctl/grid-layout? objects (:parent-id parent)) - (ctl/fill-height? parent))) + (and grid-fill? (ctl/fill-height? parent))) content-bounds (when (and (d/not-empty? children) auto?) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 76de37faa0..1a50c9db95 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1145,6 +1145,14 @@ [:text-style 18 0 1] [:duplicate 0 0 0 0] [:nest 15 0 0 0] [:switch 6 0 0 0] [:rotate 19 0 0 0] [:detach 3 0 0 0]]})))) +(t/deftest generated-turned-fill-child-of-a-grid-settles + ;; a grid main's child board fills its width and is turned 45 degrees + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library-variants true :stale-libraries true + :layout :grid :layout-item-margins false :grid-square false :library-depth 1 + :library true :rich-variants true :layout-children true :library-text true + :grid-empty true :layout-copies true :text true}] + :ops [[:style 13 29 1] [:rotate 5 0 0 0]]})))) + (t/deftest generated-detach-leaves-a-nested-copy-that-only-takes-its-parents-turn ;; a turned copy root is detached; its nested copy, whose main sits at the ;; root of its page, only shows the turn of its now plain parent