🐛 Fixed some corner cases with grid parameters

This commit is contained in:
alonso.torres 2020-05-20 15:37:11 +02:00
parent cbfa60f2e7
commit 0611ce98a3
2 changed files with 13 additions and 5 deletions

View file

@ -42,7 +42,16 @@
:stroke-width (str (/ 1 zoom))}}])]]))) :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 :value color-opacity :opacity} (-> grid :params :color)] (let [{color-value :value color-opacity :opacity} (-> grid :params :color)
gutter (-> grid :params :gutter)
gutter? (and (not (nil? gutter)) (not= gutter 0))
style (if gutter?
#js {:fill color-value
:opacity color-opacity}
#js {:stroke color-value
:strokeOpacity color-opacity
:fill "transparent"})]
[:g.grid [:g.grid
(for [{:keys [x y width height]} (gg/grid-areas frame grid)] (for [{:keys [x y width height]} (gg/grid-areas frame grid)]
[:rect {:key (str key "-" x "-" y) [:rect {:key (str key "-" x "-" y)
@ -50,8 +59,7 @@
:y y :y y
:width width :width width
:height height :height height
:style {:fill color-value :style style}])]))
:opacity color-opacity}}])]))
(mf/defc grid-display-frame [{:keys [frame zoom]}] (mf/defc grid-display-frame [{:keys [frame zoom]}]
(let [grids (:grids frame)] (let [grids (:grids frame)]

View file

@ -30,7 +30,7 @@
[{:keys [width height x y] :as frame} {:keys [size gutter margin item-length type] :as params}] [{:keys [width height x y] :as frame} {:keys [size gutter margin item-length type] :as params}]
(let [size (if (number? size) size (calculate-size width item-length margin gutter)) (let [size (if (number? size) size (calculate-size width item-length margin gutter))
parts (/ width size) parts (/ width size)
item-width (or item-length (+ parts (- gutter) (/ gutter size) (- (/ (* margin 2) size)))) item-width (min (or item-length ##Inf) (+ parts (- gutter) (/ gutter size) (- (/ (* margin 2) size))))
item-height height item-height height
initial-offset (case type initial-offset (case type
:right (- width (* item-width size) (* gutter (dec size)) margin) :right (- width (* item-width size) (* gutter (dec size)) margin)
@ -46,7 +46,7 @@
(let [size (if (number? size) size (calculate-size height item-length margin gutter)) (let [size (if (number? size) size (calculate-size height item-length margin gutter))
parts (/ height size) parts (/ height size)
item-width width item-width width
item-height (or item-length (+ parts (- gutter) (/ gutter size) (- (/ (* margin 2) size)))) item-height (min (or item-length ##Inf) (+ parts (- gutter) (/ gutter size) (- (/ (* margin 2) size))))
initial-offset (case type initial-offset (case type
:right (- height (* item-height size) (* gutter (dec size)) margin) :right (- height (* item-height size) (* gutter (dec size)) margin)
:center (/ (- height (* item-height size) (* gutter (dec size))) 2) :center (/ (- height (* item-height size) (* gutter (dec size))) 2)