diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index 8d9016c02..065bbd0ce 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -133,12 +133,12 @@ (-apply-update [_ state] (let [sid (random-uuid) pid (get-in state [:workspace :page]) - shape (merge shape props {:id sid :page pid})] + shape (merge (sh/-initialize shape props) + shape {:id sid :page pid})] (as-> state $ (update-in $ [:pages-by-id pid :shapes] conj sid) (assoc-in $ [:shapes-by-id sid] shape)))))) - (defn delete-shape "Remove the shape using its id." [id] diff --git a/src/uxbox/shapes.cljs b/src/uxbox/shapes.cljs index 44fa29c89..1e1b9186e 100644 --- a/src/uxbox/shapes.cljs +++ b/src/uxbox/shapes.cljs @@ -49,26 +49,62 @@ dispatch-by-type :hierarchy #'+hierarchy+) +;; Used for calculate the outer rect that wraps +;; up the whole underlying shape. Mostly used +;; for calculate the shape or shapes selection +;; rectangle. + (defmulti -outer-rect dispatch-by-type :hierarchy #'+hierarchy+) +;; Used for create the final shape data structure +;; from initial shape data structure and final +;; canvas position. + +(defmulti -initialize + dispatch-by-type + :hierarchy #'+hierarchy+) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Implementation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defmethod -initialize ::shape + [shape props] + (merge shape props)) + +(defmethod -initialize :builtin/line + [shape {:keys [x y width height]}] + (merge shape + {:x1 x :y1 y + :x2 (+ x width) + :y2 (+ y height)})) + (defmethod -move ::shape [shape {:keys [dx dy] :as opts}] (assoc shape :x (+ (:x shape) dx) :y (+ (:y shape) dy))) +(defmethod -move :builtin/line + [shape {:keys [dx dy] :as opts}] + (assoc shape + :x1 (+ (:x1 shape) dx) + :y1 (+ (:y1 shape) dy) + :x2 (+ (:x2 shape) dx) + :y2 (+ (:y2 shape) dy))) + (defmethod -resize ::shape [shape {:keys [width height] :as opts}] (assoc shape :width width :height height)) +(defmethod -resize :builtin/line + [shape {:keys [width height] :as opts}] + (throw (ex-info "Not implemented" {}))) + (defmethod -rotate ::shape [shape rotation] (assoc shape :rotation rotation)) diff --git a/src/uxbox/ui/shapes.cljs b/src/uxbox/ui/shapes.cljs index 7cc193cff..2998ebfbe 100644 --- a/src/uxbox/ui/shapes.cljs +++ b/src/uxbox/ui/shapes.cljs @@ -66,9 +66,10 @@ (defmethod shapes/-render :builtin/line [{:keys [id view-box] :as shape} _] (let [key (str id) - rfm (svg/calculate-transform shape) - attrs (merge (extract-attrs shape) - (make-debug-attrs shape))] + ;; rfm (svg/calculate-transform shape) + attrs (extract-attrs shape)] + ;; attrs (merge (extract-attrs shape) + ;; (make-debug-attrs shape))] (html [:g {:id key :key key} [:line attrs]]))) diff --git a/src/uxbox/ui/workspace/options.cljs b/src/uxbox/ui/workspace/options.cljs index a1da4e3c5..594ff4c61 100644 --- a/src/uxbox/ui/workspace/options.cljs +++ b/src/uxbox/ui/workspace/options.cljs @@ -17,7 +17,7 @@ {:builtin/icon [:menu/measures :menu/fill :menu/stroke] :builtin/rect [:menu/measures :menu/fill :menu/stroke] :builtin/circle [:menu/measures :menu/fill :menu/stroke] - :builtin/line [:menu/measures :menu/stroke] + :builtin/line [:menu/stroke] :builtin/group [:menu/measures]}) (def +menus-by-id+