Forward path edition state from vieweport to editor

This commit is contained in:
Andrey Antukh 2025-06-18 16:49:08 +02:00
parent f8d63f5d9d
commit db4721f692
4 changed files with 43 additions and 28 deletions

View File

@ -13,7 +13,6 @@
[app.common.types.path.helpers :as path.helpers]
[app.common.types.path.segment :as path.segment]
[app.main.data.workspace.path :as drp]
[app.main.refs :as refs]
[app.main.snap :as snap]
[app.main.store :as st]
[app.main.streams :as ms]
@ -23,7 +22,6 @@
[app.util.keyboard :as kbd]
[clojure.set :refer [map-invert]]
[goog.events :as events]
[okulary.core :as l]
[rumext.v2 :as mf]))
(def point-radius 5)
@ -260,17 +258,9 @@
angle (gpt/angle-with-other v1 v2)]
(<= (- 180 angle) 0.1))))
(defn- make-edit-path-ref [id]
(let [get-fn #(dm/get-in % [:edit-path id])]
(l/derived get-fn refs/workspace-local)))
(mf/defc path-editor*
[{:keys [shape zoom]}]
(let [shape-id (dm/get-prop shape :id)
edit-path-ref (mf/with-memo [shape-id]
(make-edit-path-ref shape-id))
hover-point (mf/use-state nil)
[{:keys [shape zoom state]}]
(let [hover-point (mf/use-state nil)
editor-ref (mf/use-ref nil)
{:keys [edit-mode
@ -284,9 +274,8 @@
moving-handler
hover-handlers
hover-points
snap-toggled]
:as edit-path}
(mf/deref edit-path-ref)
snap-toggled]}
state
selected-points
(or selected-points #{})

View File

@ -13,6 +13,7 @@
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.types.path :as path]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctt]
[app.common.types.shape.layout :as ctl]
[app.main.data.workspace.modifiers :as dwm]
@ -531,7 +532,8 @@
:on-frame-leave on-frame-leave
:on-frame-select on-frame-select}])
(when show-draw-area?
(when (and ^boolean show-draw-area?
^boolean (cts/shape? drawing-obj))
[:> drawarea/draw-area*
{:shape drawing-obj
:zoom zoom
@ -637,6 +639,7 @@
(when-not text-editing?
(if editing-shape
[:> path-editor* {:shape editing-shape
:state edit-path-state
:zoom zoom}]
(when selected-shapes
[:> selection/handlers*

View File

@ -7,13 +7,19 @@
(ns app.main.ui.workspace.viewport.drawarea
"Drawing components."
(:require
[app.common.data.macros :as dm]
[app.common.math :as mth]
[app.common.types.shape :as cts]
[app.main.refs :as refs]
[app.main.ui.shapes.path :refer [path-shape]]
[app.main.ui.workspace.shapes :as shapes]
[app.main.ui.workspace.shapes.path.editor :refer [path-editor*]]
[okulary.core :as l]
[rumext.v2 :as mf]))
(defn- make-edit-path-ref [id]
(let [get-fn #(dm/get-in % [:edit-path id])]
(l/derived get-fn refs/workspace-local)))
(mf/defc generic-draw-area*
{::mf/private true}
[{:keys [shape zoom]}]
@ -29,17 +35,32 @@
:fill "none"
:stroke-width (/ 1 zoom)}}])))
(mf/defc path-draw-area*
{::mf/private true}
[{:keys [shape] :as props}]
(let [shape-id
(dm/get-prop shape :id)
edit-path-ref
(mf/with-memo [shape-id]
(make-edit-path-ref shape-id))
edit-path-state
(mf/deref edit-path-ref)
props
(mf/spread-props props {:state edit-path-state})]
[:> path-editor* props]))
(mf/defc draw-area*
[{:keys [shape zoom tool] :as props}]
[:g.draw-area
[:g {:style {:pointer-events "none"}}
[:& shapes/shape-wrapper {:shape shape}]]
;; Prevent rendering something that it's not a shape.
(when (cts/shape? shape)
[:g.draw-area
[:g {:style {:pointer-events "none"}}
[:& shapes/shape-wrapper {:shape shape}]]
(case tool
:path [:> path-editor* props]
:curve [:& path-shape {:shape shape :zoom zoom}]
#_:default [:> generic-draw-area* props])]))
(case tool
:path [:> path-draw-area* props]
:curve [:& path-shape {:shape shape :zoom zoom}]
#_:default [:> generic-draw-area* props])])

View File

@ -522,7 +522,8 @@
:on-frame-leave on-frame-leave
:on-frame-select on-frame-select}])
(when show-draw-area?
(when (and ^boolean show-draw-area?
^boolean (cts/shape? drawing-obj))
[:> drawarea/draw-area*
{:shape drawing-obj
:zoom zoom
@ -628,6 +629,7 @@
(when-not text-editing?
(if editing-shape
[:> path-editor* {:shape editing-shape
:state edit-path-state
:zoom zoom}]
(when selected-shapes
[:> selection/handlers*