mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
✨ Keep group constraint behaviour inside flex layout
This commit is contained in:
parent
c79d549f53
commit
0d2b228eb7
@ -236,7 +236,24 @@
|
|||||||
(and (some? auto-height) (ctl/auto-height? parent))
|
(and (some? auto-height) (ctl/auto-height? parent))
|
||||||
(set-parent-auto-height auto-height))))
|
(set-parent-auto-height auto-height))))
|
||||||
|
|
||||||
(defn- propagate-modifiers
|
(defn- propagate-modifiers-constraints
|
||||||
|
"Propagate modifiers to its children"
|
||||||
|
[objects bounds ignore-constraints modif-tree parent]
|
||||||
|
(let [parent-id (:id parent)
|
||||||
|
root? (= uuid/zero parent-id)
|
||||||
|
modifiers (-> (dm/get-in modif-tree [parent-id :modifiers])
|
||||||
|
(ctm/select-geometry))
|
||||||
|
has-modifiers? (ctm/child-modifiers? modifiers)
|
||||||
|
layout? (ctl/layout? parent)
|
||||||
|
parent? (or (cph/group-like-shape? parent) (cph/frame-shape? parent))
|
||||||
|
|
||||||
|
transformed-parent-bounds (delay (gtr/transform-bounds @(get bounds parent-id) modifiers))]
|
||||||
|
|
||||||
|
(cond-> modif-tree
|
||||||
|
(and (not layout?) has-modifiers? parent? (not root?))
|
||||||
|
(set-children-modifiers objects bounds parent transformed-parent-bounds ignore-constraints))))
|
||||||
|
|
||||||
|
(defn- propagate-modifiers-layout
|
||||||
"Propagate modifiers to its children"
|
"Propagate modifiers to its children"
|
||||||
[objects bounds ignore-constraints [modif-tree autolayouts] parent]
|
[objects bounds ignore-constraints [modif-tree autolayouts] parent]
|
||||||
(let [parent-id (:id parent)
|
(let [parent-id (:id parent)
|
||||||
@ -248,14 +265,11 @@
|
|||||||
auto? (or (ctl/auto-height? parent) (ctl/auto-width? parent))
|
auto? (or (ctl/auto-height? parent) (ctl/auto-width? parent))
|
||||||
parent? (or (cph/group-like-shape? parent) (cph/frame-shape? parent))
|
parent? (or (cph/group-like-shape? parent) (cph/frame-shape? parent))
|
||||||
|
|
||||||
;; If the current child is inside the layout we ignore the constraints
|
|
||||||
inside-layout? (ctl/inside-layout? objects parent)
|
|
||||||
|
|
||||||
transformed-parent-bounds (delay (gtr/transform-bounds @(get bounds parent-id) modifiers))]
|
transformed-parent-bounds (delay (gtr/transform-bounds @(get bounds parent-id) modifiers))]
|
||||||
|
|
||||||
[(cond-> modif-tree
|
[(cond-> modif-tree
|
||||||
(and (not layout?) has-modifiers? parent? (not root?))
|
(and (not layout?) has-modifiers? parent? (not root?))
|
||||||
(set-children-modifiers objects bounds parent transformed-parent-bounds (or ignore-constraints inside-layout?))
|
(set-children-modifiers objects bounds parent transformed-parent-bounds ignore-constraints)
|
||||||
|
|
||||||
layout?
|
layout?
|
||||||
(-> (process-layout-children objects bounds parent transformed-parent-bounds)
|
(-> (process-layout-children objects bounds parent transformed-parent-bounds)
|
||||||
@ -280,18 +294,19 @@
|
|||||||
other-tree))
|
other-tree))
|
||||||
|
|
||||||
(defn transform-bounds
|
(defn transform-bounds
|
||||||
[bounds objects modif-tree]
|
([bounds objects modif-tree]
|
||||||
|
(transform-bounds bounds objects modif-tree (->> (keys modif-tree) (map #(get objects %)))))
|
||||||
|
([bounds objects modif-tree tree-seq]
|
||||||
|
|
||||||
(loop [result bounds
|
(loop [result bounds
|
||||||
ids (keys modif-tree)]
|
shapes (reverse tree-seq)]
|
||||||
(if (empty? ids)
|
(if (empty? shapes)
|
||||||
result
|
result
|
||||||
|
|
||||||
(let [id (first ids)
|
(let [shape (first shapes)
|
||||||
shape (get objects id)
|
new-bounds (delay (get-group-bounds objects bounds modif-tree shape))
|
||||||
new-bounds (delay (get-group-bounds objects bounds modif-tree shape))
|
result (assoc result (:id shape) new-bounds)]
|
||||||
result (assoc result id new-bounds)]
|
(recur result (rest shapes)))))))
|
||||||
(recur result (rest ids))))))
|
|
||||||
|
|
||||||
(defn sizing-auto-modifiers
|
(defn sizing-auto-modifiers
|
||||||
"Recalculates the layouts to adjust the sizing: auto new sizes"
|
"Recalculates the layouts to adjust the sizing: auto new sizes"
|
||||||
@ -308,7 +323,7 @@
|
|||||||
tree-seq (resolve-tree-sequence #{current} objects)
|
tree-seq (resolve-tree-sequence #{current} objects)
|
||||||
|
|
||||||
[resize-modif-tree _]
|
[resize-modif-tree _]
|
||||||
(reduce #(propagate-modifiers objects bounds ignore-constraints %1 %2) [resize-modif-tree #{}] tree-seq)
|
(reduce #(propagate-modifiers-layout objects bounds ignore-constraints %1 %2) [resize-modif-tree #{}] tree-seq)
|
||||||
|
|
||||||
bounds (transform-bounds bounds objects resize-modif-tree)
|
bounds (transform-bounds bounds objects resize-modif-tree)
|
||||||
|
|
||||||
@ -320,12 +335,18 @@
|
|||||||
[modif-tree objects ignore-constraints snap-pixel?]
|
[modif-tree objects ignore-constraints snap-pixel?]
|
||||||
|
|
||||||
(let [objects (apply-structure-modifiers objects modif-tree)
|
(let [objects (apply-structure-modifiers objects modif-tree)
|
||||||
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))
|
|
||||||
|
|
||||||
|
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))
|
||||||
shapes-tree (resolve-tree-sequence (-> modif-tree keys set) objects)
|
shapes-tree (resolve-tree-sequence (-> modif-tree keys set) objects)
|
||||||
|
|
||||||
[modif-tree sizing-auto-layouts]
|
;; Calculate the input transformation and constraints
|
||||||
(reduce #(propagate-modifiers objects bounds ignore-constraints %1 %2) [modif-tree #{}] shapes-tree)
|
modif-tree' (reduce #(propagate-modifiers-constraints objects bounds ignore-constraints %1 %2) modif-tree shapes-tree)
|
||||||
|
bounds (transform-bounds bounds objects modif-tree' shapes-tree)
|
||||||
|
|
||||||
|
[modif-tree-layout sizing-auto-layouts]
|
||||||
|
(reduce #(propagate-modifiers-layout objects bounds ignore-constraints %1 %2) [{} #{}] shapes-tree)
|
||||||
|
|
||||||
|
modif-tree (merge-modif-tree modif-tree' modif-tree-layout)
|
||||||
|
|
||||||
;; Calculate hug layouts positions
|
;; Calculate hug layouts positions
|
||||||
modif-tree
|
modif-tree
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user