mirror of
https://github.com/penpot/penpot.git
synced 2025-07-18 15:27:12 +02:00
🐛 Fix padding prediction does not work with one shape
This commit is contained in:
parent
300ad15f5a
commit
0f9ad0907e
1 changed files with 38 additions and 39 deletions
|
@ -143,17 +143,16 @@
|
||||||
(/ (- (- max-y min-y) all-height) (dec (count shapes)))
|
(/ (- (- max-y min-y) all-height) (dec (count shapes)))
|
||||||
0)
|
0)
|
||||||
|
|
||||||
layout-gap {:row-gap row-gap :column-gap column-gap}
|
layout-gap {:row-gap (max row-gap 0) :column-gap (max column-gap 0)}
|
||||||
|
|
||||||
parent-selrect (:selrect parent)
|
parent-selrect (:selrect parent)
|
||||||
padding (when (and (not (nil? parent)) (> (count shapes) 1))
|
padding (when (and (not (nil? parent)) (> (count shapes) 0))
|
||||||
{:p1 (min (- min-y (:y1 parent-selrect)) (- (:y2 parent-selrect) max-y))
|
{:p1 (min (- min-y (:y1 parent-selrect)) (- (:y2 parent-selrect) max-y))
|
||||||
:p2 (min (- min-x (:x1 parent-selrect)) (- (:x2 parent-selrect) max-x))})]
|
:p2 (min (- min-x (:x1 parent-selrect)) (- (:x2 parent-selrect) max-x))})]
|
||||||
|
|
||||||
(cond-> {:layout-flex-dir direction}
|
(cond-> {:layout-flex-dir direction}
|
||||||
(not (nil? padding)) (assoc :layout-padding {:p1 (:p1 padding) :p2 (:p2 padding) :p3 (:p1 padding) :p4 (:p2 padding)}
|
(not (nil? padding)) (assoc :layout-padding {:p1 (:p1 padding) :p2 (:p2 padding) :p3 (:p1 padding) :p4 (:p2 padding)})
|
||||||
:layout-align-items :center
|
(not (nil? layout-gap)) (assoc :layout-gap layout-gap)))))
|
||||||
:layout-gap layout-gap)))))
|
|
||||||
|
|
||||||
(defn shapes->grid-params
|
(defn shapes->grid-params
|
||||||
"Given the shapes calculate its flex parameters (horizontal vs vertical, gaps, etc)"
|
"Given the shapes calculate its flex parameters (horizontal vs vertical, gaps, etc)"
|
||||||
|
@ -361,46 +360,46 @@
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id))))))
|
||||||
|
|
||||||
#_(defn update-grid-cells
|
#_(defn update-grid-cells
|
||||||
[parent objects]
|
[parent objects]
|
||||||
(let [children (cph/get-immediate-children objects (:id parent))
|
(let [children (cph/get-immediate-children objects (:id parent))
|
||||||
layout-grid-rows (:layout-grid-rows parent)
|
layout-grid-rows (:layout-grid-rows parent)
|
||||||
layout-grid-columns (:layout-grid-columns parent)
|
layout-grid-columns (:layout-grid-columns parent)
|
||||||
num-rows (count layout-grid-columns)
|
num-rows (count layout-grid-columns)
|
||||||
num-columns (count layout-grid-columns)
|
num-columns (count layout-grid-columns)
|
||||||
layout-grid-cells (:layout-grid-cells parent)
|
layout-grid-cells (:layout-grid-cells parent)
|
||||||
|
|
||||||
allocated-shapes
|
allocated-shapes
|
||||||
(into #{} (mapcat :shapes) (:layout-grid-cells parent))
|
(into #{} (mapcat :shapes) (:layout-grid-cells parent))
|
||||||
|
|
||||||
no-cell-shapes
|
no-cell-shapes
|
||||||
(->> children (:shapes parent) (remove allocated-shapes))
|
(->> children (:shapes parent) (remove allocated-shapes))
|
||||||
|
|
||||||
layout-grid-cells
|
layout-grid-cells
|
||||||
(for [[row-idx row] (d/enumerate layout-grid-rows)
|
(for [[row-idx row] (d/enumerate layout-grid-rows)
|
||||||
[col-idx col] (d/enumerate layout-grid-columns)]
|
[col-idx col] (d/enumerate layout-grid-columns)]
|
||||||
|
|
||||||
(let [shape (nth children (+ (* row-idx num-columns) col-idx) nil)
|
(let [shape (nth children (+ (* row-idx num-columns) col-idx) nil)
|
||||||
cell-data {:id (uuid/next)
|
cell-data {:id (uuid/next)
|
||||||
:row (inc row-idx)
|
:row (inc row-idx)
|
||||||
:column (inc col-idx)
|
:column (inc col-idx)
|
||||||
:row-span 1
|
:row-span 1
|
||||||
:col-span 1
|
:col-span 1
|
||||||
:shapes (when shape [(:id shape)])}]
|
:shapes (when shape [(:id shape)])}]
|
||||||
[(:id cell-data) cell-data]))]
|
[(:id cell-data) cell-data]))]
|
||||||
(assoc parent :layout-grid-cells (into {} layout-grid-cells))))
|
(assoc parent :layout-grid-cells (into {} layout-grid-cells))))
|
||||||
|
|
||||||
#_(defn check-grid-cells-update
|
#_(defn check-grid-cells-update
|
||||||
[ids]
|
[ids]
|
||||||
(ptk/reify ::check-grid-cells-update
|
(ptk/reify ::check-grid-cells-update
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [objects (wsh/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
(rx/of (dwc/update-shapes
|
(rx/of (dwc/update-shapes
|
||||||
ids
|
ids
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(-> shape
|
(-> shape
|
||||||
(update-grid-cells objects)))))))))
|
(update-grid-cells objects)))))))))
|
||||||
|
|
||||||
(defn add-layout-track
|
(defn add-layout-track
|
||||||
[ids type value]
|
[ids type value]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue