From 8b5a36a49f0257bbd3f91780083203e617e744d7 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Feb 2023 13:15:48 +0100 Subject: [PATCH] :bug: Fix problem with auto layout an absolute positioning --- .../geom/shapes/flex_layout/bounds.cljc | 4 +- .../src/app/common/geom/shapes/modifiers.cljc | 5 +-- common/src/app/common/types/shape/layout.cljc | 40 ++++++++++--------- .../app/main/data/workspace/shape_layout.cljs | 5 ++- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/common/src/app/common/geom/shapes/flex_layout/bounds.cljc b/common/src/app/common/geom/shapes/flex_layout/bounds.cljc index d37dc32f3..358dbe34e 100644 --- a/common/src/app/common/geom/shapes/flex_layout/bounds.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/bounds.cljc @@ -117,7 +117,9 @@ child-bounds))] - (->> children (map get-child-bounds)))) + (->> children + (remove ctl/layout-absolute?) + (map get-child-bounds)))) (defn layout-content-bounds [bounds {:keys [layout-padding] :as parent} children] diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index 8e7d40704..df17fefd9 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -96,7 +96,6 @@ "Propagates the modifiers from a parent too its children applying constraints if necesary" [modif-tree children objects bounds parent transformed-parent-bounds ignore-constraints] (let [modifiers (dm/get-in modif-tree [(:id parent) :modifiers])] - ;; Move modifiers don't need to calculate constraints (if (ctm/only-move? modifiers) (loop [modif-tree modif-tree @@ -205,14 +204,14 @@ (let [origin (gpo/origin @parent-bounds) scale-width (/ auto-width (gpo/width-points @parent-bounds))] (-> modifiers - (ctm/resize-parent (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent))))) + (ctm/resize (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent))))) set-parent-auto-height (fn [modifiers auto-height] (let [origin (gpo/origin @parent-bounds) scale-height (/ auto-height (gpo/height-points @parent-bounds))] (-> modifiers - (ctm/resize-parent (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent))))) + (ctm/resize (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent))))) children (->> (cph/get-immediate-children objects parent-id) (remove :hidden)) diff --git a/common/src/app/common/types/shape/layout.cljc b/common/src/app/common/types/shape/layout.cljc index 3d9872d18..1f7b6950a 100644 --- a/common/src/app/common/types/shape/layout.cljc +++ b/common/src/app/common/types/shape/layout.cljc @@ -346,24 +346,6 @@ (defn align-self-stretch? [{:keys [layout-item-align-self]}] (= :stretch layout-item-align-self)) -(defn change-h-sizing? - [frame-id objects children-ids] - (and (layout? objects frame-id) - (auto-width? objects frame-id) - (or (and (col? objects frame-id) - (every? (partial fill-width? objects) children-ids)) - (and (row? objects frame-id) - (some (partial fill-width? objects) children-ids))))) - -(defn change-v-sizing? - [frame-id objects children-ids] - (and (layout? objects frame-id) - (auto-height? objects frame-id) - (or (and (col? objects frame-id) - (some (partial fill-height? objects) children-ids)) - (and (row? objects frame-id) - (every? (partial fill-height? objects) children-ids))))) - (defn layout-absolute? ([objects id] (layout-absolute? (get objects id))) @@ -376,6 +358,28 @@ ([shape] (or (:layout-item-z-index shape) 0))) +(defn change-h-sizing? + [frame-id objects children-ids] + (and (layout? objects frame-id) + (auto-width? objects frame-id) + (or (and (col? objects frame-id) + (->> children-ids + (remove (partial layout-absolute? objects)) + (every? (partial fill-width? objects)))) + (and (row? objects frame-id) + (->> children-ids + (remove (partial layout-absolute? objects)) + (some (partial fill-width? objects))))))) + +(defn change-v-sizing? + [frame-id objects children-ids] + (and (layout? objects frame-id) + (auto-height? objects frame-id) + (or (and (col? objects frame-id) + (some (partial fill-height? objects) children-ids)) + (and (row? objects frame-id) + (every? (partial fill-height? objects) children-ids))))) + (defn remove-layout-container-data [shape] (dissoc shape diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 60e74eaa0..2a61391b9 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -349,7 +349,10 @@ col? (ctl/col? parent) row? (ctl/row? parent) - all-children (->> parent :shapes (map (d/getf objects)))] + all-children (->> parent + :shapes + (map (d/getf objects)) + (remove ctl/layout-absolute?))] (cond-> shape ;; If the parent is hug width and the direction column