From a45bc0177b7edc7640596f4b551e3939025bd65f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 2 Oct 2023 17:22:10 +0200 Subject: [PATCH] :bug: Fix problem with grid --- .../geom/shapes/grid_layout/layout_data.cljc | 31 +++++++++---- common/src/app/common/types/shape/layout.cljc | 43 ++++++------------- .../app/util/code_gen/style_css_values.cljs | 8 ++-- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc index 72c1ea18f9..5e3595ee20 100644 --- a/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc +++ b/common/src/app/common/geom/shapes/grid_layout/layout_data.cljc @@ -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 diff --git a/common/src/app/common/types/shape/layout.cljc b/common/src/app/common/types/shape/layout.cljc index cccafdb200..7c0b6a97ac 100644 --- a/common/src/app/common/types/shape/layout.cljc +++ b/common/src/app/common/types/shape/layout.cljc @@ -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" diff --git a/frontend/src/app/util/code_gen/style_css_values.cljs b/frontend/src/app/util/code_gen/style_css_values.cljs index e2e184de41..a5f1e88345 100644 --- a/frontend/src/app/util/code_gen/style_css_values.cljs +++ b/frontend/src/app/util/code_gen/style_css_values.cljs @@ -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)))