mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
Decouple shape moving logic.
This commit is contained in:
parent
e07ada5ad4
commit
7a71b088f4
3 changed files with 25 additions and 12 deletions
|
@ -1,10 +1,11 @@
|
|||
(ns uxbox.data.workspace
|
||||
(:require [uxbox.rstore :as rs]
|
||||
(:require [bouncer.validators :as v]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.router :as r]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.schema :as sc]
|
||||
[uxbox.time :as time]
|
||||
[bouncer.validators :as v]))
|
||||
[uxbox.shapes :as shapes]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Schemas
|
||||
|
@ -127,14 +128,11 @@
|
|||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.d.w/initialize>"))))
|
||||
|
||||
(defn apply-delta
|
||||
(defn move-shape
|
||||
"Mark a shape selected for drawing in the canvas."
|
||||
[sid [dx dy :as delta]]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [shape (get-in state [:shapes-by-id sid])]
|
||||
(update-in state [:shapes-by-id sid] merge
|
||||
{:x (+ (:x shape) dx)
|
||||
:y (+ (:y shape) dy)})))))
|
||||
|
||||
(update-in state [:shapes-by-id sid] shapes/-move {:dx dx :dy dy})))))
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
;; Api
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defmulti -render
|
||||
(fn [shape attrs]
|
||||
(:type shape)))
|
||||
(declare -render)
|
||||
|
||||
(defn render
|
||||
([shape] (-render shape nil))
|
||||
|
@ -33,6 +31,18 @@
|
|||
;; Implementation
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- dispatch-by-type
|
||||
[shape props]
|
||||
(:type shape))
|
||||
|
||||
(defmulti -render
|
||||
dispatch-by-type
|
||||
:hierarchy #'+hierarchy+)
|
||||
|
||||
(defmulti -move
|
||||
dispatch-by-type
|
||||
:hierarchy #'+hierarchy+)
|
||||
|
||||
(defn transform-attrs
|
||||
[{:keys [view-box] :as data}]
|
||||
(if view-box
|
||||
|
@ -65,3 +75,8 @@
|
|||
[:svg attrs
|
||||
[:image image]])))
|
||||
|
||||
(defmethod -move ::shape
|
||||
[shape {:keys [dx dy] :as opts}]
|
||||
(assoc shape
|
||||
:x (+ (:x shape) dx)
|
||||
:y (+ (:y shape) dy)))
|
||||
|
|
|
@ -91,8 +91,8 @@
|
|||
(as-> mouse-delta-s $
|
||||
(rx/filter #(deref shapes-dragging?) $)
|
||||
(rx/on-value $ (fn [delta]
|
||||
(doseq [id @selected-state]
|
||||
(rs/emit! (dw/apply-delta id delta)))))))
|
||||
(doseq [sid @selected-state]
|
||||
(rs/emit! (dw/move-shape sid delta)))))))
|
||||
|
||||
;; Materialized views
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue