0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-04 19:11:20 -05:00

Add proper path edition behavior.

This commit is contained in:
Andrey Antukh 2016-08-23 16:26:44 +03:00
parent c1ae4348cd
commit 7875a6b961
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 53 additions and 13 deletions

View file

@ -19,6 +19,8 @@
[uxbox.main.state.shapes :as stsh]
[uxbox.main.data.core :refer (worker)]
[uxbox.main.data.pages :as udp]
;; FIXME: rlocks should be moved out of ui.workspace
[uxbox.main.ui.workspace.rlocks :as rlocks]
[uxbox.util.geom.point :as gpt]
[uxbox.util.data :refer (index-of)]))
@ -401,17 +403,43 @@
{:pre [(uuid? id) (number? index) (gpt/point? delta)]}
(UpdatePath. id index delta))
;; --- Start shape "edition mode"
(defrecord StartEditionMode [id]
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:workspace :edition] id))
rs/EffectEvent
(-apply-effect [_ state]
(rlocks/acquire! :shape/edition)))
(defn start-edition-mode
[id]
{:pre [(uuid? id)]}
(println "start-edition-mode" id)
(StartEditionMode. id))
;; --- Events (implicit) (for selected)
(defrecord DeselectAll []
rs/UpdateEvent
(-apply-update [_ state]
(-> state
(assoc-in [:workspace :selected] #{})
(assoc-in [:workspace :edition] nil)
(assoc-in [:workspace :drawing] nil)))
rs/EffectEvent
(-apply-effect [_ state]
(rlocks/release! :shape/edition)))
(defn deselect-all
"Mark a shape selected for drawing in the canvas."
"Clear all possible state of drawing, edition
or any similar action taken by the user."
[]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(-> state
(assoc-in [:workspace :selected] #{})
(assoc-in [:workspace :drawing] nil)))))
(println "deselect-all")
(DeselectAll.))
(defn group-selected
[]

View file

@ -17,7 +17,12 @@
[uxbox.main.geom :as geom]
[uxbox.util.dom :as dom]))
;; --- Lenses
;; --- Refs
;; (defonce edition-ref (atom nil))
(def edition-ref
(-> (l/in [:workspace :edition])
(l/derive st/state)))
(def drawing-state-ref
(-> (l/in [:workspace :drawing])

View file

@ -6,8 +6,10 @@
(ns uxbox.main.ui.shapes.path
(:require [uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.rstore :as rs]
[uxbox.main.ui.shapes.common :as common]
[uxbox.main.ui.shapes.attrs :as attrs]
[uxbox.main.data.shapes :as uds]
[uxbox.main.geom :as geom]))
;; --- Path Component
@ -18,11 +20,16 @@
{:mixins [mx/static mx/reactive]}
[{:keys [id] :as shape}]
(let [selected (mx/react common/selected-ref)
selected? (contains? selected id)
on-mouse-down #(common/on-mouse-down % shape selected)]
[:g.shape {:class (when selected? "selected")
:on-mouse-down on-mouse-down}
(path-shape shape identity)]))
selected? (contains? selected id)]
(letfn [(on-mouse-down [event]
(common/on-mouse-down event shape selected))
(on-double-click [event]
(when selected?
(rs/emit! (uds/start-edition-mode id))))]
[:g.shape {:class (when selected? "selected")
:on-double-click on-double-click
:on-mouse-down on-mouse-down}
(path-shape shape identity)])))
;; --- Path Shape