🔧 Adapt shapes to use new rumext macros.

This commit is contained in:
Andrey Antukh 2019-08-07 20:12:35 +02:00
parent 204f180ec9
commit fada526f5d
13 changed files with 225 additions and 344 deletions

View file

@ -2,34 +2,31 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.ui.shapes.path
(:require [potok.core :as ptk]
[cuerdas.core :as str :include-macros true]
[uxbox.main.geom :as geom]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.shapes.common :as common]
[uxbox.main.ui.shapes.attrs :as attrs]
[uxbox.util.data :refer [classnames normalize-props]]
[uxbox.util.geom.matrix :as gmt]
[uxbox.util.geom.point :as gpt]
[rumext.core :as mx :include-macros true]))
(:require
[cuerdas.core :as str :include-macros true]
[rumext.alpha :as mf]
[uxbox.main.data.shapes :as uds]
[uxbox.main.geom :as geom]
[uxbox.main.refs :as refs]
[uxbox.main.store :as st]
[uxbox.main.ui.shapes.attrs :as attrs]
[uxbox.main.ui.shapes.common :as common]
[uxbox.util.data :refer [classnames normalize-props]]
[uxbox.util.geom.matrix :as gmt]
[uxbox.util.geom.point :as gpt]))
;; --- Path Component
(declare path-shape)
(mx/defc path-component
{:mixins [mx/static mx/reactive]}
(mf/defc path-component
[{:keys [id] :as shape}]
(let [modifiers (mx/react (refs/selected-modifiers id))
selected (mx/react refs/selected-shapes)
selected? (contains? selected id)
shape (assoc shape
:modifiers modifiers
:background? true)]
(let [modifiers (mf/deref (refs/selected-modifiers id))
selected (mf/deref refs/selected-shapes)
selected? (contains? selected id)]
(letfn [(on-mouse-down [event]
(common/on-mouse-down event shape selected))
(on-double-click [event]
@ -38,7 +35,9 @@
[:g.shape {:class (when selected? "selected")
:on-double-click on-double-click
:on-mouse-down on-mouse-down}
(path-shape shape)])))
[:& path-shape {:shape shape
:modifiers modifiers
:background? true}]])))
;; --- Path Shape
@ -63,9 +62,8 @@
buffer (conj buffer (str/istr "L~{x},~{y}"))]
(recur buffer (inc index)))))))
(mx/defc path-shape
{:mixins [mx/static]}
[{:keys [id modifiers background?] :as shape}]
(mf/defc path-shape
[{:keys [shape modifiers background?] :as props}]
(let [{:keys [resize displacement]} modifiers
shape (cond-> shape
displacement (geom/transform displacement)
@ -73,13 +71,13 @@
moving? (boolean displacement)
pdata (render-path shape)
props {:id (str id)
props {:id (str (:id shape))
:class (classnames :move-cursor moving?)
:d pdata}
attrs (merge (attrs/extract-style-attrs shape) props)]
(if background?
[:g {}
[:g
[:path {:stroke "transparent"
:fill "transparent"
:stroke-width "20px"