mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 22:22:43 -05:00
Simplify grid call arguments.
This commit is contained in:
parent
4a1c7ab2c9
commit
2a2fcb1a75
1 changed files with 14 additions and 25 deletions
|
@ -55,14 +55,14 @@
|
||||||
(def ^:static grid-color "#cccccc")
|
(def ^:static grid-color "#cccccc")
|
||||||
|
|
||||||
(defn grid-render
|
(defn grid-render
|
||||||
[own enabled? width height start-width start-height zoom]
|
[own enabled? zoom]
|
||||||
(letfn [(vertical-line [position value padding]
|
(letfn [(vertical-line [position value padding]
|
||||||
(let [ticks-mod (/ 100 zoom)
|
(let [ticks-mod (/ 100 zoom)
|
||||||
step-size (/ 10 zoom)]
|
step-size (/ 10 zoom)]
|
||||||
(if (< (mod value ticks-mod) step-size)
|
(if (< (mod value ticks-mod) step-size)
|
||||||
(html [:line {:key position
|
(html [:line {:key position
|
||||||
:y1 padding
|
:y1 padding
|
||||||
:y2 width
|
:y2 wb/viewport-width
|
||||||
:x1 position
|
:x1 position
|
||||||
:x2 position
|
:x2 position
|
||||||
:stroke grid-color
|
:stroke grid-color
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
:opacity 0.75}])
|
:opacity 0.75}])
|
||||||
(html [:line {:key position
|
(html [:line {:key position
|
||||||
:y1 padding
|
:y1 padding
|
||||||
:y2 width
|
:y2 wb/viewport-width
|
||||||
:x1 position
|
:x1 position
|
||||||
:x2 position
|
:x2 position
|
||||||
:stroke grid-color
|
:stroke grid-color
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
:y1 position
|
:y1 position
|
||||||
:y2 position
|
:y2 position
|
||||||
:x1 padding
|
:x1 padding
|
||||||
:x2 height
|
:x2 wb/viewport-height
|
||||||
:stroke grid-color
|
:stroke grid-color
|
||||||
:stroke-width (/ 0.5 zoom)
|
:stroke-width (/ 0.5 zoom)
|
||||||
:opacity 0.75}])
|
:opacity 0.75}])
|
||||||
|
@ -92,30 +92,31 @@
|
||||||
:y1 position
|
:y1 position
|
||||||
:y2 position
|
:y2 position
|
||||||
:x1 padding
|
:x1 padding
|
||||||
:x2 height
|
:x2 wb/viewport-height
|
||||||
:stroke grid-color
|
:stroke grid-color
|
||||||
:stroke-width (/ 0.5 zoom)
|
:stroke-width (/ 0.5 zoom)
|
||||||
:opacity 0.25}]))))]
|
:opacity 0.25}]))))]
|
||||||
(let [padding (* 20 zoom)
|
(let [padding (* 20 zoom)
|
||||||
ticks-mod (/ 100 zoom)
|
ticks-mod (/ 100 zoom)
|
||||||
step-size (/ 10 zoom)
|
step-size (/ 10 zoom)
|
||||||
vertical-ticks (range (- padding start-height)
|
vertical-ticks (range (- padding wb/document-start-y)
|
||||||
(- height start-height padding) step-size)
|
(- wb/viewport-height wb/document-start-y padding)
|
||||||
horizontal-ticks (range (- padding start-width)
|
step-size)
|
||||||
(- width start-width padding) step-size)]
|
horizontal-ticks (range (- padding wb/document-start-x)
|
||||||
|
(- wb/viewport-width wb/document-start-x padding)
|
||||||
|
step-size)]
|
||||||
(html
|
(html
|
||||||
[:g.grid
|
[:g.grid
|
||||||
{:style {:display (if enabled? "block" "none")}}
|
{:style {:display (if enabled? "block" "none")}}
|
||||||
(for [tick vertical-ticks]
|
(for [tick vertical-ticks]
|
||||||
(let [position (+ tick start-width)
|
(let [position (+ tick wb/document-start-x)
|
||||||
line (vertical-line position tick padding)]
|
line (vertical-line position tick padding)]
|
||||||
(rum/with-key line (str "tick-" tick))))
|
(rum/with-key line (str "tick-" tick))))
|
||||||
(for [tick horizontal-ticks]
|
(for [tick horizontal-ticks]
|
||||||
(let [position (+ tick start-height)
|
(let [position (+ tick wb/document-start-y)
|
||||||
line (horizontal-line position tick padding)]
|
line (horizontal-line position tick padding)]
|
||||||
(rum/with-key line (str "tick-" tick))))]))))
|
(rum/with-key line (str "tick-" tick))))]))))
|
||||||
|
|
||||||
|
|
||||||
(def grid
|
(def grid
|
||||||
(util/component
|
(util/component
|
||||||
{:render grid-render
|
{:render grid-render
|
||||||
|
@ -198,19 +199,7 @@
|
||||||
[:g.zoom
|
[:g.zoom
|
||||||
{:transform (str "scale(" zoom ", " zoom ")")}
|
{:transform (str "scale(" zoom ", " zoom ")")}
|
||||||
(canvas)
|
(canvas)
|
||||||
#_(canvas conn
|
(grid (:grid-enabled workspace false) zoom)]])))
|
||||||
page
|
|
||||||
shapes
|
|
||||||
{:viewport-height wb/viewport-height
|
|
||||||
:viewport-width wb/viewport-width
|
|
||||||
:document-start-x wb/document-start-x
|
|
||||||
:document-start-y wb/document-start-y})
|
|
||||||
(grid (:grid-enabled workspace false)
|
|
||||||
wb/viewport-width
|
|
||||||
wb/viewport-height
|
|
||||||
wb/document-start-x
|
|
||||||
wb/document-start-y
|
|
||||||
zoom)]])))
|
|
||||||
|
|
||||||
(def viewport
|
(def viewport
|
||||||
(util/component
|
(util/component
|
||||||
|
|
Loading…
Add table
Reference in a new issue