Improved shape component for proper handle shapes in groups.

This commit is contained in:
Andrey Antukh 2016-01-22 19:38:44 +02:00
parent 84d87dcc4f
commit 42073077ee

View file

@ -8,7 +8,7 @@
[uxbox.rstore :as rs] [uxbox.rstore :as rs]
[uxbox.state :as st] [uxbox.state :as st]
[uxbox.xforms :as xf] [uxbox.xforms :as xf]
[uxbox.shapes :as shapes] [uxbox.shapes :as sh]
[uxbox.util.lens :as ul] [uxbox.util.lens :as ul]
[uxbox.library.icons :as _icons] [uxbox.library.icons :as _icons]
[uxbox.data.projects :as dp] [uxbox.data.projects :as dp]
@ -49,35 +49,60 @@
;; Shape ;; Shape
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declare shape)
(defn shape-render (defn shape-render
[own shape selected] [own item selected]
(let [{:keys [id x y width height] :as shape} shape (let [{:keys [id x y width height group] :as item} item
selected? (contains? selected id)] selected? (contains? selected id)
local (:rum/local own)]
(letfn [(on-mouse-down [event] (letfn [(on-mouse-down [event]
(when-not (:blocked shape) (when-not (:blocked item)
(let [local (:rum/local own)] ;; (let [local (:rum/local own)]
;; (swap! local assoc :init-coords [x y])
;; (reset! wb/shapes-dragging? true))
(cond
(and group (:locked (sh/resolve-parent item)))
nil
(and (not selected?) (empty? selected))
(do
(dom/stop-propagation event) (dom/stop-propagation event)
(swap! local assoc :init-coords [x y]) (swap! local assoc :init-coords [x y])
(reset! wb/shapes-dragging? true)) (reset! wb/shapes-dragging? true)
(cond
(and (not selected?)
(empty? selected))
(rs/emit! (dw/select-shape id))
(and (not selected?) (rs/emit! (dw/select-shape id)))
(not (empty? selected)))
(and (not selected?) (not (empty? selected)))
(do
(dom/stop-propagation event)
(swap! local assoc :init-coords [x y])
(reset! wb/shapes-dragging? true)
(if (.-ctrlKey event) (if (.-ctrlKey event)
(rs/emit! (dw/select-shape id)) (rs/emit! (dw/select-shape id))
(rs/emit! (dw/deselect-all) (rs/emit! (dw/deselect-all)
(dw/select-shape id)))))) (dw/select-shape id))))
(on-mouse-up [event]
:else
(do
(dom/stop-propagation event) (dom/stop-propagation event)
(reset! wb/shapes-dragging? false))] (swap! local assoc :init-coords [x y])
(reset! wb/shapes-dragging? true)))))
(on-mouse-up [event]
(cond
(and group (:locked (sh/resolve-parent item)))
nil
:else
(do
(dom/stop-propagation event)
(reset! wb/shapes-dragging? false))))]
(html (html
[:g.shape {:class (when selected? "selected") [:g.shape {:class (when selected? "selected")
:on-mouse-down on-mouse-down :on-mouse-down on-mouse-down
:on-mouse-up on-mouse-up} :on-mouse-up on-mouse-up}
(shapes/-render shape nil)])))) (sh/-render item #(shape % selected))]))))
(def ^:static shape (def ^:static shape
(mx/component (mx/component