mirror of
https://github.com/penpot/penpot.git
synced 2025-02-14 19:19:09 -05:00
✨ Changed grid render for performance
This commit is contained in:
parent
6a077c967a
commit
4513033634
2 changed files with 27 additions and 26 deletions
|
@ -81,7 +81,7 @@
|
||||||
(when component
|
(when component
|
||||||
[:> component (obj/set! props "key" index)
|
[:> component (obj/set! props "key" index)
|
||||||
(for [[index child] (d/enumerate children)]
|
(for [[index child] (d/enumerate children)]
|
||||||
(let [props (-> props
|
(let [props (-> (obj/clone props)
|
||||||
(obj/set! "node" child)
|
(obj/set! "node" child)
|
||||||
(obj/set! "index" index))]
|
(obj/set! "index" index))]
|
||||||
[:> render-node props]))])))))
|
[:> render-node props]))])))))
|
||||||
|
|
|
@ -15,35 +15,36 @@
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.util.geom.grid :as gg]))
|
[app.util.geom.grid :as gg]
|
||||||
|
[app.common.uuid :as uuid]))
|
||||||
|
|
||||||
(mf/defc square-grid [{:keys [frame zoom grid] :as props}]
|
(mf/defc square-grid [{:keys [frame zoom grid] :as props}]
|
||||||
(let [{:keys [color size] :as params} (-> grid :params)
|
(let [grid-id (mf/use-memo #(uuid/next))
|
||||||
|
{:keys [color size] :as params} (-> grid :params)
|
||||||
{color-value :color color-opacity :opacity} (-> grid :params :color)
|
{color-value :color color-opacity :opacity} (-> grid :params :color)
|
||||||
;; Support for old color format
|
;; Support for old color format
|
||||||
color-value (or color-value (:value (get-in grid [:params :color :value])))
|
color-value (or color-value (:value (get-in grid [:params :color :value])))]
|
||||||
{frame-width :width frame-height :height :keys [x y]} frame]
|
|
||||||
(when (> size 0)
|
[:g.grid
|
||||||
[:g.grid
|
[:defs
|
||||||
[:*
|
[:pattern {:id grid-id
|
||||||
(for [xs (range size frame-width size)]
|
:x (:x frame)
|
||||||
[:line {:key (str (:id frame) "-y-" xs)
|
:y (:y frame)
|
||||||
:x1 (mth/round (+ x xs))
|
:width size
|
||||||
:y1 (mth/round y)
|
:height size
|
||||||
:x2 (mth/round (+ x xs))
|
:pattern-units "userSpaceOnUse"}
|
||||||
:y2 (mth/round (+ y frame-height))
|
[:path {:d (str "M " size " " 0 " "
|
||||||
:style {:stroke color-value
|
"L " 0 " " 0 " " 0 " " size " ")
|
||||||
:stroke-opacity color-opacity
|
:style {:fill "none"
|
||||||
:stroke-width (str (/ 1 zoom))}}])
|
:stroke color-value
|
||||||
(for [ys (range size frame-height size)]
|
:stroke-opacity color-opacity
|
||||||
[:line {:key (str (:id frame) "-x-" ys)
|
:stroke-width (str (/ 1 zoom))}}]]]
|
||||||
:x1 (mth/round x)
|
|
||||||
:y1 (mth/round (+ y ys))
|
[:rect {:x (:x frame)
|
||||||
:x2 (mth/round (+ x frame-width))
|
:y (:y frame)
|
||||||
:y2 (mth/round (+ y ys))
|
:width (:width frame)
|
||||||
:style {:stroke color-value
|
:height (:height frame)
|
||||||
:stroke-opacity color-opacity
|
:fill (str "url(#" grid-id ")")}]]))
|
||||||
:stroke-width (str (/ 1 zoom))}}])]])))
|
|
||||||
|
|
||||||
(mf/defc layout-grid [{:keys [key frame zoom grid]}]
|
(mf/defc layout-grid [{:keys [key frame zoom grid]}]
|
||||||
(let [{color-value :color color-opacity :opacity} (-> grid :params :color)
|
(let [{color-value :color color-opacity :opacity} (-> grid :params :color)
|
||||||
|
|
Loading…
Add table
Reference in a new issue