From 16db31c53ca657be32e538a815d1f77b37f55ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 26 Oct 2021 12:32:20 +0200 Subject: [PATCH] :sparkles: Ignore constraints when flipping --- CHANGES.md | 1 + .../app/common/geom/shapes/transforms.cljc | 10 +++++--- .../app/main/data/workspace/transforms.cljs | 25 ++++++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1da4bf6ae..e8a0132b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ ### :bug: Bugs fixed - Enhance duplicating prototype connections behaviour [Taiga #2093](https://tree.taiga.io/project/penpot/us/2093). +- Ignore constraints in horizontal or vertical flip [Taiga #2038](https://tree.taiga.io/project/penpot/issue/2038). - Fix color and typographies refs lost when duplicated file [Taiga #2165](https://tree.taiga.io/project/penpot/issue/2165). - Fix problem with overflow dropdown on stroke-cap [#1216](https://github.com/penpot/penpot/issues/1216). - Fix menu context for single element nested in components [#1186](https://github.com/penpot/penpot/issues/1186). diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 0d014cf3a..bfb6a751f 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -506,7 +506,7 @@ (defn calc-child-modifiers "Given the modifiers to apply to the parent, calculate the corresponding modifiers for the child, depending on the child constraints." - [parent child parent-modifiers] + [parent child parent-modifiers ignore-constraints] (let [parent-rect (:selrect parent) child-rect (:selrect child) @@ -540,8 +540,12 @@ ;; Calculate the modifiers in the horizontal and vertical directions ;; depending on the child constraints. - constraints-h (get child :constraints-h (spec/default-constraints-h child)) - constraints-v (get child :constraints-v (spec/default-constraints-v child)) + constraints-h (if-not ignore-constraints + (get child :constraints-h (spec/default-constraints-h child)) + :scale) + constraints-v (if-not ignore-constraints + (get child :constraints-v (spec/default-constraints-v child)) + :scale) modifiers-h (case constraints-h :left diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 8180690bf..d7574e330 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -113,8 +113,9 @@ (declare clear-local-transform) (defn- set-modifiers - ([ids] (set-modifiers ids nil)) - ([ids modifiers] + ([ids] (set-modifiers ids nil false)) + ([ids modifiers] (set-modifiers ids modifiers false)) + ([ids modifiers ignore-constraints] (us/verify (s/coll-of uuid?) ids) (ptk/reify ::set-modifiers ptk/UpdateEvent @@ -132,7 +133,8 @@ (get objects id) modifiers nil - nil))) + nil + ignore-constraints))) state ids)))))) @@ -197,7 +199,7 @@ (dwu/commit-undo-transaction)))))) (defn- set-modifiers-recursive - [modif-tree objects shape modifiers root transformed-root] + [modif-tree objects shape modifiers root transformed-root ignore-constraints] (let [children (->> (get shape :shapes []) (map #(get objects %))) @@ -211,13 +213,15 @@ set-child (fn [modif-tree child] (let [child-modifiers (gsh/calc-child-modifiers shape child - modifiers)] + modifiers + ignore-constraints)] (set-modifiers-recursive modif-tree objects child child-modifiers root - transformed-root)))] + transformed-root + ignore-constraints)))] (reduce set-child (assoc-in modif-tree [(:id shape) :modifiers] modifiers) children))) @@ -410,7 +414,8 @@ shape modifiers nil - nil)))) + nil + false)))) state ids))) @@ -715,7 +720,8 @@ (rx/of (set-modifiers selected {:resize-vector (gpt/point -1.0 1.0) :resize-origin origin - :displacement (gmt/translate-matrix (gpt/point (- (:width selrect)) 0))}) + :displacement (gmt/translate-matrix (gpt/point (- (:width selrect)) 0))} + true) (apply-modifiers selected)))))) (defn flip-vertical-selected [] @@ -731,7 +737,8 @@ (rx/of (set-modifiers selected {:resize-vector (gpt/point 1.0 -1.0) :resize-origin origin - :displacement (gmt/translate-matrix (gpt/point 0 (- (:height selrect))))}) + :displacement (gmt/translate-matrix (gpt/point 0 (- (:height selrect))))} + true) (apply-modifiers selected))))))