mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 09:01:37 +02:00
Fix many inconsistencies between drawing and resizing.
This enables sharing code between the drawing logic and the simple resizing. Allowing drawing in any direction, not only from top-left to bottom-right. Fixes issue #44.
This commit is contained in:
parent
b7253b7fd5
commit
f82ddac72d
16 changed files with 291 additions and 321 deletions
|
@ -23,12 +23,6 @@
|
|||
[uxbox.util.geom.path :as path]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
||||
;; --- Refs
|
||||
|
||||
(def drawing-shape
|
||||
(-> (l/key :drawing)
|
||||
(l/derive refs/workspace)))
|
||||
|
||||
;; --- Components
|
||||
|
||||
(declare generic-draw-area)
|
||||
|
@ -37,25 +31,26 @@
|
|||
(mx/defc draw-area
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[zoom]
|
||||
(when-let [shape (mx/react drawing-shape)]
|
||||
(if (= (:type shape) :path)
|
||||
(path-draw-area shape)
|
||||
(generic-draw-area shape zoom))))
|
||||
(when-let [{:keys [id] :as shape} (mx/react refs/selected-drawing-shape)]
|
||||
(let [modifiers (mx/react (refs/selected-modifiers id))]
|
||||
(if (= (:type shape) :path)
|
||||
(path-draw-area shape)
|
||||
(-> (assoc shape :modifiers modifiers)
|
||||
(generic-draw-area zoom))))))
|
||||
|
||||
(mx/defc generic-draw-area
|
||||
[shape zoom]
|
||||
(let [{:keys [x1 y1 width height]} (geom/selection-rect shape)]
|
||||
[:g
|
||||
(-> (assoc shape :drawing? true)
|
||||
(shapes/render-component))
|
||||
(shapes/render-component shape)
|
||||
[:rect.main {:x x1 :y y1
|
||||
:width width
|
||||
:height height
|
||||
:stroke-dasharray (str (/ 5.0 zoom) "," (/ 5 zoom))
|
||||
:style {:stroke "#333" :fill "transparent"
|
||||
:style {:stroke "#333"
|
||||
:fill "transparent"
|
||||
:stroke-opacity "1"}}]]))
|
||||
|
||||
|
||||
(mx/defc path-draw-area
|
||||
[{:keys [segments] :as shape}]
|
||||
(letfn [(on-click [event]
|
||||
|
@ -68,8 +63,7 @@
|
|||
(st/emit! (udw/set-tooltip nil)))]
|
||||
(when-let [{:keys [x y] :as segment} (first segments)]
|
||||
[:g
|
||||
(-> (assoc shape :drawing? true)
|
||||
(shapes/render-component))
|
||||
(shapes/render-component shape)
|
||||
(when-not (:free shape)
|
||||
[:circle.close-bezier {:cx x
|
||||
:cy y
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue