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