diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index aaeb83dc2..fd1838c69 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -198,7 +198,7 @@ (reify rs/UpdateEvent (-apply-update [_ state] - (let [size [width height]] + (let [size {:width width :height height}] (update-in state [:shapes-by-id sid] sh/-resize' size))))) (defn update-position diff --git a/src/uxbox/shapes.cljs b/src/uxbox/shapes.cljs index f44647e71..450b905af 100644 --- a/src/uxbox/shapes.cljs +++ b/src/uxbox/shapes.cljs @@ -116,38 +116,46 @@ ;; Resize (defmethod -resize :builtin/line - [shape [x2 y2]] + [shape {:keys [x2 y2] :as pos}] (assoc shape :x2 x2 :y2 y2)) (defmethod -resize :builtin/circle - [{:keys [cx cy rx ry] :as shape} [x2 y2]] + [{:keys [cx cy rx ry] :as shape} {:keys [x2 y2 lock] :as pos}] (let [x1 (- cx rx) y1 (- cy ry) width (- x2 x1) - height (- y2 y1) + height (if lock + width + (- y2 y1)) rx (/ width 2) ry (/ height 2) cx (+ x1 (/ width 2)) cy (+ y1 (/ height 2))] - (assoc shape :rx rx :ry ry :cx cx :cy cy))) + (if lock + (assoc shape :rx rx :ry ry :cx cx :cy cy) + (assoc shape :rx rx :ry ry :cx cx :cy cy)))) (defmethod -resize :builtin/rect - [shape [x2 y2]] + [shape {:keys [x2 y2 lock] :as pos}] (let [{:keys [x y]} shape] - (assoc shape - :width (- x2 x) - :height (- y2 y)))) + (if lock + (assoc shape + :width (- x2 x) + :height (- x2 x)) + (assoc shape + :width (- x2 x) + :height (- y2 y))))) (defmethod -resize :default [shape _] (throw (ex-info "Not implemented" (select-keys shape [:type])))) (defmethod -resize' ::rect - [shape [width height]] + [shape {:keys [width height] :as size}] (merge shape (when width {:width width}) (when height {:height height}))) diff --git a/src/uxbox/ui/workspace/canvas/draw.cljs b/src/uxbox/ui/workspace/canvas/draw.cljs index 017157697..0c9b46b86 100644 --- a/src/uxbox/ui/workspace/canvas/draw.cljs +++ b/src/uxbox/ui/workspace/canvas/draw.cljs @@ -22,9 +22,9 @@ (defn- draw-area-render [own] (let [shape (rum/react +drawing-shape+) - [x y] (rum/react +drawing-position+)] + position (rum/react +drawing-position+)] (when shape - (-> (sh/-resize shape [x y]) + (-> (sh/-resize shape position) (sh/-render identity))))) (def ^:static draw-area @@ -43,19 +43,21 @@ stop @wb/scroll-top y (+ stop y) shape (sh/-initialize shape {:x1 x :y1 y :x2 x :y2 y})] + (reset! +drawing-shape+ shape) - (reset! +drawing-position+ [x y]) + (reset! +drawing-position+ {:x2 x :y2 y :lock false}) (as-> wb/interactions-b $ (rx/filter #(not= % :shape/movement) $) (rx/take 1 $) (rx/take-until $ wb/mouse-s) + (rx/with-latest-from vector wb/mouse-ctrl-s $) (rx/subscribe $ on-value nil on-complete)))) - (on-value [[x y :as pos]] + (on-value [[[x y :as pos] ctrl?]] (let [stop @wb/scroll-top] (reset! +drawing-position+ - [x (+ y stop)]))) + {:x2 x :y2 (+ y stop) :lock ctrl?}))) (on-complete [] (let [shape @+drawing-shape+