mirror of
https://github.com/penpot/penpot.git
synced 2025-03-19 19:21:23 -05:00
Fix alignment initialization and flags management on workspace.
Fixes issue #47.
This commit is contained in:
parent
f82ddac72d
commit
51fd90c64d
2 changed files with 36 additions and 32 deletions
frontend/src/uxbox/main/data
|
@ -11,6 +11,7 @@
|
|||
[potok.core :as ptk]
|
||||
[uxbox.main.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.lenses :as ul]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.main.workers :as uwrk]
|
||||
|
@ -141,19 +142,23 @@
|
|||
|
||||
(declare apply-temporal-displacement)
|
||||
|
||||
(defn initial-align-shape
|
||||
|
||||
(deftype InitialShapeAlign [id]
|
||||
ptk/WatchEvent
|
||||
(watch [_ state s]
|
||||
(let [{:keys [x1 y1] :as shape} (->> (get-in state [:shapes id])
|
||||
(geom/shape->rect-shape state))
|
||||
point1 (gpt/point x1 y1)
|
||||
point2 (gpt/add point1 canvas-coords)]
|
||||
(->> (uwrk/align-point point2)
|
||||
(rx/map #(gpt/subtract % canvas-coords))
|
||||
(rx/map (fn [{:keys [x y] :as pt}]
|
||||
(apply-temporal-displacement id (gpt/subtract pt point1))))))))
|
||||
|
||||
(defn initial-shape-align
|
||||
[id]
|
||||
(reify
|
||||
ptk/WatchEvent
|
||||
(watch [_ state s]
|
||||
(let [{:keys [x1 y1] :as shape} (->> (get-in state [:shapes id])
|
||||
(geom/shape->rect-shape state))
|
||||
point1 (gpt/point x1 y1)
|
||||
point2 (gpt/add point1 canvas-coords)]
|
||||
(->> (uwrk/align-point point2)
|
||||
(rx/map #(gpt/subtract % canvas-coords))
|
||||
(rx/map (fn [{:keys [x y] :as pt}]
|
||||
(apply-temporal-displacement id (gpt/subtract pt point1)))))))))
|
||||
{:pre [(uuid? id)]}
|
||||
(InitialShapeAlign. id))
|
||||
|
||||
(defn update-rotation
|
||||
[sid rotation]
|
||||
|
@ -649,13 +654,10 @@
|
|||
|
||||
;; --- Move Selected
|
||||
|
||||
(defn alignment-activated?
|
||||
;; TODO: use the function defined in uxbox.main.refs
|
||||
(defn- alignment-activated?
|
||||
[state]
|
||||
(let [flags (l/focus ul/workspace-flags state)]
|
||||
(and (contains? flags :grid-indexed)
|
||||
(contains? flags :grid-alignment)
|
||||
(contains? flags :grid))))
|
||||
(refs/alignment-activated? flags)))
|
||||
|
||||
(defn- get-displacement
|
||||
"Retrieve the correct displacement delta point for the
|
||||
|
@ -678,6 +680,11 @@
|
|||
:fast (gpt/point (if align? (* 3 gx) 10)
|
||||
(if align? (* 3 gy) 10))}))
|
||||
|
||||
;; --- Move Selected
|
||||
|
||||
;; Event used for apply displacement transformation
|
||||
;; to the selected shapes throught the keyboard shortcuts.
|
||||
|
||||
(deftype MoveSelected [direction speed]
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
|
@ -690,7 +697,7 @@
|
|||
(rx/concat
|
||||
(when align?
|
||||
(rx/concat
|
||||
(rx/from-coll (map initial-align-shape selected))
|
||||
(rx/from-coll (map initial-shape-align selected))
|
||||
(rx/from-coll (map apply-displacement selected))))
|
||||
(rx/from-coll (map #(apply-temporal-displacement % displacement) selected))
|
||||
(rx/from-coll (map apply-displacement selected))))))
|
||||
|
|
|
@ -273,22 +273,19 @@
|
|||
(defrecord InitializeAlignment [id]
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [page (get-in state [:pages id])
|
||||
opts (:metadata page)
|
||||
(let [{:keys [metadata] :as page} (get-in state [:pages id])
|
||||
params {:width c/viewport-width
|
||||
:height c/viewport-height
|
||||
:x-axis (:grid-x-axis opts c/grid-x-axis)
|
||||
:y-axis (:grid-y-axis opts c/grid-y-axis)}
|
||||
stoper (->> (rx/filter initialize-alignment? stream)
|
||||
(rx/take 1))]
|
||||
(->> (rx/just nil)
|
||||
(rx/delay 1000)
|
||||
(rx/take-until stoper)
|
||||
(rx/flat-map (fn [_]
|
||||
(rx/merge (->> (uwrk/initialize-alignment params)
|
||||
(rx/map #(activate-flag :grid-indexed)))
|
||||
(when (:grid-alignment opts)
|
||||
(rx/of (activate-flag :grid-alignment))))))))))
|
||||
:x-axis (:grid-x-axis metadata c/grid-x-axis)
|
||||
:y-axis (:grid-y-axis metadata c/grid-y-axis)}]
|
||||
(rx/merge
|
||||
(rx/of (deactivate-flag :grid-indexed)
|
||||
(if (:grid-alignment metadata)
|
||||
(activate-flag :grid-alignment)
|
||||
(deactivate-flag :grid-alignment)))
|
||||
|
||||
(->> (uwrk/initialize-alignment params)
|
||||
(rx/map #(activate-flag :grid-indexed)))))))
|
||||
|
||||
(defn initialize-alignment?
|
||||
[v]
|
||||
|
|
Loading…
Add table
Reference in a new issue