From 06d0ea326b12482cc745b817c36784e0d0ba4bb8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 6 Jan 2016 21:03:59 +0200 Subject: [PATCH] Add size change event for shape. --- frontend/uxbox/data/workspace.cljs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/frontend/uxbox/data/workspace.cljs b/frontend/uxbox/data/workspace.cljs index fb86ed5c0..aea5f0c0c 100644 --- a/frontend/uxbox/data/workspace.cljs +++ b/frontend/uxbox/data/workspace.cljs @@ -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)))))