0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 16:00:19 -05:00

Add size change event for shape.

This commit is contained in:
Andrey Antukh 2016-01-06 21:03:59 +02:00
parent c364e35292
commit 06d0ea326b

View file

@ -24,6 +24,11 @@
:height [v/integer]
:type [v/required sc/shape-type]})
(def ^:static +shape-update-size-schema+
{:width [v/integer]
:height [v/integer]
:lock [v/boolean]})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -169,3 +174,19 @@
(-apply-update [_ state]
(let [shape (get-in state [:shapes-by-id sid])]
(update-in state [:shapes-by-id sid] shapes/-move {:dx dx :dy dy})))))
;; TODO: implement locked resize
(defn update-shape-size
[sid {:keys [width height lock] :as opts}]
(sc/validate! +shape-update-size-schema+ opts)
(reify
rs/UpdateEvent
(-apply-update [_ state]
(let [shape (get-in state [:shapes-by-id sid])
size (select-keys shape [:width :height])
size (merge size
(when width {:width width})
(when height {:height height}))]
(update-in state [:shapes-by-id sid]
shapes/-resize size)))))