diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 6369264faf..535ddbd47c 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -610,7 +610,7 @@ (let [{:keys [a b c d]} (axes-matrix shape)] (not (mth/close? (+ (* a c) (* b d)) 0 0.0001)))) -(defn- unskewed +(defn unskewed "`shape` with the transform that its rotation and flips give it, without the skew a layout gives a turned child that it resizes along its parent's axes. Of a turn before or after the flips, the one nearer its axes." diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 32d87649b0..1b6ded2c51 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -307,6 +307,26 @@ :always (conj [attr attr-val]))))) +(defn- reoriented-operations + "The switch operations `[roperations uoperations]` into `current-shape` + with, when they carry a turn or a flip, the transform and the corners + the resulting turn and flips give it, so they describe one orientation. + Of a turn before or after the flips, the one nearer the axes of + `previous-shape`." + [[roperations uoperations] current-shape previous-shape] + (if-not (some (comp #{:rotation :flip-x :flip-y} :attr) roperations) + [roperations uoperations] + (let [carried (reduce (fn [shape {:keys [attr val]}] (assoc shape attr val)) + current-shape roperations) + oriented (cll/unskewed (assoc carried :transform (:transform previous-shape))) + values {:transform (:transform oriented) + :transform-inverse (:transform-inverse oriented) + :points (sized-geometry-value oriented (:width carried) (:height carried) :points)} + kept? #(not (contains? values (:attr %))) + [rops uops] (cll/attr-operations current-shape (fn [attr] [[attr (get values attr)]]) (keys values))] + [(into (filterv kept? roperations) rops) + (into (apply list (filter kept? uoperations)) uops)]))) + (defn update-attrs-on-switch "Copy attributes that have changed in the shape previous to the switch to the current shape (post switch). Used only on variants switch" @@ -333,10 +353,11 @@ (concat (disj ctk/swap-keep-attrs :interactions))) [roperations uoperations] - (cll/attr-operations current-shape - #(switch-attr-operations current-shape previous-shape origin-ref-shape - touched text-auto? %) - attrs) + (-> (cll/attr-operations current-shape + #(switch-attr-operations current-shape previous-shape origin-ref-shape + touched text-auto? %) + attrs) + (reoriented-operations current-shape previous-shape)) updated-attrs (into #{} (map :attr) roperations) updated-sync-groups (into #{} diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 1f9989c81b..807930f7e5 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2058,6 +2058,20 @@ :layout-children false :grid-empty false :layout-copies false :text false}] :ops [[:combine 2] [:switch] [:swap 3]]})))) +(t/deftest switching-flips-a-child-transform-with-the-flip-both-variants-share + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies false :text true}] + :ops [[:make-variant 15] [:make-variant] [:make-variant 20] [:swap 8] + [:transform 0 10 0 18] [:rotate 21] [:switch]]})))) + +(t/deftest switching-turns-a-child-keeping-the-flip-of-its-new-variant + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :flex :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies false :text true}] + :ops [[:combine 8] [:transform 13 4 0 6] [:nest 8] [:make-variant] [:make-variant 7] + [:make-variant] [:transform 0 9 0 2] [:combine 9] [:switch 6]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true