mirror of
https://github.com/penpot/penpot.git
synced 2026-09-11 22:49:30 +00:00
Change the shapes moviment tracking approach.
Will facilitate grid alignment.
This commit is contained in:
parent
69329f7f64
commit
551c95b8fe
@ -8,16 +8,31 @@
|
|||||||
(ns uxbox.ui.workspace.movement
|
(ns uxbox.ui.workspace.movement
|
||||||
"Shape movement in workspace logic."
|
"Shape movement in workspace logic."
|
||||||
(:require [beicon.core :as rx]
|
(:require [beicon.core :as rx]
|
||||||
|
[lentes.core :as l]
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
[uxbox.state :as st]
|
[uxbox.state :as st]
|
||||||
|
[uxbox.shapes :as sh]
|
||||||
[uxbox.ui.core :as uuc]
|
[uxbox.ui.core :as uuc]
|
||||||
[uxbox.ui.workspace.base :as wb]
|
[uxbox.ui.workspace.base :as wb]
|
||||||
|
[uxbox.ui.workspace.align :as align]
|
||||||
[uxbox.data.shapes :as uds]
|
[uxbox.data.shapes :as uds]
|
||||||
[uxbox.util.geom.point :as gpt]))
|
[uxbox.util.geom.point :as gpt]))
|
||||||
|
|
||||||
(declare initialize)
|
(declare initialize)
|
||||||
(declare handle-movement)
|
(declare handle-movement)
|
||||||
|
|
||||||
|
;; --- Lenses
|
||||||
|
|
||||||
|
(defn- resolve-selected
|
||||||
|
[state]
|
||||||
|
(let [selected (get-in state [:workspace :selected])
|
||||||
|
xf (map #(get-in state [:shapes-by-id %]))]
|
||||||
|
(into #{} xf selected)))
|
||||||
|
|
||||||
|
(def ^:const ^:private selected-shapes-l
|
||||||
|
(-> (l/getter resolve-selected)
|
||||||
|
(l/focus-atom st/state)))
|
||||||
|
|
||||||
;; --- Public Api
|
;; --- Public Api
|
||||||
|
|
||||||
(defn watch-move-actions
|
(defn watch-move-actions
|
||||||
@ -30,22 +45,19 @@
|
|||||||
|
|
||||||
(defn- initialize
|
(defn- initialize
|
||||||
[]
|
[]
|
||||||
(let [stoper (->> uuc/actions-s
|
(let [shapes @selected-shapes-l
|
||||||
|
stoper (->> uuc/actions-s
|
||||||
(rx/map :type)
|
(rx/map :type)
|
||||||
(rx/filter empty?)
|
(rx/filter empty?)
|
||||||
(rx/take 1))]
|
(rx/take 1))]
|
||||||
(as-> wb/mouse-delta-s $
|
(as-> wb/mouse-delta-s $
|
||||||
(rx/take-until stoper $)
|
(rx/take-until stoper $)
|
||||||
(rx/on-value $ handle-movement))))
|
(rx/scan (fn [acc delta]
|
||||||
|
(mapv #(sh/move % delta) acc)) shapes $)
|
||||||
|
(rx/subscribe $ handle-movement))))
|
||||||
|
|
||||||
(defn- handle-movement
|
(defn- handle-movement
|
||||||
[delta]
|
[delta]
|
||||||
(let [pageid (get-in @st/state [:workspace :page])
|
(doseq [shape delta]
|
||||||
selected (get-in @st/state [:workspace :selected])
|
(rs/emit! (uds/update-shape shape))))
|
||||||
shapes (->> (vals @wb/shapes-by-id-l)
|
|
||||||
(filter #(= (:page %) pageid))
|
|
||||||
(filter (comp selected :id)))
|
|
||||||
delta (gpt/divide delta @wb/zoom-l)]
|
|
||||||
(doseq [{:keys [id group]} shapes]
|
|
||||||
(rs/emit! (uds/move-shape id delta)))))
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user