diff --git a/frontend/uxbox/data/workspace.cljs b/frontend/uxbox/data/workspace.cljs index 0eb6635ac..d12bfb8ed 100644 --- a/frontend/uxbox/data/workspace.cljs +++ b/frontend/uxbox/data/workspace.cljs @@ -1,10 +1,11 @@ (ns uxbox.data.workspace - (:require [uxbox.rstore :as rs] + (:require [bouncer.validators :as v] + [uxbox.rstore :as rs] [uxbox.router :as r] [uxbox.state :as st] [uxbox.schema :as sc] [uxbox.time :as time] - [bouncer.validators :as v])) + [uxbox.shapes :as shapes])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Schemas @@ -127,14 +128,11 @@ (-pr-writer [mv writer _] (-write writer "#")))) -(defn apply-delta +(defn move-shape "Mark a shape selected for drawing in the canvas." [sid [dx dy :as delta]] (reify rs/UpdateEvent (-apply-update [_ state] (let [shape (get-in state [:shapes-by-id sid])] - (update-in state [:shapes-by-id sid] merge - {:x (+ (:x shape) dx) - :y (+ (:y shape) dy)}))))) - + (update-in state [:shapes-by-id sid] shapes/-move {:dx dx :dy dy}))))) diff --git a/frontend/uxbox/shapes.cljs b/frontend/uxbox/shapes.cljs index 40214290b..986b56732 100644 --- a/frontend/uxbox/shapes.cljs +++ b/frontend/uxbox/shapes.cljs @@ -21,9 +21,7 @@ ;; Api ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defmulti -render - (fn [shape attrs] - (:type shape))) +(declare -render) (defn render ([shape] (-render shape nil)) @@ -33,6 +31,18 @@ ;; Implementation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defn- dispatch-by-type + [shape props] + (:type shape)) + +(defmulti -render + dispatch-by-type + :hierarchy #'+hierarchy+) + +(defmulti -move + dispatch-by-type + :hierarchy #'+hierarchy+) + (defn transform-attrs [{:keys [view-box] :as data}] (if view-box @@ -65,3 +75,8 @@ [:svg attrs [:image image]]))) +(defmethod -move ::shape + [shape {:keys [dx dy] :as opts}] + (assoc shape + :x (+ (:x shape) dx) + :y (+ (:y shape) dy))) diff --git a/frontend/uxbox/ui/workspace/base.cljs b/frontend/uxbox/ui/workspace/base.cljs index 6c1646bdf..8d8fc342e 100644 --- a/frontend/uxbox/ui/workspace/base.cljs +++ b/frontend/uxbox/ui/workspace/base.cljs @@ -91,8 +91,8 @@ (as-> mouse-delta-s $ (rx/filter #(deref shapes-dragging?) $) (rx/on-value $ (fn [delta] - (doseq [id @selected-state] - (rs/emit! (dw/apply-delta id delta))))))) + (doseq [sid @selected-state] + (rs/emit! (dw/move-shape sid delta))))))) ;; Materialized views