mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 00:10:11 -05:00
✨ Improve panning code
This commit is contained in:
parent
7cb8eb783a
commit
1e0e0aabf2
1 changed files with 5 additions and 7 deletions
|
@ -10,7 +10,6 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.align :as gal]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.rect :as gpr]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.math :as mth]
|
||||
|
@ -150,19 +149,18 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [stopper (->> stream (rx/filter (ptk/type? ::finish-panning)))
|
||||
zoom (-> (get-in state [:workspace-local :zoom]) gpt/point)]
|
||||
zoom (get-in state [:workspace-local :zoom])]
|
||||
(when-not (get-in state [:workspace-local :panning])
|
||||
(rx/concat
|
||||
(rx/of #(-> % (assoc-in [:workspace-local :panning] true)))
|
||||
(->> stream
|
||||
(rx/filter mse/pointer-event?)
|
||||
(rx/filter #(= :delta (:source %)))
|
||||
(rx/map :pt)
|
||||
(rx/take-until stopper)
|
||||
(rx/map (fn [delta]
|
||||
(let [delta (gpt/divide delta zoom)]
|
||||
(update-viewport-position {:x #(- % (:x delta))
|
||||
:y #(- % (:y delta))})))))))))))
|
||||
(rx/map (fn [event]
|
||||
(let [delta (dm/get-prop event :pt)]
|
||||
(update-viewport-position {:x #(- % (/ (:x delta) zoom))
|
||||
:y #(- % (/ (:y delta) zoom))})))))))))))
|
||||
|
||||
(defn finish-panning []
|
||||
(ptk/reify ::finish-panning
|
||||
|
|
Loading…
Reference in a new issue