mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 10:51:39 +02:00
✨ Minor performance changes on snap-distances ns.
This commit is contained in:
parent
2976bc4e5c
commit
da1179f628
1 changed files with 45 additions and 34 deletions
|
@ -1,20 +1,28 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.main.ui.workspace.snap-distances
|
(ns app.main.ui.workspace.snap-distances
|
||||||
(:require
|
(:require
|
||||||
[rumext.alpha :as mf]
|
[app.common.data :as d]
|
||||||
[beicon.core :as rx]
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.math :as mth]
|
||||||
|
[app.common.pages :as cp]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.snap :as snap]
|
[app.main.snap :as snap]
|
||||||
[app.util.geom.snap-points :as sp]
|
|
||||||
[app.common.geom.point :as gpt]
|
|
||||||
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[app.common.pages :as cp]
|
|
||||||
[app.common.data :as d]
|
|
||||||
[app.common.geom.shapes :as gsh]
|
|
||||||
[app.common.math :as mth]
|
|
||||||
[app.main.worker :as uw]
|
[app.main.worker :as uw]
|
||||||
[clojure.set :as set]))
|
[app.util.geom.snap-points :as sp]
|
||||||
|
[beicon.core :as rx]
|
||||||
|
[clojure.set :as set]
|
||||||
|
[cuerdas.core :as str]
|
||||||
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
(def ^:private line-color "#D383DA")
|
(def ^:private line-color "#D383DA")
|
||||||
(def ^:private segment-gap 2)
|
(def ^:private segment-gap 2)
|
||||||
|
@ -107,15 +115,14 @@
|
||||||
(mf/defc shape-distance
|
(mf/defc shape-distance
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [frame (unchecked-get props "frame")
|
(let [frame (unchecked-get props "frame")
|
||||||
selrect (unchecked-get props "selrect")
|
selrect (unchecked-get props "selrect")
|
||||||
page-id (unchecked-get props "page-id")
|
page-id (unchecked-get props "page-id")
|
||||||
zoom (unchecked-get props "zoom")
|
zoom (unchecked-get props "zoom")
|
||||||
coord (unchecked-get props "coord")
|
coord (unchecked-get props "coord")
|
||||||
selected (unchecked-get props "selected")
|
selected (unchecked-get props "selected")
|
||||||
;{:keys [frame selrect page-id zoom coord selected]}
|
|
||||||
|
|
||||||
subject (mf/use-memo #(rx/subject))
|
subject (mf/use-memo #(rx/subject))
|
||||||
to-measure (mf/use-state [])
|
to-measure (mf/use-state [])
|
||||||
|
|
||||||
pair->distance+pair
|
pair->distance+pair
|
||||||
|
@ -226,26 +233,30 @@
|
||||||
:zoom zoom}])))
|
:zoom zoom}])))
|
||||||
|
|
||||||
(mf/defc snap-distances
|
(mf/defc snap-distances
|
||||||
[{:keys [layout page-id zoom selected transform]}]
|
{::mf/wrap-props false}
|
||||||
(let [selected-shapes (mf/deref (refs/objects-by-id selected))
|
[props]
|
||||||
frame-id (-> selected-shapes first :frame-id)
|
(let [layout (unchecked-get props "layout")
|
||||||
frame (mf/deref (refs/object-by-id frame-id))]
|
page-id (unchecked-get props "page-id")
|
||||||
|
zoom (unchecked-get props "zoom")
|
||||||
|
selected (unchecked-get props "selected")
|
||||||
|
transform (unchecked-get props "transform")
|
||||||
|
selected-shapes (mf/deref (refs/objects-by-id selected))
|
||||||
|
frame-id (-> selected-shapes first :frame-id)
|
||||||
|
frame (mf/deref (refs/object-by-id frame-id))]
|
||||||
(when (and (contains? layout :dynamic-alignment)
|
(when (and (contains? layout :dynamic-alignment)
|
||||||
(= transform :move)
|
(= transform :move)
|
||||||
(not (empty? selected)))
|
(not (empty? selected)))
|
||||||
(let [shapes (->> selected-shapes (map gsh/transform-shape))
|
(let [shapes (map gsh/transform-shape selected-shapes)
|
||||||
selrect (gsh/selection-rect shapes)
|
selrect (gsh/selection-rect shapes)
|
||||||
key (->> selected (map str) (str/join "-"))]
|
key (->> selected (map str) (str/join "-"))]
|
||||||
[:g.distance
|
[:g.distance
|
||||||
[:& shape-distance
|
[:& shape-distance
|
||||||
{:selrect selrect
|
{:selrect selrect
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:frame frame
|
:frame frame
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:coord :x
|
:coord :x
|
||||||
:selected selected}]
|
:selected selected}]
|
||||||
|
|
||||||
[:& shape-distance
|
[:& shape-distance
|
||||||
{:selrect selrect
|
{:selrect selrect
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue