🐛 Fix problem with grid layout paddings

This commit is contained in:
alonso.torres 2024-03-04 15:52:24 +01:00 committed by Andrey Antukh
parent f36410da87
commit fb2c4c9c3a
3 changed files with 29 additions and 23 deletions

View file

@ -1076,14 +1076,13 @@
(->> (cells-seq parent :sort? true) (->> (cells-seq parent :sort? true)
(reduce (reduce
(fn [[parent auto?] cell] (fn [[parent auto?] cell]
(let [[cell auto?] (let [[cell auto?]
(cond (cond
(and (empty? (:shapes cell)) (and (empty? (:shapes cell))
(= :manual (:position cell)) (= :manual (:position cell))
(= (:row-span cell) 1) (= (:row-span cell) 1)
(= (:column-span cell) 1)) (= (:column-span cell) 1))
[(assoc cell :position :auto) false] [cell false]
(and (or (not= (:row-span cell) 1) (and (or (not= (:row-span cell) 1)
(not= (:column-span cell) 1)) (not= (:column-span cell) 1))

View file

@ -573,6 +573,7 @@
(> (:row-span cell) 1) (> (:row-span cell) 1)
(> (:column-span cell) 1)) (> (:column-span cell) 1))
(-> (d/update-in-when [:layout-grid-cells cell-id] assoc :shapes [] :position :auto) (-> (d/update-in-when [:layout-grid-cells cell-id] assoc :shapes [] :position :auto)
(d/update-in-when [:layout-grid-cells cell-id] dissoc :area-name)
(ctl/resize-cell-area (:row cell) (:column cell) (:row cell) (:column cell) 1 1) (ctl/resize-cell-area (:row cell) (:column cell) (:row cell) (:column cell) 1 1)
(ctl/assign-cells objects))))) (ctl/assign-cells objects)))))
shape)) shape))
@ -585,6 +586,7 @@
(cond-> shape (cond-> shape
(contains? #{:area :auto} (:position cell)) (contains? #{:area :auto} (:position cell))
(-> (d/assoc-in-when [:layout-grid-cells cell-id :position] :manual) (-> (d/assoc-in-when [:layout-grid-cells cell-id :position] :manual)
(d/update-in-when [:layout-grid-cells cell-id] dissoc :area-name)
(ctl/assign-cells objects))))) (ctl/assign-cells objects)))))
shape)) shape))

View file

@ -918,8 +918,11 @@
on-gap-change on-gap-change
(fn [multiple? type val] (fn [multiple? type val]
(let [val (mth/finite val 0)] (let [val (mth/finite val 0)]
(if ^boolean multiple? (cond
^boolean multiple?
(st/emit! (dwsl/update-layout ids {:layout-gap {:row-gap val :column-gap val}})) (st/emit! (dwsl/update-layout ids {:layout-gap {:row-gap val :column-gap val}}))
(some? type)
(st/emit! (dwsl/update-layout ids {:layout-gap {type val}}))))) (st/emit! (dwsl/update-layout ids {:layout-gap {type val}})))))
;; Padding ;; Padding
@ -941,7 +944,7 @@
(and (= type :simple) (= prop :p2)) (and (= type :simple) (= prop :p2))
(st/emit! (dwsl/update-layout ids {:layout-padding {:p2 val :p4 val}})) (st/emit! (dwsl/update-layout ids {:layout-padding {:p2 val :p4 val}}))
:else (some? prop)
(st/emit! (dwsl/update-layout ids {:layout-padding {prop val}})))))) (st/emit! (dwsl/update-layout ids {:layout-padding {prop val}}))))))
;; Grid-direction ;; Grid-direction
@ -1126,16 +1129,16 @@
:on-change on-column-justify-change}] :on-change on-column-justify-change}]
[:& justify-grid-row {:is-column false [:& justify-grid-row {:is-column false
:value grid-justify-content-row :value grid-justify-content-row
:on-change on-row-justify-change}]]] :on-change on-row-justify-change}]]
[:div {:class (stl/css :row)}
[:& gap-section {:on-change on-gap-change
:value (:layout-gap values)}]]
[:div {:class (stl/css :row :padding-section)} [:div {:class (stl/css :row)}
[:& padding-section {:value (:layout-padding values) [:& gap-section {:on-change on-gap-change
:type (:layout-padding-type values) :value (:layout-gap values)}]]
:on-change-style on-padding-type-change [:div {:class (stl/css :row :padding-section)}
:on-change on-padding-change}]] [:& padding-section {:value (:layout-padding values)
:type (:layout-padding-type values)
:on-change-style on-padding-type-change
:on-change on-padding-change}]]]
nil))])) nil))]))
@ -1156,9 +1159,10 @@
(mf/use-fn (mf/use-fn
(mf/deps ids) (mf/deps ids)
(fn [multiple? type val] (fn [multiple? type val]
(if multiple? (let [val (mth/finite val 0)]
(st/emit! (dwsl/update-layout ids {:layout-gap {:row-gap val :column-gap val}})) (if multiple?
(st/emit! (dwsl/update-layout ids {:layout-gap {type val}}))))) (st/emit! (dwsl/update-layout ids {:layout-gap {:row-gap val :column-gap val}}))
(st/emit! (dwsl/update-layout ids {:layout-gap {type val}}))))))
;; Padding ;; Padding
on-padding-type-change on-padding-type-change
@ -1169,15 +1173,16 @@
on-padding-change on-padding-change
(fn [type prop val] (fn [type prop val]
(cond (let [val (mth/finite val 0)]
(and (= type :simple) (= prop :p1)) (cond
(st/emit! (dwsl/update-layout ids {:layout-padding {:p1 val :p3 val}})) (and (= type :simple) (= prop :p1))
(st/emit! (dwsl/update-layout ids {:layout-padding {:p1 val :p3 val}}))
(and (= type :simple) (= prop :p2)) (and (= type :simple) (= prop :p2))
(st/emit! (dwsl/update-layout ids {:layout-padding {:p2 val :p4 val}})) (st/emit! (dwsl/update-layout ids {:layout-padding {:p2 val :p4 val}}))
:else :else
(st/emit! (dwsl/update-layout ids {:layout-padding {prop val}})))) (st/emit! (dwsl/update-layout ids {:layout-padding {prop val}})))))
;; Align grid ;; Align grid
align-items-row (:layout-align-items values) align-items-row (:layout-align-items values)