diff --git a/common/src/app/common/geom/shapes/constraints.cljc b/common/src/app/common/geom/shapes/constraints.cljc index 32064b22d..1565392f8 100644 --- a/common/src/app/common/geom/shapes/constraints.cljc +++ b/common/src/app/common/geom/shapes/constraints.cljc @@ -176,45 +176,50 @@ (defn calc-child-modifiers [parent child modifiers ignore-constraints transformed-parent-rect] - (let [constraints-h - (if-not ignore-constraints - (:constraints-h child (default-constraints-h child)) - :scale) - constraints-v - (if-not ignore-constraints - (:constraints-v child (default-constraints-v child)) - :scale) + (if (and (nil? (:resize-vector modifiers)) + (nil? (:resize-vector-2 modifiers))) + ;; If we don't have a resize modifier we return the same modifiers + modifiers + (let [constraints-h + (if-not ignore-constraints + (:constraints-h child (default-constraints-h child)) + :scale) - modifiers-h (constraint-modifier (constraints-h const->type+axis) :x parent child modifiers transformed-parent-rect) - modifiers-v (constraint-modifier (constraints-v const->type+axis) :y parent child modifiers transformed-parent-rect)] + constraints-v + (if-not ignore-constraints + (:constraints-v child (default-constraints-v child)) + :scale) - ;; Build final child modifiers. Apply transform again to the result, to get the - ;; real modifiers that need to be applied to the child, including rotation as needed. - (cond-> {} - (or (contains? modifiers-h :displacement) - (contains? modifiers-v :displacement)) - (assoc :displacement (cond-> (gpt/point (get-in modifiers-h [:displacement :x] 0) - (get-in modifiers-v [:displacement :y] 0)) - (some? (:resize-transform modifiers)) - (gpt/transform (:resize-transform modifiers)) + modifiers-h (constraint-modifier (constraints-h const->type+axis) :x parent child modifiers transformed-parent-rect) + modifiers-v (constraint-modifier (constraints-v const->type+axis) :y parent child modifiers transformed-parent-rect)] - :always - (gmt/translate-matrix))) + ;; Build final child modifiers. Apply transform again to the result, to get the + ;; real modifiers that need to be applied to the child, including rotation as needed. + (cond-> {} + (or (contains? modifiers-h :displacement) + (contains? modifiers-v :displacement)) + (assoc :displacement (cond-> (gpt/point (get-in modifiers-h [:displacement :x] 0) + (get-in modifiers-v [:displacement :y] 0)) + (some? (:resize-transform modifiers)) + (gpt/transform (:resize-transform modifiers)) - (:resize-vector modifiers-h) - (assoc :resize-origin (:resize-origin modifiers-h) - :resize-vector (gpt/point (get-in modifiers-h [:resize-vector :x] 1) - (get-in modifiers-h [:resize-vector :y] 1))) + :always + (gmt/translate-matrix))) - (:resize-vector modifiers-v) - (assoc :resize-origin-2 (:resize-origin modifiers-v) - :resize-vector-2 (gpt/point (get-in modifiers-v [:resize-vector :x] 1) - (get-in modifiers-v [:resize-vector :y] 1))) + (:resize-vector modifiers-h) + (assoc :resize-origin (:resize-origin modifiers-h) + :resize-vector (gpt/point (get-in modifiers-h [:resize-vector :x] 1) + (get-in modifiers-h [:resize-vector :y] 1))) - (:resize-transform modifiers) - (assoc :resize-transform (:resize-transform modifiers) - :resize-transform-inverse (:resize-transform-inverse modifiers)) + (:resize-vector modifiers-v) + (assoc :resize-origin-2 (:resize-origin modifiers-v) + :resize-vector-2 (gpt/point (get-in modifiers-v [:resize-vector :x] 1) + (get-in modifiers-v [:resize-vector :y] 1))) - :always - (clean-modifiers)))) + (:resize-transform modifiers) + (assoc :resize-transform (:resize-transform modifiers) + :resize-transform-inverse (:resize-transform-inverse modifiers)) + + :always + (clean-modifiers))))) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 058f1b42c..6b2cc9d22 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -356,22 +356,27 @@ [modif-tree shape modifiers] (let [children (map (d/getf objects) (:shapes shape)) - modifiers (cond-> modifiers snap-pixel? (set-pixel-precision shape)) transformed-rect (gsh/transform-selrect (:selrect shape) modifiers) set-child - (fn [modif-tree child] - (let [child-modifiers (gsh/calc-child-modifiers shape child modifiers ignore-constraints transformed-rect)] + (fn [snap-pixel? modif-tree child] + (let [child-modifiers (gsh/calc-child-modifiers shape child modifiers ignore-constraints transformed-rect) + child-modifiers (cond-> child-modifiers snap-pixel? (set-pixel-precision child))] (cond-> modif-tree (not (gsh/empty-modifiers? child-modifiers)) (set-modifiers-rec child child-modifiers)))) modif-tree (-> modif-tree - (assoc-in [(:id shape) :modifiers] modifiers))] + (assoc-in [(:id shape) :modifiers] modifiers)) - (reduce set-child modif-tree children)))] - (set-modifiers-rec modif-tree shape modifiers))) + resize-modif? + (or (:resize-vector modifiers) (:resize-vector-2 modifiers))] + + (reduce (partial set-child (and snap-pixel? resize-modif?)) modif-tree children)))] + + (let [modifiers (cond-> modifiers snap-pixel? (set-pixel-precision shape))] + (set-modifiers-rec modif-tree shape modifiers)))) (defn- get-ignore-tree "Retrieves a map with the flag `ignore-geometry?` given a tree of modifiers" diff --git a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs index b78c3967a..f799bf63b 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts.cljs @@ -28,9 +28,12 @@ (defn strip-position-data [shape] (dissoc shape :position-data :transform :transform-inverse)) +(defn strip-modifier + [modifier] + (d/update-when modifier :modifiers dissoc :displacement :rotation)) + (defn process-shape [modifiers {:keys [id] :as shape}] - (let [modifier (get modifiers id) - modifier (d/update-when modifier :modifiers dissoc :displacement :rotation) + (let [modifier (-> (get modifiers id) strip-modifier) shape (cond-> shape (not (gsh/empty-modifiers? (:modifiers modifier))) (-> (assoc :grow-type :fixed) @@ -117,11 +120,16 @@ text-change? (fn [id] (let [old-shape (get prev-text-shapes id) - new-shape (get text-shapes id)] + new-shape (get text-shapes id) + old-modifiers (-> (get prev-modifiers id) strip-modifier) + new-modifiers (-> (get modifiers id) strip-modifier)] (or (and (not (identical? old-shape new-shape)) (not= old-shape new-shape)) - (not= (get modifiers id) - (get prev-modifiers id))))) + + ;; The shape has changed only if its modifier is not empty and it's different + (and (not= new-modifiers old-modifiers) + (or (not (gsh/empty-modifiers? (:modifiers old-modifiers))) + (not (gsh/empty-modifiers? (:modifiers new-modifiers)))))))) changed-texts (mf/use-memo