0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-23 07:16:07 -05:00

🐛 Fix scaling frame proportionally

This commit is contained in:
Aitor 2023-03-07 16:35:42 +01:00 committed by alonso.torres
parent 4eeef41ed4
commit 44c35e6aee
2 changed files with 19 additions and 15 deletions

View file

@ -635,28 +635,32 @@
matrix)))] matrix)))]
(recur matrix (next modifiers))))))) (recur matrix (next modifiers)))))))
(defn transform-text-node [value attrs]
(let [font-size (-> (get attrs :font-size 14)
(d/parse-double)
(* value)
(str))]
(d/txt-merge attrs {:font-size font-size})))
(defn update-text-content
[shape scale-text-content value]
(update shape :content scale-text-content value))
(defn apply-structure-modifiers (defn apply-structure-modifiers
"Apply structure changes to a shape" "Apply structure changes to a shape"
[shape modifiers] [shape modifiers]
(letfn [(scale-text-content (letfn [(scale-text-content
[content value] [content value]
(->> content (->> content
(txt/transform-nodes (txt/transform-nodes
txt/is-text-node? txt/is-text-node?
(fn [attrs] (partial transform-text-node value))))
(let [font-size (-> (get attrs :font-size 14)
(d/parse-double)
(* value)
(str)) ]
(d/txt-merge attrs {:font-size font-size}))))))
(apply-scale-content (apply-scale-content
[shape value] [shape value]
(cond-> shape (cond-> shape
(cph/text-shape? shape) (cph/text-shape? shape)
(update :content scale-text-content value) (update-text-content scale-text-content value)
(cph/rect-shape? shape) (cph/rect-shape? shape)
(gsc/update-corners-scale value) (gsc/update-corners-scale value)
@ -666,7 +670,7 @@
(d/not-empty? (:shadow shape)) (d/not-empty? (:shadow shape))
(gse/update-shadows-scale value) (gse/update-shadows-scale value)
(some? (:blur shape)) (some? (:blur shape))
(gse/update-blur-scale value)))] (gse/update-blur-scale value)))]
@ -698,7 +702,6 @@
(let [value (dm/get-prop operation :value)] (let [value (dm/get-prop operation :value)]
(update shape :shapes remove-children value)) (update shape :shapes remove-children value))
:scale-content :scale-content
(let [value (dm/get-prop operation :value)] (let [value (dm/get-prop operation :value)]
(apply-scale-content shape value)) (apply-scale-content shape value))

View file

@ -104,7 +104,8 @@
(defn start-resize (defn start-resize
"Enter mouse resize mode, until mouse button is released." "Enter mouse resize mode, until mouse button is released."
[handler ids shape] [handler ids shape]
(letfn [(resize [shape initial layout [point lock? center? point-snap]] (letfn [(resize
[shape initial layout [point lock? center? point-snap]]
(let [{:keys [width height]} (:selrect shape) (let [{:keys [width height]} (:selrect shape)
{:keys [rotation]} shape {:keys [rotation]} shape
@ -192,7 +193,7 @@
(ctm/scale-content (:x scalev)))) (ctm/scale-content (:x scalev))))
modif-tree (dwm/create-modif-tree ids modifiers)] modif-tree (dwm/create-modif-tree ids modifiers)]
(rx/of (dwm/set-modifiers modif-tree)))) (rx/of (dwm/set-modifiers modif-tree (and (= :frame (:type shape)) scale-text)))))
;; Unifies the instantaneous proportion lock modifier ;; Unifies the instantaneous proportion lock modifier
;; activated by Shift key and the shapes own proportion ;; activated by Shift key and the shapes own proportion
@ -209,7 +210,7 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [initial-position @ms/mouse-position (let [initial-position @ms/mouse-position
stoper (rx/filter ms/mouse-up? stream) stopper (rx/filter ms/mouse-up? stream)
layout (:workspace-layout state) layout (:workspace-layout state)
page-id (:current-page-id state) page-id (:current-page-id state)
focus (:workspace-focus-selected state) focus (:workspace-focus-selected state)
@ -226,7 +227,7 @@
(->> (snap/closest-snap-point page-id resizing-shapes objects layout zoom focus point) (->> (snap/closest-snap-point page-id resizing-shapes objects layout zoom focus point)
(rx/map #(conj current %))))) (rx/map #(conj current %)))))
(rx/mapcat (partial resize shape initial-position layout)) (rx/mapcat (partial resize shape initial-position layout))
(rx/take-until stoper)) (rx/take-until stopper))
(rx/of (dwm/apply-modifiers) (rx/of (dwm/apply-modifiers)
(finish-transform)))))))) (finish-transform))))))))