diff --git a/common/src/app/common/geom/shapes/flex_layout.cljc b/common/src/app/common/geom/shapes/flex_layout.cljc index b61eabf09..937975246 100644 --- a/common/src/app/common/geom/shapes/flex_layout.cljc +++ b/common/src/app/common/geom/shapes/flex_layout.cljc @@ -13,9 +13,9 @@ [app.common.geom.shapes.flex-layout.modifiers :as fmo])) (dm/export fbo/layout-content-bounds) +(dm/export fbo/child-layout-bound-points) (dm/export fdr/get-drop-index) (dm/export fdr/layout-drop-areas) (dm/export fli/calc-layout-data) (dm/export fmo/layout-child-modifiers) (dm/export fmo/normalize-child-modifiers) - 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 a24e81214..307e9ecb2 100644 --- a/common/src/app/common/geom/shapes/flex_layout/bounds.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/bounds.cljc @@ -106,7 +106,7 @@ child-bounds @(get bounds child-id) child-bounds (if (or (ctl/fill-height? child) (ctl/fill-height? child)) - (child-layout-bound-points parent child parent-bounds parent-bounds) + (child-layout-bound-points parent child parent-bounds child-bounds) child-bounds)] (gpo/parent-coords-bounds child-bounds parent-bounds)))] diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index a80a2f9c6..48b1eda5b 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -12,6 +12,7 @@ [app.common.geom.shapes.constraints :as gct] [app.common.geom.shapes.flex-layout :as gcl] [app.common.geom.shapes.pixel-precision :as gpp] + [app.common.geom.shapes.points :as cpo] [app.common.geom.shapes.points :as gpo] [app.common.geom.shapes.transforms :as gtr] [app.common.pages.helpers :as cph] @@ -138,29 +139,34 @@ (let [children (map (d/getf objects) (:shapes parent))] (reduce process-child modif-tree children)))) - (defn get-group-bounds [objects bounds modif-tree shape] (let [shape-id (:id shape) modifiers (-> (dm/get-in modif-tree [shape-id :modifiers]) (ctm/select-geometry)) - children (cph/get-immediate-children objects shape-id) - group-bounds - (cond - (cph/group-shape? shape) - (let [children-bounds (->> children (mapv #(get-group-bounds objects bounds modif-tree %)))] - (gtr/group-bounds shape children-bounds)) + children (cph/get-immediate-children objects shape-id)] - (cph/mask-shape? shape) - (get-group-bounds objects bounds modif-tree (-> children first)) + (cond + (cph/group-shape? shape) + (let [;; Transform here to then calculate the bounds relative to the transform + current-bounds + (cond-> @(get bounds shape-id) + (not (ctm/empty? modifiers)) + (gtr/transform-bounds modifiers)) - :else - @(get bounds shape-id))] + children-bounds + (->> children + (mapv #(get-group-bounds objects bounds modif-tree %)))] + (cpo/merge-parent-coords-bounds children-bounds current-bounds)) - (cond-> group-bounds - (not (ctm/empty? modifiers)) - (gtr/transform-bounds modifiers)))) + (cph/mask-shape? shape) + (get-group-bounds objects bounds modif-tree (-> children first)) + + :else + (cond-> @(get bounds shape-id) + (not (ctm/empty? modifiers)) + (gtr/transform-bounds modifiers))))) (defn- set-layout-modifiers [modif-tree objects bounds parent transformed-parent-bounds] diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 4383b28e8..2e5cc5954 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -369,16 +369,6 @@ (update :width + (:width deltas)) (update :height + (:height deltas))))))) -(defn group-bounds - [group children-bounds] - (let [shape-center (gco/center-shape group) - points (flatten children-bounds) - points (if (empty? points) (:points group) points)] - (-> points - (gco/transform-points shape-center (:transform-inverse group (gmt/matrix))) - (gpr/squared-points) - (gco/transform-points shape-center (:transform group (gmt/matrix)))))) - (defn update-group-selrect [group children] (let [shape-center (gco/center-shape group) diff --git a/frontend/src/app/main/ui/workspace/viewport/debug.cljs b/frontend/src/app/main/ui/workspace/viewport/debug.cljs index 5da0460f8..b8079c324 100644 --- a/frontend/src/app/main/ui/workspace/viewport/debug.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/debug.cljs @@ -152,7 +152,7 @@ [props] (let [objects (unchecked-get props "objects") - zoom (unchecked-get props "objects") + zoom (unchecked-get props "zoom") selected-shapes (unchecked-get props "selected-shapes") hover-top-frame-id (unchecked-get props "hover-top-frame-id") @@ -160,13 +160,26 @@ (when (and (= (count selected-shapes) 1) (= :frame (-> selected-shapes first :type))) (first selected-shapes)) - parent (or selected-frame (get objects hover-top-frame-id))] + parent (or selected-frame (get objects hover-top-frame-id)) + parent-bounds (:points parent)] (when (and (some? parent) (not= uuid/zero (:id parent))) (let [children (cph/get-immediate-children objects (:id parent))] [:g.debug-parent-bounds {:pointer-events "none"} (for [[idx child] (d/enumerate children)] - [:> shape-parent-bound {:key (dm/str "bound-" idx) - :zoom zoom - :shape child - :parent parent}])])))) + [:* + [:> shape-parent-bound {:key (dm/str "bound-" idx) + :zoom zoom + :shape child + :parent parent}] + + (let [child-bounds (:points child) + points + (if (or (ctl/fill-height? child) (ctl/fill-height? child)) + (gsl/child-layout-bound-points parent child parent-bounds child-bounds) + child-bounds)] + (for [point points] + [:circle {:cx (:x point) + :cy (:y point) + :r (/ 2 zoom) + :style {:fill "red"}}]))])]))))