mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 02:28:18 -05:00
🐛 Fix problem with grid
This commit is contained in:
parent
d420f30835
commit
a45bc0177b
3 changed files with 40 additions and 42 deletions
|
@ -228,16 +228,17 @@
|
|||
(defn allocate-auto-tracks
|
||||
[allocations indexed-tracks to-allocate]
|
||||
(if (empty? indexed-tracks)
|
||||
allocations
|
||||
[allocations to-allocate]
|
||||
(let [[idx track] (first indexed-tracks)
|
||||
old-allocated (get allocations idx 0.01)
|
||||
auto-track? (= :auto (:type track))
|
||||
|
||||
allocated (if auto-track?
|
||||
(max old-allocated
|
||||
(/ to-allocate (count indexed-tracks))
|
||||
(:size track))
|
||||
(:size track))]
|
||||
allocated
|
||||
(if auto-track?
|
||||
(max old-allocated
|
||||
(/ to-allocate (count indexed-tracks))
|
||||
(:size track))
|
||||
(:size track))]
|
||||
(recur (cond-> allocations
|
||||
auto-track?
|
||||
(assoc idx allocated))
|
||||
|
@ -304,8 +305,22 @@
|
|||
[to-allocate (conj result idx-track)]
|
||||
;; If fixed, we remove from allocate and don't add the track
|
||||
[(- to-allocate (:size track)) result]))
|
||||
[to-allocate []]))]
|
||||
(allocate-auto-tracks allocated indexed-tracks (max to-allocate 0))))
|
||||
[to-allocate []]))
|
||||
|
||||
|
||||
non-assigned-indexed-tracks
|
||||
(->> indexed-tracks
|
||||
(remove (fn [[idx track]] (contains? allocated idx))))
|
||||
|
||||
;; First we try to assign into the non-assigned tracks
|
||||
[allocated to-allocate]
|
||||
(allocate-auto-tracks allocated non-assigned-indexed-tracks (max to-allocate 0))
|
||||
|
||||
;; In the second pass we use every track for the rest of the space
|
||||
[allocated _]
|
||||
(allocate-auto-tracks allocated indexed-tracks (max to-allocate 0))]
|
||||
|
||||
allocated))
|
||||
{}))
|
||||
|
||||
;; Apply the allocations to the tracks
|
||||
|
|
|
@ -715,26 +715,6 @@
|
|||
[parent from-index to-index]
|
||||
(reorder-grid-track :layout-grid-rows parent from-index to-index))
|
||||
|
||||
(defn get-cells
|
||||
([parent]
|
||||
(get-cells parent nil))
|
||||
|
||||
([{:keys [layout-grid-cells layout-grid-dir]} {:keys [sort? remove-empty?] :or {sort? false remove-empty? false}}]
|
||||
(let [comp-fn (if (= layout-grid-dir :row)
|
||||
(juxt :row :column)
|
||||
(juxt :column :row))
|
||||
|
||||
maybe-sort?
|
||||
(if sort? (partial sort-by (comp comp-fn second)) identity)
|
||||
|
||||
maybe-remove?
|
||||
(if remove-empty? (partial remove #(empty? (:shapes (second %)))) identity)]
|
||||
|
||||
(->> layout-grid-cells
|
||||
(maybe-sort?)
|
||||
(maybe-remove?)
|
||||
(map (fn [[id cell]] (assoc cell :id id)))))))
|
||||
|
||||
(defn cells-seq
|
||||
[{:keys [layout-grid-cells layout-grid-dir]} & {:keys [sort?] :or {sort? false}}]
|
||||
|
||||
|
@ -752,18 +732,21 @@
|
|||
([parent]
|
||||
(get-free-cells parent nil))
|
||||
|
||||
([{:keys [layout-grid-cells layout-grid-dir]} {:keys [sort?] :or {sort? false}}]
|
||||
(let [comp-fn (if (= layout-grid-dir :row)
|
||||
(juxt :row :column)
|
||||
(juxt :column :row))
|
||||
([parent {:keys [sort?] :or {sort? false}}]
|
||||
(->> (cells-seq parent :sort? sort?)
|
||||
(filter (comp empty? :shapes))
|
||||
(map :id))))
|
||||
|
||||
maybe-sort?
|
||||
(if sort? (partial sort-by (comp comp-fn second)) identity)]
|
||||
(defn get-cells
|
||||
([parent]
|
||||
(get-cells parent nil))
|
||||
|
||||
(->> layout-grid-cells
|
||||
(filter (comp empty? :shapes second))
|
||||
(maybe-sort?)
|
||||
(map first)))))
|
||||
([parent {:keys [sort? remove-empty?] :or {sort? false remove-empty? false}}]
|
||||
(let [maybe-remove?
|
||||
(if remove-empty? (partial remove (comp empty? :shapes)) identity)]
|
||||
|
||||
(->> (cells-seq parent :sort? sort?)
|
||||
(maybe-remove?)))))
|
||||
|
||||
(defn check-deassigned-cells
|
||||
"Clean the cells whith shapes that are no longer in the layout"
|
||||
|
|
|
@ -367,13 +367,13 @@
|
|||
(defmethod get-value :max-height
|
||||
[_ shape objects]
|
||||
(cond
|
||||
(ctl/flex-layout-immediate-child? objects shape)
|
||||
(ctl/any-layout-immediate-child? objects shape)
|
||||
(:layout-item-max-h shape)))
|
||||
|
||||
(defmethod get-value :min-height
|
||||
[_ shape objects]
|
||||
(cond
|
||||
(and (ctl/flex-layout-immediate-child? objects shape) (some? (:layout-item-min-h shape)))
|
||||
(and (ctl/any-layout-immediate-child? objects shape) (some? (:layout-item-min-h shape)))
|
||||
(:layout-item-min-h shape)
|
||||
|
||||
(and (ctl/auto-height? shape) (cph/frame-shape? shape) (not (:show-content shape)))
|
||||
|
@ -382,13 +382,13 @@
|
|||
(defmethod get-value :max-width
|
||||
[_ shape objects]
|
||||
(cond
|
||||
(ctl/flex-layout-immediate-child? objects shape)
|
||||
(ctl/any-layout-immediate-child? objects shape)
|
||||
(:layout-item-max-w shape)))
|
||||
|
||||
(defmethod get-value :min-width
|
||||
[_ shape objects]
|
||||
(cond
|
||||
(and (ctl/flex-layout-immediate-child? objects shape) (some? (:layout-item-min-w shape)))
|
||||
(and (ctl/any-layout-immediate-child? objects shape) (some? (:layout-item-min-w shape)))
|
||||
(:layout-item-min-w shape)
|
||||
|
||||
(and (ctl/auto-width? shape) (cph/frame-shape? shape) (not (:show-content shape)))
|
||||
|
|
Loading…
Add table
Reference in a new issue