diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index d786ca874..11391183d 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -119,7 +119,7 @@ (filter #(= (:page %) pageid)) (remove :hidden) (remove :blocked) - (map sh/-outer-rect) + (map sh/outer-rect') (filter #(sh/contained-in? % selrect)) (map :id))] (->> (into #{} xf (vals (:shapes-by-id state))) @@ -152,7 +152,7 @@ rs/UpdateEvent (-apply-update [_ state] (let [shape (get-in state [:shapes-by-id sid])] - (update-in state [:shapes-by-id sid] sh/-move delta))))) + (update-in state [:shapes-by-id sid] sh/move delta))))) (defn update-line-attrs [sid {:keys [x1 y1 x2 y2] :as opts}] @@ -163,7 +163,7 @@ (let [shape (get-in state [:shapes-by-id sid]) props (select-keys opts [:x1 :y1 :x2 :y2]) props' (select-keys shape [:x1 :y1 :x2 :y2])] - (update-in state [:shapes-by-id sid] sh/-initialize + (update-in state [:shapes-by-id sid] sh/initialize (merge props' props)))))) (defn update-rotation @@ -175,7 +175,7 @@ rs/UpdateEvent (-apply-update [_ state] (update-in state [:shapes-by-id sid] - sh/-rotate rotation)))) + sh/rotate rotation)))) (defn update-size "A helper event just for update the position @@ -190,8 +190,8 @@ rs/UpdateEvent (-apply-update [_ state] (let [shape (get-in state [:shapes-by-id sid]) - size (merge (sh/-size shape) opts)] - (update-in state [:shapes-by-id sid] sh/-resize' size))))) + size (merge (sh/size shape) opts)] + (update-in state [:shapes-by-id sid] sh/resize' size))))) (defn update-position "Update the start position coordenate of the shape." @@ -200,7 +200,7 @@ (reify rs/UpdateEvent (-apply-update [_ state] - (update-in state [:shapes-by-id sid] sh/-move' opts)))) + (update-in state [:shapes-by-id sid] sh/move' opts)))) (defn update-fill-attrs [sid {:keys [color opacity] :as opts}] diff --git a/src/uxbox/shapes.cljs b/src/uxbox/shapes.cljs index 287a8b705..3ed46ed56 100644 --- a/src/uxbox/shapes.cljs +++ b/src/uxbox/shapes.cljs @@ -31,27 +31,27 @@ [shape & params] (:type shape)) -(defmulti -move +(defmulti move dispatch-by-type :hierarchy #'+hierarchy+) -(defmulti -move' +(defmulti move' dispatch-by-type :hierarchy #'+hierarchy+) -(defmulti -resize +(defmulti resize dispatch-by-type :hierarchy #'+hierarchy+) -(defmulti -resize' +(defmulti resize' dispatch-by-type :hierarchy #'+hierarchy+) -(defmulti -size +(defmulti size dispatch-by-type :hierarchy #'+hierarchy+) -(defmulti -rotate +(defmulti rotate dispatch-by-type :hierarchy #'+hierarchy+) @@ -60,7 +60,7 @@ ;; for calculate the shape or shapes selection ;; rectangle. -(defmulti -outer-rect +(defmulti outer-rect' dispatch-by-type :hierarchy #'+hierarchy+) @@ -68,7 +68,7 @@ ;; from initial shape data structure and final ;; canvas position. -(defmulti -initialize +(defmulti initialize dispatch-by-type :hierarchy #'+hierarchy+) @@ -82,7 +82,7 @@ ;; Initialize -(defmethod -initialize ::shape +(defmethod initialize ::shape [shape {:keys [x1 y1 x2 y2]}] (assoc shape :x1 x1 @@ -92,11 +92,11 @@ ;; :width (- x2 x1) ;; :height (- y2 y1))) -(defmethod -initialize :builtin/group +(defmethod initialize :builtin/group [shape {:keys [x1 y1 x2 y2] :as props}] (assoc shape ::initial props)) -(defmethod -initialize :builtin/line +(defmethod initialize :builtin/line [shape {:keys [x1 y1 x2 y2]}] (assoc shape :x1 x1 @@ -104,7 +104,7 @@ :x2 x2 :y2 y2)) -(defmethod -initialize :builtin/circle +(defmethod initialize :builtin/circle [shape {:keys [x1 y1 x2 y2]}] (assoc shape :cx x1 @@ -114,11 +114,11 @@ ;; FIXME: lock mode -(defmethod -resize :builtin/line +(defmethod resize :builtin/line [shape {:keys [x y] :as pos}] (assoc shape :x2 x :y2 y)) -(defmethod -resize :builtin/circle +(defmethod resize :builtin/circle [shape {:keys [x y lock] :as pos}] (let [cx (:cx shape) cy (:cy shape) @@ -129,17 +129,17 @@ (assoc shape :rx rx :ry rx) (assoc shape :rx rx :ry ry)))) -(defmethod -resize :builtin/rect +(defmethod resize :builtin/rect [shape {:keys [x y lock] :as pos}] (if lock (assoc shape :x2 x :y2 x) (assoc shape :x2 x :y2 y))) -(defmethod -resize :default +(defmethod resize :default [shape _] (throw (ex-info "Not implemented" (select-keys shape [:type])))) -(defmethod -resize' ::rect +(defmethod resize' ::rect [shape {:keys [width height] :as size}] (let [x1 (:x1 shape) y1 (:y1 shape)] @@ -147,22 +147,22 @@ :x2 (+ x1 width) :y2 (+ y1 height)))) -(defmethod -resize' :default +(defmethod resize' :default [shape _] (throw (ex-info "Not implemented" (select-keys shape [:type])))) -(defmethod -size ::rect +(defmethod size ::rect [{:keys [x1 y1 x2 y2] :as shape}] {:width (- x2 x1) :height (- y2 y1)}) -(defmethod -size :default +(defmethod size :default [shape _] (throw (ex-info "Not implemented" (select-keys shape [:type])))) ;; Move -(defmethod -move ::rect +(defmethod move ::rect [shape {dx :x dy :y}] (assoc shape :x1 (+ (:x1 shape) dx) @@ -170,13 +170,13 @@ :x2 (+ (:x2 shape) dx) :y2 (+ (:y2 shape) dy))) -(defmethod -move :builtin/group +(defmethod move :builtin/group [shape {dx :x dy :y}] (assoc shape :dx (+ (:dx shape 0) dx) :dy (+ (:dy shape 0) dy))) -(defmethod -move :builtin/line +(defmethod move :builtin/line [shape {dx :x dy :y}] (assoc shape :x1 (+ (:x1 shape) dx) @@ -184,54 +184,54 @@ :x2 (+ (:x2 shape) dx) :y2 (+ (:y2 shape) dy))) -(defmethod -move :builtin/circle +(defmethod move :builtin/circle [shape {dx :x dy :y}] (assoc shape :cx (+ (:cx shape) dx) :cy (+ (:cy shape) dy))) -(defmethod -move :default +(defmethod move :default [shape _] (throw (ex-info "Not implemented" (select-keys shape [:type])))) -(defmethod -move' ::rect +(defmethod move' ::rect [shape {:keys [x y] :as pos}] (let [dx (if x (- (:x1 shape) x) 0) dy (if y (- (:y1 shape) y) 0)] - (-move shape (gpt/point dx dy)))) + (move shape (gpt/point dx dy)))) -(defmethod -move' :builtin/line +(defmethod move' :builtin/line [shape {:keys [x y] :as pos}] (let [dx (if x (- (:x1 shape) x) 0) dy (if y (- (:y1 shape) y) 0)] - (-move shape (gpt/point dx dy)))) + (move shape (gpt/point dx dy)))) -(defmethod -move' :builtin/circle +(defmethod move' :builtin/circle [shape {:keys [x y] :as pos}] (let [dx (if x (- (:cx shape) x) 0) dy (if y (- (:cy shape) y) 0)] - (-move shape (gpt/point dx dy)))) + (move shape (gpt/point dx dy)))) -(defmethod -move' :default +(defmethod move' :default [shape _] (throw (ex-info "Not implemented" (select-keys shape [:type])))) -(defmethod -rotate ::shape +(defmethod rotate ::shape [shape rotation] (assoc shape :rotation rotation)) (declare container-rect) -(defmethod -outer-rect ::shape +(defmethod outer-rect' ::shape [{:keys [group] :as shape}] (let [group (get-in @st/state [:shapes-by-id group])] (as-> shape $ (assoc $ :x (+ (:x1 shape) (:dx group 0))) (assoc $ :y (+ (:y1 shape) (:dy group 0))) - (merge $ (-size $)) + (merge $ (size $)) (container-rect $)))) -(defmethod -outer-rect :builtin/line +(defmethod outer-rect' :builtin/line [{:keys [x1 y1 x2 y2 group] :as shape}] (let [group (get-in @st/state [:shapes-by-id group]) props {:x (+ x1 (:dx group 0)) @@ -241,7 +241,7 @@ (-> (merge shape props) (container-rect)))) -(defmethod -outer-rect :builtin/circle +(defmethod outer-rect' :builtin/circle [{:keys [cx cy rx ry group] :as shape}] (let [group (get-in @st/state [:shapes-by-id group]) props {:x (+ (- cx rx) (:dx group 0)) @@ -251,11 +251,11 @@ (-> (merge shape props) (container-rect)))) -(defmethod -outer-rect :builtin/group +(defmethod outer-rect' :builtin/group [{:keys [id group rotation dx dy] :as shape}] (let [shapes (->> (:items shape) (map #(get-in @st/state [:shapes-by-id %])) - (map -outer-rect)) + (map outer-rect')) x (apply min (map :x shapes)) y (apply min (map :y shapes)) x' (apply max (map (fn [{:keys [x width]}] (+ x width)) shapes)) @@ -271,13 +271,13 @@ }) (container-rect $))))) -(defmethod -outer-rect :default +(defmethod outer-rect' :default [shape _] (throw (ex-info "Not implemented" (select-keys shape [:type])))) (defmethod -transformation :builtin/icon [{:keys [x1 y1 rotation view-box] :or {rotation 0} :as shape}] - (let [{:keys [width height]} (-size shape) + (let [{:keys [width height]} (size shape) orig-width (nth view-box 2) orig-height (nth view-box 3) scale-x (/ width orig-width) @@ -293,7 +293,7 @@ (defmethod -transformation :builtin/rect [{:keys [x1 y1 rotation] :or {rotation 0} :as shape}] - (let [{:keys [width height]} (-size shape) + (let [{:keys [width height]} (size shape) center-x (+ x1 (/ width 2)) center-y (+ y1 (/ height 2))] (-> (gmt/matrix) @@ -408,7 +408,7 @@ (defn outer-rect [shapes] {:pre [(seq shapes)]} - (let [shapes (map -outer-rect shapes) + (let [shapes (map outer-rect' shapes) x (apply min (map :x shapes)) y (apply min (map :y shapes)) x' (apply max (map (fn [{:keys [x width]}] (+ x width)) shapes)) diff --git a/src/uxbox/ui/shapes/icon.cljs b/src/uxbox/ui/shapes/icon.cljs index aa84868db..e71975ab3 100644 --- a/src/uxbox/ui/shapes/icon.cljs +++ b/src/uxbox/ui/shapes/icon.cljs @@ -88,7 +88,7 @@ (defn- handlers-render [own shape] - (let [{:keys [x y width height]} (sh/-outer-rect shape)] + (let [{:keys [x y width height]} (sh/outer-rect' shape)] (html [:g.controls [:rect {:x x :y y :width width :height height :stroke-dasharray "5,5" diff --git a/src/uxbox/ui/shapes/rect.cljs b/src/uxbox/ui/shapes/rect.cljs index 65d03f27b..10ba3a63e 100644 --- a/src/uxbox/ui/shapes/rect.cljs +++ b/src/uxbox/ui/shapes/rect.cljs @@ -16,7 +16,7 @@ [{:keys [id x1 y1 x2 y2] :as shape}] (let [key (str id) rfm (ush/-transformation shape) - size (ush/-size shape) + size (ush/size shape) props {:x x1 :y y1 :id key :key key :transform (str rfm)} attrs (-> (uusc/extract-style-attrs shape) (merge props size))] diff --git a/src/uxbox/ui/workspace/canvas/draw.cljs b/src/uxbox/ui/workspace/canvas/draw.cljs index 7501dd8c9..ba79912c4 100644 --- a/src/uxbox/ui/workspace/canvas/draw.cljs +++ b/src/uxbox/ui/workspace/canvas/draw.cljs @@ -26,7 +26,7 @@ (let [shape (rum/react +drawing-shape+) position (rum/react +drawing-position+)] (when shape - (-> (ush/-resize shape position) + (-> (ush/resize shape position) (uusc/render-shape identity))))) (def ^:static draw-area @@ -45,7 +45,7 @@ (define-once :drawing-subscriptions (letfn [(init-shape [shape] (let [{:keys [x y] :as point} @wb/mouse-canvas-a - shape (ush/-initialize shape {:x1 x :y1 y :x2 x :y2 y})] + shape (ush/initialize shape {:x1 x :y1 y :x2 x :y2 y})] (reset! +drawing-shape+ shape) (reset! +drawing-position+ (assoc point :lock false)) @@ -63,7 +63,7 @@ (on-complete [] (let [shape @+drawing-shape+ shpos @+drawing-position+ - shape (ush/-resize shape shpos)] + shape (ush/resize shape shpos)] (rs/emit! (dw/add-shape shape) (dw/select-for-drawing nil)) (reset! +drawing-position+ nil) @@ -72,7 +72,7 @@ (init-icon [shape] (let [{:keys [x y]} @wb/mouse-canvas-a props {:x1 x :y1 y :x2 (+ x 100) :y2 (+ y 100)} - shape (ush/-initialize shape props)] + shape (ush/initialize shape props)] (rs/emit! (dw/add-shape shape) (dw/select-for-drawing nil)))) (init [] diff --git a/src/uxbox/ui/workspace/sidebar/options.cljs b/src/uxbox/ui/workspace/sidebar/options.cljs index af522cf52..2f5c3eb90 100644 --- a/src/uxbox/ui/workspace/sidebar/options.cljs +++ b/src/uxbox/ui/workspace/sidebar/options.cljs @@ -190,7 +190,7 @@ sid (:id shape) props {attr value}] (rs/emit! (dw/update-radius-attrs sid props))))] - (let [size (sh/-size shape)] + (let [size (sh/size shape)] (html [:div.element-set {:key (str (:id menu))} [:div.element-set-title (:name menu)] @@ -282,7 +282,7 @@ sid (:id shape) props {attr value}] (rs/emit! (dw/update-position sid props))))] - (let [size (sh/-size shape)] + (let [size (sh/size shape)] (html [:div.element-set {:key (str (:id menu))} [:div.element-set-title (:name menu)]