Merge remote-tracking branch 'origin/feature-grid' into develop

This commit is contained in:
alonso.torres
2023-12-11 14:55:58 +01:00
41 changed files with 846 additions and 749 deletions

View File

@@ -82,7 +82,6 @@
children
(->> children
(keep (d/getf objects))
(remove :hidden)
(remove gco/invalid-geometry?)
(map (partial apply-modifiers bounds)))
@@ -169,13 +168,13 @@
children-modifiers
(if (or flex-layout? grid-layout?)
(->> (:shapes parent)
(filter #(ctl/layout-absolute? objects %)))
(filter #(ctl/position-absolute? objects %)))
(:shapes parent))
children-layout
(when (or flex-layout? grid-layout?)
(->> (:shapes parent)
(remove #(ctl/layout-absolute? objects %))))]
(remove #(ctl/position-absolute? objects %))))]
(cond-> modif-tree
(and has-modifiers? parent? (not root?))
@@ -222,7 +221,7 @@
(ctm/resize (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent)))))
children (->> (cfh/get-immediate-children objects parent-id)
(remove :hidden)
(remove ctl/position-absolute?)
(remove gco/invalid-geometry?))
content-bounds

View File

@@ -299,7 +299,7 @@
ignore-constraints
:scale
(and (ctl/any-layout? parent) (not (ctl/layout-absolute? child)))
(and (ctl/any-layout? parent) (not (ctl/position-absolute? child)))
:left
:else
@@ -310,7 +310,7 @@
ignore-constraints
:scale
(and (ctl/any-layout? parent) (not (ctl/layout-absolute? child)))
(and (ctl/any-layout? parent) (not (ctl/position-absolute? child)))
:top
:else
@@ -335,13 +335,14 @@
child-bounds (gtr/transform-bounds child-bounds modifiers)
parent-bounds transformed-parent-bounds))
transformed-child-bounds (if reset-modifiers?
child-bounds
(gtr/transform-bounds child-bounds modifiers))]
transformed-child-bounds
(if reset-modifiers?
child-bounds
(gtr/transform-bounds child-bounds modifiers))]
;; If the parent is a layout we don't need to calculate its constraints. Finish
;; after normalize the children (to keep proper proportions)
(if (ctl/any-layout? parent)
(if (and (ctl/any-layout? parent) (not (ctl/position-absolute? child)))
modifiers
(let [child-points-before (gpo/parent-coords-bounds child-bounds parent-bounds)
child-points-after (gpo/parent-coords-bounds transformed-child-bounds transformed-parent-bounds)

View File

@@ -421,8 +421,12 @@
reverse? (ctl/reverse? shape)
children (cond->> children (not reverse?) reverse)
ignore-child?
(fn [[_ child]]
(ctl/position-absolute? child))
;; Don't take into account absolute children
children (->> children (remove (comp ctl/layout-absolute? second)))
children (->> children (remove ignore-child?))
;; Creates the layout lines information
layout-lines

View File

@@ -424,7 +424,7 @@
children
(->> children
(remove #(ctl/layout-absolute? (second %))))
(remove #(ctl/position-absolute? (second %))))
children-map
(into {}

View File

@@ -178,7 +178,7 @@
position-delta (child-position-delta parent child child-bounds child-width child-height layout-data cell-data)]
(cond-> (ctm/empty)
(not (ctl/layout-absolute? child))
(not (ctl/position-absolute? child))
(-> (ctm/add-modifiers fill-modifiers)
(ctm/move position-delta)))))

View File

@@ -491,12 +491,19 @@
(defn align-self-stretch? [{:keys [layout-item-align-self]}]
(= :stretch layout-item-align-self))
(defn layout-absolute?
(defn item-absolute?
([objects id]
(layout-absolute? (get objects id)))
(item-absolute? (get objects id)))
([shape]
(true? (:layout-item-absolute shape))))
(defn position-absolute?
([objects id]
(position-absolute? (get objects id)))
([shape]
(or (item-absolute? shape)
(:hidden shape))))
(defn layout-z-index
([objects id]
(layout-z-index (get objects id)))
@@ -509,11 +516,11 @@
(auto-width? objects frame-id)
(or (and (col? objects frame-id)
(->> children-ids
(remove (partial layout-absolute? objects))
(remove (partial position-absolute? objects))
(every? (partial fill-width? objects))))
(and (row? objects frame-id)
(->> children-ids
(remove (partial layout-absolute? objects))
(remove (partial position-absolute? objects))
(some (partial fill-width? objects)))))))
(defn change-v-sizing?
@@ -705,8 +712,9 @@
(update :layout-grid-cells update-cells)
(assign-cells))))
(defn- reorder-grid-track
[prop parent from-index to-index]
(defn- reorder-grid-tracks
"Swap the positions of the tracks info"
[parent prop from-index to-index]
(-> parent
(update
prop
@@ -720,13 +728,70 @@
(d/insert-at-index (inc to-index) [[nil tr]])
(d/vec-without-nils))))))))
(defn- swap-track-content
"Swap the shapes contained in the given tracks moves as necessary the others."
[parent prop from-track to-track]
(let [remap-tracks
(cond
(> from-track to-track)
(into {from-track to-track}
(map #(vector % (inc %)))
(range to-track from-track))
(< from-track to-track)
(into {from-track to-track}
(map #(vector % (dec %)))
(range (inc from-track) (inc to-track))))]
(-> parent
(update
:layout-grid-cells
update-vals
(fn [cell] (update cell prop #(get remap-tracks % %)))))))
(declare resize-cell-area)
(declare cells-by-column)
(declare cells-by-row)
(defn- reorder-grid-track
[parent from-index to-index move-content? cells-by tracks-props prop prop-span]
(let [from-track (inc from-index)
to-track (if (< to-index from-index)
(+ to-index 2)
(inc to-index))
move-content?
(and move-content? (not= from-track to-track))
parent
(if move-content?
(->> (concat (cells-by parent (dec from-track))
(cells-by parent (dec to-track)))
(reduce (fn [parent cell]
(cond-> parent
(and (> (get cell prop-span) 1)
(or (> to-track from-track) (not (= to-track (get cell prop))))
(or (< to-track from-track) (not (= to-track (+ (get cell prop) (dec (get cell prop-span)))))))
(resize-cell-area
(:row cell)
(:column cell)
(:row cell)
(:column cell)
(if (= prop :row) 1 (:row-span cell))
(if (= prop :column) 1 (:column-span cell)))))
parent))
parent)
parent
(reorder-grid-tracks parent tracks-props from-index to-index)]
(cond-> parent
move-content?
(swap-track-content prop from-track to-track))))
(defn reorder-grid-column
[parent from-index to-index]
(reorder-grid-track :layout-grid-columns parent from-index to-index))
[parent from-index to-index move-content?]
(reorder-grid-track parent from-index to-index move-content? cells-by-column :layout-grid-columns :column :column-span))
(defn reorder-grid-row
[parent from-index to-index]
(reorder-grid-track :layout-grid-rows parent from-index to-index))
[parent from-index to-index move-content?]
(reorder-grid-track parent from-index to-index move-content? cells-by-row :layout-grid-rows :row :row-span))
(defn cells-seq
[{:keys [layout-grid-cells layout-grid-dir]} & {:keys [sort?] :or {sort? false}}]
@@ -992,9 +1057,8 @@
(defn resize-cell-area
"Increases/decreases the cell size"
[parent row column new-row new-column new-row-span new-column-span]
(if (and (>= new-row 0)
(>= new-column 0)
(if (and (>= new-row 1)
(>= new-column 1)
(>= new-row-span 1)
(>= new-column-span 1))
(let [prev-cell (cell-by-row-column parent row column)
@@ -1112,7 +1176,7 @@
(update :shapes #(d/removev children %))
(assign-cells))
children (->> children (remove #(layout-absolute? objects %)))]
children (->> children (remove #(position-absolute? objects %)))]
(-> frame
(update :shapes d/concat-vec children)
@@ -1146,22 +1210,30 @@
(assoc parent :shapes (into [] (reverse new-shapes)))))
(defn shapes-by-row
(defn cells-by-row
[parent index]
(->> (:layout-grid-cells parent)
(filter (fn [[_ {:keys [row row-span]}]]
(and (>= (inc index) row)
(< (inc index) (+ row row-span)))))
(map second)
(mapcat :shapes)))
(map second)))
(defn shapes-by-column
(defn cells-by-column
[parent index]
(->> (:layout-grid-cells parent)
(filter (fn [[_ {:keys [column column-span]}]]
(and (>= (inc index) column)
(< (inc index) (+ column column-span)))))
(map second)
(map second)))
(defn shapes-by-row
[parent index]
(->> (cells-by-row parent index)
(mapcat :shapes)))
(defn shapes-by-column
[parent index]
(->> (cells-by-column parent index)
(mapcat :shapes)))
(defn cells-coordinates