0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 12:59:12 -05:00

Make update-size event work with different types of shapes.

Thanks to the previously added `resize-dim` geom helpers.
This commit is contained in:
Andrey Antukh 2016-09-29 07:06:03 +02:00
parent b3207b5746
commit e30871bd48
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -108,25 +108,14 @@
(defn update-size (defn update-size
"A helper event just for update the position "A helper event just for update the position
of the shape using the width and heigt attrs of the shape using the width and height attrs
instread final point of coordinates. instread final point of coordinates."
[sid opts]
WARN: only works with shapes that works
with height and width such are ::rect"
[sid {:keys [width height] :as opts}]
(reify (reify
udp/IPageUpdate udp/IPageUpdate
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(letfn [(resize [shape {:keys [width height] :as size}] (update-in state [:shapes-by-id sid] geom/resize-dim opts))))
(let [x1 (:x1 shape)
y1 (:y1 shape)]
(assoc shape
:x2 (+ x1 width)
:y2 (+ y1 height))))]
(let [shape (get-in state [:shapes-by-id sid])
size (merge (geom/size shape) opts)]
(update-in state [:shapes-by-id sid] resize size))))))
(defn update-vertex-position (defn update-vertex-position
[id {:keys [vid delta]}] [id {:keys [vid delta]}]