0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

Add lock mode for mouse resize interaction.

Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Andrey Antukh 2016-02-29 17:52:34 +02:00
parent 5c7188eeba
commit ffaca0f459
2 changed files with 37 additions and 38 deletions

View file

@ -117,7 +117,8 @@
:ry (mth/abs (- y2 y1))))
(defmethod move-vertex ::rect
[shape vid {dx :x dy :y}]
[shape vid {dx :x dy :y lock :lock}]
(let [[dx dy] (if lock [dx dx] [dx dy])]
(case vid
1 (assoc shape
:x1 (+ (:x1 shape) dx)
@ -130,10 +131,11 @@
:y2 (+ (:y2 shape) dy))
4 (assoc shape
:x2 (+ (:x2 shape) dx)
:y2 (+ (:y2 shape) dy))))
:y2 (+ (:y2 shape) dy)))))
(defmethod move-vertex :builtin/circle
[shape vid {dx :x dy :y}]
[shape vid {dx :x dy :y lock :lock}]
(let [[dx dy] (if lock [dx dx] [dx dy])]
(case vid
1 (assoc shape
:rx (- (:rx shape) dx)
@ -146,7 +148,7 @@
:ry (+ (:ry shape) dy))
4 (assoc shape
:rx (+ (:rx shape) dx)
:ry (+ (:ry shape) dy))))
:ry (+ (:ry shape) dy)))))
;; FIXME: lock mode

View file

@ -16,23 +16,20 @@
[uxbox.util.dom :as dom]))
(define-once :resize-subscriptions
(letfn [(init [{:keys [payload]}]
(println payload)
(let [stoper (->> uuc/actions-s
(letfn [(init [event]
(let [payload (:payload event)
stoper (->> uuc/actions-s
(rx/map :type)
(rx/pr-log "kaka:")
(rx/filter #(= :nothing %))
(rx/take 1))]
(as-> uuwb/mouse-delta-s $
(rx/take-until stoper $)
(rx/subscribe
$ #(on-value payload %) nil on-complete))))
(rx/with-latest-from vector uuwb/mouse-ctrl-s $)
(rx/subscribe $ #(on-value payload %)))))
(on-complete []
(println "on-complete"))
(on-value [{:keys [vid shape]} delta]
(let [params {:vid vid :delta delta}]
(on-value [{:keys [vid shape]} [delta ctrl?]]
(let [params {:vid vid :delta (assoc delta :lock ctrl?)}]
(rs/emit! (uds/update-vertex-position shape params))))]
(as-> uuc/actions-s $