diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index dc57ac178a..5386c05c51 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -128,7 +128,7 @@ (some? modifiers) (gtr/transform-shape modifiers) - (and (some? modifiers) (cph/group-like-shape? child)) + (cph/group-like-shape? child) (gtr/apply-group-modifiers objects modif-tree)))) (set-child-modifiers [parent [layout-line modif-tree] child] @@ -226,13 +226,13 @@ has-modifiers? (ctm/child-modifiers? modifiers) is-layout? (ctl/layout? parent) is-auto? (or (ctl/auto-height? transformed-parent) (ctl/auto-width? transformed-parent)) - is-parent? (or (cph/group-like-shape? parent) (and (cph/frame-shape? parent) (not (ctl/layout? parent)))) + is-parent? (or (cph/group-like-shape? parent) (cph/frame-shape? parent)) ;; If the current child is inside the layout we ignore the constraints is-inside-layout? (ctl/inside-layout? objects parent)] [(cond-> modif-tree - (and has-modifiers? is-parent? (not root?)) + (and (not is-layout?) has-modifiers? is-parent? (not root?)) (set-children-modifiers objects parent transformed-parent (or ignore-constraints is-inside-layout?) snap-pixel?) is-layout? diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 45ece704bf..9928ffee15 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -407,17 +407,19 @@ (apply-modifiers modifiers)))) (defn transform-bounds - [points center modifiers] - (let [transform (ctm/modifiers->transform modifiers)] - (gco/transform-points points center transform))) + ([points modifiers] + (transform-bounds points nil modifiers)) + + ([points center modifiers] + (let [transform (ctm/modifiers->transform modifiers)] + (gco/transform-points points center transform)))) (defn transform-selrect [selrect modifiers] - (let [center (gco/center-selrect selrect)] - (-> selrect - (gpr/rect->points) - (transform-bounds center modifiers) - (gpr/points->selrect)))) + (-> selrect + (gpr/rect->points) + (transform-bounds modifiers) + (gpr/points->selrect))) (defn transform-selrect-matrix [selrect mtx] @@ -434,34 +436,45 @@ (map (comp gpr/points->selrect :points transform-shape)) (gpr/join-selrects))) +(declare apply-group-modifiers) + (defn apply-children-modifiers - [objects modif-tree children] + [objects modif-tree parent-modifiers children] (->> children (map (fn [child] - (let [modifiers (get-in modif-tree [(:id child) :modifiers]) - child (transform-shape child modifiers) - parent? (or (= :group (:type child)) (= :bool (:type child)))] + (let [modifiers (->> (get-in modif-tree [(:id child) :modifiers]) + (ctm/add-modifiers parent-modifiers)) + child (transform-shape child modifiers) + parent? (cph/group-like-shape? child)] (cond-> child parent? - (apply-children-modifiers objects modif-tree))))))) + (apply-group-modifiers objects (assoc-in modif-tree [(:id child) :modifiers] modifiers)))))))) (defn apply-group-modifiers "Apply the modifiers to the group children to calculate its selection rect" - [parent objects modif-tree] + [group objects modif-tree] - (let [children (->> (:shapes parent) + (let [modifiers (get-in modif-tree [(:id group) :modifiers]) + children (->> (:shapes group) (map (d/getf objects)) - (apply-children-modifiers objects modif-tree))] - (cond-> parent - (cph/group-shape? parent) - (update-group-selrect children)))) + (apply-children-modifiers objects modif-tree modifiers))] + (cond + (cph/mask-shape? group) + (update-mask-selrect group children) + + (cph/group-shape? group) + (update-group-selrect group children) + + :else + group))) (defn get-children-bounds [parent objects modif-tree] - (let [children + (let [modifiers (get-in modif-tree [(:id parent) :modifiers]) + children (->> (:shapes parent) (map (d/getf objects)) - (apply-children-modifiers objects modif-tree))] + (apply-children-modifiers objects modif-tree modifiers))] (->> children (mapcat :points) gpr/points->rect))) (defn parent-coords-rect diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 7bbda08e87..76e234f576 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -37,6 +37,10 @@ [{:keys [type]}] (= type :group)) +(defn mask-shape? + [{:keys [type masked-group?]}] + (and (= type :group) masked-group?)) + (defn bool-shape? [{:keys [type]}] (= type :bool)) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 9b801f12ac..eb89167110 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -25,6 +25,7 @@ [app.common.types.pages-list :as ctpl] [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] + [app.common.types.shape.layout :as ctl] [app.common.uuid :as uuid] [app.config :as cfg] [app.main.data.comments :as dcm] @@ -686,11 +687,16 @@ shapes-to-detach shapes-to-reroot shapes-to-deroot - ids)] + ids) + + layouts-to-update + (into #{} + (filter (partial ctl/layout? objects)) + (concat [parent-id] (cph/get-parent-ids objects parent-id)))] (rx/of (dch/commit-changes changes) (dwco/expand-collapse parent-id) - (dwul/update-layout-positions [parent-id])))))) + (dwul/update-layout-positions layouts-to-update)))))) (defn relocate-selected-shapes [parent-id to-index] diff --git a/frontend/src/app/main/ui/workspace/viewport/snap_distances.cljs b/frontend/src/app/main/ui/workspace/viewport/snap_distances.cljs index 95cc5693ce..7854fd8c8a 100644 --- a/frontend/src/app/main/ui/workspace/viewport/snap_distances.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/snap_distances.cljs @@ -10,6 +10,7 @@ [app.common.geom.shapes :as gsh] [app.common.math :as mth] [app.common.pages.helpers :as cph] + [app.common.types.shape.layout :as ctl] [app.main.refs :as refs] [app.main.ui.formats :as fmt] [app.main.worker :as uw] @@ -272,18 +273,20 @@ frame-id (-> selected-shapes first :frame-id) frame (mf/deref (refs/object-by-id frame-id)) selrect (gsh/selection-rect selected-shapes)] - [:g.distance - [:& shape-distance - {:selrect selrect - :page-id page-id - :frame frame - :zoom zoom - :coord :x - :selected selected}] - [:& shape-distance - {:selrect selrect - :page-id page-id - :frame frame - :zoom zoom - :coord :y - :selected selected}]])) + + (when-not (ctl/layout? frame) + [:g.distance + [:& shape-distance + {:selrect selrect + :page-id page-id + :frame frame + :zoom zoom + :coord :x + :selected selected}] + [:& shape-distance + {:selrect selrect + :page-id page-id + :frame frame + :zoom zoom + :coord :y + :selected selected}]]))) diff --git a/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs b/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs index 8b8892ea99..88fe7bc81b 100644 --- a/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs @@ -10,6 +10,7 @@ [app.common.geom.shapes :as gsh] [app.common.pages.helpers :as cph] [app.common.spec :as us] + [app.common.types.shape.layout :as ctl] [app.main.snap :as snap] [app.util.geom.snap-points :as sp] [beicon.core :as rx] @@ -172,9 +173,11 @@ (and (= type :layout) (= grid :square)) (= type :guide)))) - shapes (if drawing [drawing] shapes)] - [:& snap-feedback {:shapes shapes - :page-id page-id - :remove-snap? remove-snap? - :zoom zoom}])) + shapes (if drawing [drawing] shapes) + frame-id (snap/snap-frame-id shapes)] + (when-not (ctl/layout? objects frame-id) + [:& snap-feedback {:shapes shapes + :page-id page-id + :remove-snap? remove-snap? + :zoom zoom}])))