mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 22:18:32 +02:00
Implement shapes moving using mouse.
This commit is contained in:
parent
17eafb8563
commit
a5dc634e35
4 changed files with 126 additions and 27 deletions
|
@ -63,6 +63,7 @@
|
|||
:project project
|
||||
:created (time/now :unix)
|
||||
:shapes []
|
||||
:shapes-by-id {}
|
||||
:name name
|
||||
:width width
|
||||
:height height}]
|
||||
|
|
|
@ -74,11 +74,13 @@
|
|||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(println "add-shape")
|
||||
(if-let [pageid (get-in state [:workspace :page])]
|
||||
(update-in state [:pages-by-id pageid :shapes] conj
|
||||
(merge shape props))
|
||||
state))
|
||||
(let [id (random-uuid)
|
||||
pageid (get-in state [:workspace :page])
|
||||
_ (assert pageid)
|
||||
shape (merge shape props {:id id})]
|
||||
(as-> state $
|
||||
(update-in $ [:pages-by-id pageid :shapes] conj id)
|
||||
(update-in $ [:pages-by-id pageid :shapes-by-id] assoc id shape))))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [mv writer _]
|
||||
|
@ -101,3 +103,29 @@
|
|||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.d.w/initialize>"))))
|
||||
|
||||
(defn apply-delta
|
||||
"Mark a shape selected for drawing in the canvas."
|
||||
[shapeid [dx dy :as delta]]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
;; (println "apply-delta" shapeid delta)
|
||||
(let [pageid (get-in state [:workspace :page])
|
||||
_ (assert pageid)
|
||||
shape (get-in state [:pages-by-id pageid :shapes-by-id shapeid])]
|
||||
(update-in state [:pages-by-id pageid :shapes-by-id shapeid] merge
|
||||
{:x (+ (:x shape) dx)
|
||||
:y (+ (:y shape) dy)})))))
|
||||
|
||||
|
||||
;; (defn apply-delta'
|
||||
;; "Mark a shape selected for drawing in the canvas."
|
||||
;; [shapeid [dx dy :as delta]]
|
||||
;; (reify
|
||||
;; rs/UpdateEvent
|
||||
;; (-apply-update [_ state]
|
||||
;; ;; (println "apply-delta'" shapeid delta)
|
||||
;; (let [pageid (get-in state [:workspace :page])
|
||||
;; shape (get-in state [:pages-by-id pageid :shapes-by-id shapeid])]
|
||||
;; (update-in state [:pages-by-id pageid :shapes-by-id shapeid] merge
|
||||
;; {:x dx :y dy})))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue