mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 22:31:38 +02:00
Rename :points
attr to :segments
on path shape.
This commit is contained in:
parent
340a5b3da2
commit
e8fcb38597
5 changed files with 48 additions and 39 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
(ns uxbox.main.ui.shapes.path
|
||||
(:require [potok.core :as ptk]
|
||||
[cuerdas.core :as str :include-macros true]
|
||||
[uxbox.main.store :as st]
|
||||
[uxbox.main.ui.shapes.common :as common]
|
||||
[uxbox.main.ui.shapes.attrs :as attrs]
|
||||
|
@ -14,7 +15,6 @@
|
|||
[uxbox.util.geom.matrix :as gmt]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.mixins :as mx :include-macros true]))
|
||||
|
||||
;; --- Path Component
|
||||
|
||||
(declare path-shape)
|
||||
|
@ -39,12 +39,25 @@
|
|||
;; --- Path Shape
|
||||
|
||||
(defn- render-path
|
||||
[{:keys [points close?] :as shape}]
|
||||
(let [start (first points)
|
||||
init (str "M " (:x start) " " (:y start))
|
||||
path (reduce #(str %1 " L" (:x %2) " " (:y %2)) init points)]
|
||||
(cond-> path
|
||||
close? (str " Z"))))
|
||||
[{:keys [segments close?] :as shape}]
|
||||
(let [numsegs (count segments)]
|
||||
(loop [buffer []
|
||||
index 0]
|
||||
(cond
|
||||
(>= index numsegs)
|
||||
(if close?
|
||||
(str/join " " (conj buffer "Z"))
|
||||
(str/join " " buffer))
|
||||
|
||||
(zero? index)
|
||||
(let [{:keys [x y] :as segment} (nth segments index)
|
||||
buffer (conj buffer (str/istr "M~{x},~{y}"))]
|
||||
(recur buffer (inc index)))
|
||||
|
||||
:else
|
||||
(let [{:keys [x y] :as segment} (nth segments index)
|
||||
buffer (conj buffer (str/istr "L~{x},~{y}"))]
|
||||
(recur buffer (inc index)))))))
|
||||
|
||||
(mx/defc path-shape
|
||||
{:mixins [mx/static]}
|
||||
|
|
|
@ -327,12 +327,12 @@
|
|||
(rx/subscribe stream on-move))))
|
||||
|
||||
(mx/defc path-edition-selection-handlers
|
||||
[{:keys [id points] :as shape} zoom]
|
||||
[{:keys [id segments] :as shape} zoom]
|
||||
(letfn [(on-mouse-down [index event]
|
||||
(dom/stop-propagation event)
|
||||
(start-path-edition id index))]
|
||||
[:g.controls
|
||||
(for [[index {:keys [x y]}] (map-indexed vector points)]
|
||||
(for [[index {:keys [x y]}] (map-indexed vector segments)]
|
||||
[:circle {:cx x :cy y
|
||||
:r (/ 6.0 zoom)
|
||||
:on-mouse-down (partial on-mouse-down index)
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
(shapes/render-component)))
|
||||
|
||||
(mx/defc path-draw-area
|
||||
[{:keys [points] :as shape}]
|
||||
[{:keys [segments] :as shape}]
|
||||
(letfn [(on-click [event]
|
||||
(dom/stop-propagation event)
|
||||
(st/emit! (udw/set-tooltip nil)
|
||||
|
@ -56,12 +56,8 @@
|
|||
(on-mouse-enter [event]
|
||||
(st/emit! (udw/set-tooltip "Click to close the path")))
|
||||
(on-mouse-leave [event]
|
||||
(st/emit! (udw/set-tooltip nil)))
|
||||
(drop-last-point [shape]
|
||||
(let [points (:points shape)
|
||||
points (vec (butlast points))]
|
||||
(assoc shape :points points :close? true)))]
|
||||
(when-let [{:keys [x y]} (first points)]
|
||||
(st/emit! (udw/set-tooltip nil)))]
|
||||
(when-let [{:keys [x y] :as segment} (first segments)]
|
||||
[:g
|
||||
(-> (assoc shape :drawing? true)
|
||||
(shapes/render-component))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue