0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

Add proportions related events to shapes events ns.

This commit is contained in:
Andrey Antukh 2016-09-29 07:10:42 +02:00
parent 69f258b4f4
commit a994dba165
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -166,6 +166,47 @@
(when color {:fill color})
(when opacity {:fill-opacity opacity})))))
(defn lock-proportions
"Mark proportions of the shape locked and save the current
proportion as additional precalculated property."
[sid]
{:pre [(uuid? sid)]}
(reify
udp/IPageUpdate
rs/UpdateEvent
(-apply-update [_ state]
(let [[width height] (-> (get-in state [:shapes-by-id sid])
(geom/size)
(keep [:width :height]))
proportion (/ width height)]
(update-in state [:shapes-by-id sid] assoc
:proportion proportion
:proportion-lock true)))))
(defn unlock-proportions
[sid]
{:pre [(uuid? sid)]}
(reify
udp/IPageUpdate
rs/UpdateEvent
(-apply-update [_ state]
(update-in state [:shapes-by-id sid] assoc
:proportion-lock false))))
(defn setup-proportions
[sid]
{:pre [(uuid? sid)]}
(reify
udp/IPageUpdate
rs/UpdateEvent
(-apply-update [_ state]
(let [[width height] (-> (get-in state [:shapes-by-id sid])
(geom/size)
(keep [:width :height]))
proportion (/ width height)]
(update-in state [:shapes-by-id sid] assoc
:proportion proportion)))))
(defn update-font-attrs
[sid {:keys [family style weight size align
letter-spacing line-height] :as opts}]