0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -05:00

Add collapsing group shape events.

And reorganize a little bit the shapes events ns.
This commit is contained in:
Andrey Antukh 2016-09-30 11:34:57 +02:00
parent 819fa69ae2
commit c617fba52b
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -23,6 +23,8 @@
[uxbox.util.geom.point :as gpt] [uxbox.util.geom.point :as gpt]
[uxbox.util.data :refer (index-of)])) [uxbox.util.data :refer (index-of)]))
;; --- Shapes CRUD
(defn add-shape (defn add-shape
"Create and add shape to the current selected page." "Create and add shape to the current selected page."
[shape] [shape]
@ -53,6 +55,8 @@
(-apply-update [_ state] (-apply-update [_ state]
(update-in state [:shapes-by-id id] merge shape)))) (update-in state [:shapes-by-id id] merge shape))))
;; --- Shape Transformations
(defn move-shape (defn move-shape
"Move shape using relative position (delta)." "Move shape using relative position (delta)."
[sid delta] [sid delta]
@ -166,6 +170,50 @@
(when color {:fill color}) (when color {:fill color})
(when opacity {:fill-opacity opacity}))))) (when opacity {:fill-opacity opacity})))))
(defn update-font-attrs
[sid {:keys [family style weight size align
letter-spacing line-height] :as opts}]
(reify
udp/IPageUpdate
rs/UpdateEvent
(-apply-update [_ state]
(update-in state [:shapes-by-id sid :font]
merge
(when line-height {:line-height line-height})
(when letter-spacing {:letter-spacing letter-spacing})
(when align {:align align})
(when family {:family family})
(when style {:style style})
(when weight {:weight weight})
(when size {:size size})))))
(defn update-stroke-attrs
[sid {:keys [color opacity type width] :as opts}]
(reify
udp/IPageUpdate
rs/UpdateEvent
(-apply-update [_ state]
(update-in state [:shapes-by-id sid]
merge
(when type {:stroke-type type})
(when width {:stroke-width width})
(when color {:stroke color})
(when opacity {:stroke-opacity opacity})))))
(defn update-radius-attrs
[sid {:keys [rx ry] :as opts}]
(reify
udp/IPageUpdate
rs/UpdateEvent
(-apply-update [_ state]
(update-in state [:shapes-by-id sid]
merge
(when rx {:rx rx})
(when ry {:ry ry})))))
;; --- Shape Proportions
(defn lock-proportions (defn lock-proportions
"Mark proportions of the shape locked and save the current "Mark proportions of the shape locked and save the current
proportion as additional precalculated property." proportion as additional precalculated property."
@ -207,46 +255,27 @@
(update-in state [:shapes-by-id sid] assoc (update-in state [:shapes-by-id sid] assoc
:proportion proportion))))) :proportion proportion)))))
(defn update-font-attrs ;; --- Group Collapsing
[sid {:keys [family style weight size align
letter-spacing line-height] :as opts}]
(reify
udp/IPageUpdate
rs/UpdateEvent
(-apply-update [_ state]
(update-in state [:shapes-by-id sid :font]
merge
(when line-height {:line-height line-height})
(when letter-spacing {:letter-spacing letter-spacing})
(when align {:align align})
(when family {:family family})
(when style {:style style})
(when weight {:weight weight})
(when size {:size size})))))
(defn update-stroke-attrs (defn collapse-shape
[sid {:keys [color opacity type width] :as opts}] [id]
{:pre [(uuid? id)]}
(reify (reify
udp/IPageUpdate udp/IPageUpdate
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(update-in state [:shapes-by-id sid] (update-in state [:shapes-by-id id] assoc :collapsed true))))
merge
(when type {:stroke-type type})
(when width {:stroke-width width})
(when color {:stroke color})
(when opacity {:stroke-opacity opacity})))))
(defn update-radius-attrs (defn uncollapse-shape
[sid {:keys [rx ry] :as opts}] [id]
{:pre [(uuid? id)]}
(reify (reify
udp/IPageUpdate udp/IPageUpdate
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(update-in state [:shapes-by-id sid] (update-in state [:shapes-by-id id] assoc :collapsed false))))
merge
(when rx {:rx rx}) ;; --- Shape Visibility
(when ry {:ry ry})))))
(defn hide-shape (defn hide-shape
[sid] [sid]