diff --git a/common/src/app/common/geom/modifiers.cljc b/common/src/app/common/geom/modifiers.cljc index 8aef13a3c0..8668c332d4 100644 --- a/common/src/app/common/geom/modifiers.cljc +++ b/common/src/app/common/geom/modifiers.cljc @@ -197,12 +197,24 @@ ([objects bounds ignore-constraints modif-tree shapes] (reduce #(set-modifiers-layout objects bounds ignore-constraints %1 %2) modif-tree shapes))) +(defn- current-transform + "The transform and its inverse of the shape `id` as the modifiers being + calculated leave it in `bounds`, or as it is stored in `objects`." + [objects bounds id] + (if-let [points (some-> (get bounds id) deref)] + (let [[_ transform transform-inverse] (gtr/calculate-geometry points)] + [(or transform (gmt/matrix)) (or transform-inverse (gmt/matrix))]) + (let [shape (get objects id)] + [(or (:transform shape) (gmt/matrix)) (or (:transform-inverse shape) (gmt/matrix))]))) + (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)))] + "Whether the axes of the shape `id` are turned against those of its parent, + as the modifiers being calculated leave them, so that a size along one of + them does not follow a size along the other." + [objects bounds id] + (let [[transform _] (current-transform objects bounds id) + [_ parent-inverse] (current-transform objects bounds (get-in objects [id :parent-id])) + {:keys [b c]} (gmt/multiply parent-inverse transform)] (not (and (mth/close? b 0 0.0001) (mth/close? c 0 0.0001))))) (defn- calc-auto-modifiers @@ -213,6 +225,8 @@ [objects bounds parent] (let [parent-id (:id parent) parent-bounds (get bounds parent-id) + ;; the frame the modifiers being calculated leave the shape in + [transform transform-inverse] (current-transform objects bounds parent-id) set-parent-auto-width (fn [modifiers auto-width] @@ -220,7 +234,7 @@ current-width (gpo/width-points @parent-bounds) scale-width (/ auto-width current-width)] (-> modifiers - (ctm/resize (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent))))) + (ctm/resize (gpt/point scale-width 1) origin transform transform-inverse)))) set-parent-auto-height (fn [modifiers auto-height] @@ -228,14 +242,14 @@ current-height (gpo/height-points @parent-bounds) scale-height (/ auto-height current-height)] (-> modifiers - (ctm/resize (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent))))) + (ctm/resize (gpt/point 1 scale-height) origin transform transform-inverse)))) children (->> (cfh/get-immediate-children objects parent-id) (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))))) + (not (turned-in-parent? objects bounds parent-id))) auto? (or (ctl/auto? parent) (and grid-fill? (ctl/fill? parent))) auto-width? (or (ctl/auto-width? parent) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 1ac612eba3..77279eb1f5 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1169,3 +1169,12 @@ :layout-children false :grid-empty false :layout-copies true :text true}] :ops [[:transform 1 4 0 0] [:delete 5 0 0 0] [:delete 0] [:restore 0] [:transform 1 4 0 0] [:switch 0 0 0 0]]})))) + +(t/deftest generated-turning-a-grid-turns-its-fill-child-rigidly + ;; a grid copy whose child fills its width is turned 45 degrees: the child + ;; turns with it, unskewed, as a full sync places it + (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 6 0 0 0]]}))))