mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
♻️ Refactor selection start-resize event.
This commit is contained in:
parent
20364f47b4
commit
844c866642
1 changed files with 22 additions and 23 deletions
|
@ -10,6 +10,7 @@
|
||||||
(:require
|
(:require
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[lentes.core :as l]
|
[lentes.core :as l]
|
||||||
|
[potok.core :as ptk]
|
||||||
[rumext.alpha :as mf]
|
[rumext.alpha :as mf]
|
||||||
[uxbox.main.data.workspace :as dw]
|
[uxbox.main.data.workspace :as dw]
|
||||||
[uxbox.main.geom :as geom]
|
[uxbox.main.geom :as geom]
|
||||||
|
@ -32,19 +33,13 @@
|
||||||
|
|
||||||
;; --- Resize Implementation
|
;; --- Resize Implementation
|
||||||
|
|
||||||
;; TODO: this function need to be refactored
|
|
||||||
|
|
||||||
(defn- start-resize
|
(defn- start-resize
|
||||||
[vid ids shape]
|
[vid ids shape]
|
||||||
(letfn [(on-resize [shape [point lock?]]
|
(letfn [(resize [shape [point lock?]]
|
||||||
(let [result (geom/resize-shape vid shape point lock?)
|
(let [result (geom/resize-shape vid shape point lock?)
|
||||||
scale (geom/calculate-scale-ratio shape result)
|
scale (geom/calculate-scale-ratio shape result)
|
||||||
mtx (geom/generate-resize-matrix vid shape scale)
|
mtx (geom/generate-resize-matrix vid shape scale)]
|
||||||
xfm (map #(dw/assoc-temporal-modifier % mtx))]
|
(apply rx/of (map #(dw/assoc-temporal-modifier % mtx) ids))))
|
||||||
(apply st/emit! (sequence xfm ids))))
|
|
||||||
|
|
||||||
(on-end []
|
|
||||||
(apply st/emit! (map dw/materialize-current-modifier ids)))
|
|
||||||
|
|
||||||
;; Unifies the instantaneous proportion lock modifier
|
;; Unifies the instantaneous proportion lock modifier
|
||||||
;; activated by Ctrl key and the shapes own proportion
|
;; activated by Ctrl key and the shapes own proportion
|
||||||
|
@ -63,19 +58,23 @@
|
||||||
;; Apply the current zoom factor to the point.
|
;; Apply the current zoom factor to the point.
|
||||||
(apply-zoom [point]
|
(apply-zoom [point]
|
||||||
(gpt/divide point @refs/selected-zoom))]
|
(gpt/divide point @refs/selected-zoom))]
|
||||||
|
(reify
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [shape (->> (geom/shape->rect-shape shape)
|
||||||
|
(geom/size))
|
||||||
|
stoper (rx/filter ws/mouse-up? stream)]
|
||||||
|
(rx/concat
|
||||||
|
(->> ws/mouse-position
|
||||||
|
(rx/map apply-zoom)
|
||||||
|
(rx/mapcat apply-grid-alignment)
|
||||||
|
(rx/with-latest vector ws/mouse-position-ctrl)
|
||||||
|
(rx/map normalize-proportion-lock)
|
||||||
|
(rx/mapcat (partial resize shape))
|
||||||
|
(rx/take-until stoper))
|
||||||
|
(rx/from-coll (map dw/materialize-current-modifier ids))))))))
|
||||||
|
|
||||||
(let [shape (->> (geom/shape->rect-shape shape)
|
;; (rx/subscribe stream (partial on-resize shape) nil on-end))))
|
||||||
(geom/size))
|
|
||||||
stoper (->> st/stream
|
|
||||||
(rx/filter ws/mouse-up?)
|
|
||||||
(rx/take 1))
|
|
||||||
stream (->> ws/mouse-position
|
|
||||||
(rx/take-until stoper)
|
|
||||||
(rx/map apply-zoom)
|
|
||||||
(rx/mapcat apply-grid-alignment)
|
|
||||||
(rx/with-latest vector ws/mouse-position-ctrl)
|
|
||||||
(rx/map normalize-proportion-lock))]
|
|
||||||
(rx/subscribe stream (partial on-resize shape) nil on-end))))
|
|
||||||
|
|
||||||
;; --- Controls (Component)
|
;; --- Controls (Component)
|
||||||
|
|
||||||
|
@ -196,7 +195,7 @@
|
||||||
(geom/shapes->rect-shape)
|
(geom/shapes->rect-shape)
|
||||||
(geom/selection-rect))
|
(geom/selection-rect))
|
||||||
on-click #(do (dom/stop-propagation %2)
|
on-click #(do (dom/stop-propagation %2)
|
||||||
(start-resize %1 (map :id shapes) shape))]
|
(st/emit! (start-resize %1 (mapv :id shapes) shape)))]
|
||||||
[:& controls {:shape shape
|
[:& controls {:shape shape
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:on-click on-click}]))
|
:on-click on-click}]))
|
||||||
|
@ -217,7 +216,7 @@
|
||||||
(mf/defc single-selection-handlers
|
(mf/defc single-selection-handlers
|
||||||
[{:keys [shape zoom] :as props}]
|
[{:keys [shape zoom] :as props}]
|
||||||
(let [on-click #(do (dom/stop-propagation %2)
|
(let [on-click #(do (dom/stop-propagation %2)
|
||||||
(start-resize %1 #{(:id shape)} shape))
|
(st/emit! (start-resize %1 #{(:id shape)} shape)))
|
||||||
shape (geom/selection-rect shape)]
|
shape (geom/selection-rect shape)]
|
||||||
[:& controls {:shape shape :zoom zoom :on-click on-click}]))
|
[:& controls {:shape shape :zoom zoom :on-click on-click}]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue