mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 15:41:39 +02:00
🐛 Fix problem with hug layout and groups
This commit is contained in:
parent
2c558a6a02
commit
29b1b4dbc9
5 changed files with 41 additions and 32 deletions
|
@ -13,9 +13,9 @@
|
||||||
[app.common.geom.shapes.flex-layout.modifiers :as fmo]))
|
[app.common.geom.shapes.flex-layout.modifiers :as fmo]))
|
||||||
|
|
||||||
(dm/export fbo/layout-content-bounds)
|
(dm/export fbo/layout-content-bounds)
|
||||||
|
(dm/export fbo/child-layout-bound-points)
|
||||||
(dm/export fdr/get-drop-index)
|
(dm/export fdr/get-drop-index)
|
||||||
(dm/export fdr/layout-drop-areas)
|
(dm/export fdr/layout-drop-areas)
|
||||||
(dm/export fli/calc-layout-data)
|
(dm/export fli/calc-layout-data)
|
||||||
(dm/export fmo/layout-child-modifiers)
|
(dm/export fmo/layout-child-modifiers)
|
||||||
(dm/export fmo/normalize-child-modifiers)
|
(dm/export fmo/normalize-child-modifiers)
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@
|
||||||
child-bounds @(get bounds child-id)
|
child-bounds @(get bounds child-id)
|
||||||
child-bounds
|
child-bounds
|
||||||
(if (or (ctl/fill-height? child) (ctl/fill-height? child))
|
(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)]
|
child-bounds)]
|
||||||
(gpo/parent-coords-bounds child-bounds parent-bounds)))]
|
(gpo/parent-coords-bounds child-bounds parent-bounds)))]
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
[app.common.geom.shapes.constraints :as gct]
|
[app.common.geom.shapes.constraints :as gct]
|
||||||
[app.common.geom.shapes.flex-layout :as gcl]
|
[app.common.geom.shapes.flex-layout :as gcl]
|
||||||
[app.common.geom.shapes.pixel-precision :as gpp]
|
[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.points :as gpo]
|
||||||
[app.common.geom.shapes.transforms :as gtr]
|
[app.common.geom.shapes.transforms :as gtr]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
|
@ -138,29 +139,34 @@
|
||||||
(let [children (map (d/getf objects) (:shapes parent))]
|
(let [children (map (d/getf objects) (:shapes parent))]
|
||||||
(reduce process-child modif-tree children))))
|
(reduce process-child modif-tree children))))
|
||||||
|
|
||||||
|
|
||||||
(defn get-group-bounds
|
(defn get-group-bounds
|
||||||
[objects bounds modif-tree shape]
|
[objects bounds modif-tree shape]
|
||||||
(let [shape-id (:id shape)
|
(let [shape-id (:id shape)
|
||||||
modifiers (-> (dm/get-in modif-tree [shape-id :modifiers])
|
modifiers (-> (dm/get-in modif-tree [shape-id :modifiers])
|
||||||
(ctm/select-geometry))
|
(ctm/select-geometry))
|
||||||
|
|
||||||
children (cph/get-immediate-children objects shape-id)
|
children (cph/get-immediate-children objects shape-id)]
|
||||||
group-bounds
|
|
||||||
(cond
|
(cond
|
||||||
(cph/group-shape? shape)
|
(cph/group-shape? shape)
|
||||||
(let [children-bounds (->> children (mapv #(get-group-bounds objects bounds modif-tree %)))]
|
(let [;; Transform here to then calculate the bounds relative to the transform
|
||||||
(gtr/group-bounds shape children-bounds))
|
current-bounds
|
||||||
|
(cond-> @(get bounds shape-id)
|
||||||
|
(not (ctm/empty? modifiers))
|
||||||
|
(gtr/transform-bounds modifiers))
|
||||||
|
|
||||||
|
children-bounds
|
||||||
|
(->> children
|
||||||
|
(mapv #(get-group-bounds objects bounds modif-tree %)))]
|
||||||
|
(cpo/merge-parent-coords-bounds children-bounds current-bounds))
|
||||||
|
|
||||||
(cph/mask-shape? shape)
|
(cph/mask-shape? shape)
|
||||||
(get-group-bounds objects bounds modif-tree (-> children first))
|
(get-group-bounds objects bounds modif-tree (-> children first))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
@(get bounds shape-id))]
|
(cond-> @(get bounds shape-id)
|
||||||
|
|
||||||
(cond-> group-bounds
|
|
||||||
(not (ctm/empty? modifiers))
|
(not (ctm/empty? modifiers))
|
||||||
(gtr/transform-bounds modifiers))))
|
(gtr/transform-bounds modifiers)))))
|
||||||
|
|
||||||
(defn- set-layout-modifiers
|
(defn- set-layout-modifiers
|
||||||
[modif-tree objects bounds parent transformed-parent-bounds]
|
[modif-tree objects bounds parent transformed-parent-bounds]
|
||||||
|
|
|
@ -369,16 +369,6 @@
|
||||||
(update :width + (:width deltas))
|
(update :width + (:width deltas))
|
||||||
(update :height + (:height 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
|
(defn update-group-selrect
|
||||||
[group children]
|
[group children]
|
||||||
(let [shape-center (gco/center-shape group)
|
(let [shape-center (gco/center-shape group)
|
||||||
|
|
|
@ -152,7 +152,7 @@
|
||||||
[props]
|
[props]
|
||||||
|
|
||||||
(let [objects (unchecked-get props "objects")
|
(let [objects (unchecked-get props "objects")
|
||||||
zoom (unchecked-get props "objects")
|
zoom (unchecked-get props "zoom")
|
||||||
selected-shapes (unchecked-get props "selected-shapes")
|
selected-shapes (unchecked-get props "selected-shapes")
|
||||||
hover-top-frame-id (unchecked-get props "hover-top-frame-id")
|
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)))
|
(when (and (= (count selected-shapes) 1) (= :frame (-> selected-shapes first :type)))
|
||||||
(first selected-shapes))
|
(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)))
|
(when (and (some? parent) (not= uuid/zero (:id parent)))
|
||||||
(let [children (cph/get-immediate-children objects (:id parent))]
|
(let [children (cph/get-immediate-children objects (:id parent))]
|
||||||
[:g.debug-parent-bounds {:pointer-events "none"}
|
[:g.debug-parent-bounds {:pointer-events "none"}
|
||||||
(for [[idx child] (d/enumerate children)]
|
(for [[idx child] (d/enumerate children)]
|
||||||
|
[:*
|
||||||
[:> shape-parent-bound {:key (dm/str "bound-" idx)
|
[:> shape-parent-bound {:key (dm/str "bound-" idx)
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:shape child
|
:shape child
|
||||||
:parent parent}])]))))
|
: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"}}]))])]))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue