diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index be3cf89eb1..02f299ecb7 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -366,7 +366,7 @@ (reduce #(update %1 %2 turn) objects (cfh/get-children-ids-with-self objects (:id shape-main))))))))) -(defn- generate-sync-shape-direct +(defn generate-sync-shape-direct "Generate changes to synchronize one shape that is the root of a component instance, and all its children, from the given component." [changes file libraries container shape-id reset?] diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 33e2351c63..204e8978b0 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -470,7 +470,14 @@ (ctk/touched-group? % :geometry-group)) orig-touched) (keep-orientation-override original-shape new-shape page (or (get-in libraries [(:component-file new-shape) :data]) ldata) - (:component-id new-shape) nil))] + (:component-id new-shape) nil)) + ;; A carried size changes the frame its untouched children follow. + ;; Place them through the same constraints as an ordinary copy sync. + changes (cond-> changes + (some #(ctk/touched-group? % :geometry-group) orig-touched) + (cll/generate-sync-shape-direct + nil libraries (assoc container :objects (pcb/get-objects changes)) + (:id new-shape) false))] [changes (mapv (comp :parent-id :new) pairs)])) (defn- shape-index diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index 1a72302f9e..57cb460738 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -51,6 +51,34 @@ (t/is (mth/close? 80 (get-in copy [:selrect :height]) 1e-10)) (t/is (contains? (:touched copy) :geometry-group))))) +(t/deftest switch-places-children-through-a-carried-root-resize + (doseq [angle [0 45]] + (let [root-params {:width 100 :height 100} + child-params {:x 10 :y 10 :width 20 :height 20 + :constraints-h :left :constraints-v :top} + file (-> (thf/sample-file :file1) + (thv/add-variant-with-child + :v01 :c01 :m01 :c02 :m02 :r01 :r02 + {:variant1-params root-params :variant2-params root-params + :child1-params child-params :child2-params child-params}) + (thc/instantiate-component :c01 :copy01)) + file (reduce (fn [file modifiers] + (let [shape (ths/get-shape file :copy01)] + (thf/apply-changes file + (n/transform-changes (thf/current-page file) shape + (modifiers shape))))) + file [#(ctm/rotation-modifiers % (gsh/shape->center %) angle) + #(ctm/change-size % nil 80)]) + switched (tho/swap-component-in-shape file :copy01 :c02 {:keep-touched? true}) + relative (fn [file] + (let [root (ths/get-shape file :copy01) + child (get-in (thf/current-page file) [:objects (first (:shapes root))])] + (gpt/subtract (first (:points child)) (first (:points root))))) + child (get-in (thf/current-page switched) + [:objects (first (:shapes (ths/get-shape switched :copy01)))])] + (t/is (< (gpt/distance (relative file) (relative switched)) 0.01)) + (t/is (empty? (:touched child)))))) + ;; ============================================================ ;; BASIC SWITCH TESTS (no overrides) ;; ============================================================