mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Turn and skew layout children with their layout board
A turned board that fills its flex parent skews, and so does a grid board it holds. In the layout pass a layout board handed its modifiers only to its absolute children, so the layout moved the others without the board's turn or skew: they stayed rigid, while the WASM layout and a component sync skew them. The layout pass now hands a layout board's modifiers to all its children, which keep their size along its axes, and the layout places them from the transformed bounds. Benchmark (scripts/bench-components, lower quantile in ms): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.425 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 41.077 | 0.60 | | library-update-into-copies | 83.083 | 47.075 | 0.57 | | main-edit-among-many-shapes | 4.837 | 2.276 | 0.47 | | main-edit-into-10-copies | 1.79 | 0.998 | 0.56 | | main-edit-into-100-copies | 15.415 | 11.243 | 0.73 | | main-edit-into-1000-copies | 153.086 | 109.801 | 0.72 | | variant-switch-into-copies | 32.052 | 20.218 | 0.63 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
afabcbca3a
commit
e10ce2dba9
@ -166,20 +166,16 @@
|
||||
|
||||
transformed-parent-bounds (delay (gtr/transform-bounds @(get bounds parent-id) modifiers))
|
||||
|
||||
children-modifiers
|
||||
(if (or flex-layout? grid-layout?)
|
||||
(->> (:shapes parent)
|
||||
(filter #(ctl/position-absolute? objects %)))
|
||||
(:shapes parent))
|
||||
|
||||
children-layout
|
||||
(when (or flex-layout? grid-layout?)
|
||||
(->> (:shapes parent)
|
||||
(remove #(ctl/position-absolute? objects %))))]
|
||||
|
||||
(cond-> modif-tree
|
||||
;; layout children keep their size along the parent's axes and follow
|
||||
;; its turn or skew; the layout then places them
|
||||
(and has-modifiers? parent? (not root?))
|
||||
(set-children-modifiers children-modifiers objects bounds parent transformed-parent-bounds ignore-constraints)
|
||||
(set-children-modifiers (:shapes parent) objects bounds parent transformed-parent-bounds ignore-constraints)
|
||||
|
||||
flex-layout?
|
||||
(set-flex-layout-modifiers children-layout objects bounds parent transformed-parent-bounds)
|
||||
|
||||
@ -8,6 +8,9 @@
|
||||
(:require
|
||||
[app.common.geom.modifiers :as gm]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.shapes.transforms :as gtr]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
@ -185,3 +188,41 @@
|
||||
|
||||
(t/is (some? result))
|
||||
(t/is (contains? result rect-id)))))
|
||||
|
||||
(defn- reflow
|
||||
[objects ids]
|
||||
(->> objects
|
||||
(gm/set-objects-modifiers (into {} (map #(vector % {:modifiers (ctm/reflow-modifiers)})) ids))
|
||||
(gtr/apply-objects-modifiers objects)))
|
||||
|
||||
(defn- edges
|
||||
[{:keys [points]}]
|
||||
(let [[p0 p1 _ p3] points]
|
||||
[(gpt/to-vec p0 p1) (gpt/to-vec p0 p3)]))
|
||||
|
||||
(t/deftest grid-child-skews-with-its-skewed-grid
|
||||
(t/testing "a grid board skewed by its turned parent filling a flex skews its children too"
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame :outer :width 340 :height 200 :layout :flex :layout-flex-dir :row
|
||||
:layout-align-items :center :layout-justify-content :center
|
||||
:layout-padding-type :simple :layout-padding {:p1 30 :p2 30 :p3 30 :p4 30})
|
||||
(tho/add-frame :card :parent-label :outer :x 120 :y 50 :width 100 :height 100)
|
||||
(tho/add-grid-frame :inner :parent-label :card :x 140 :y 70 :width 60 :height 60)
|
||||
(add-rect-child :cell :inner :x 140 :y 70 :width 20 :height 20)
|
||||
(tho/place-in-grid-columns :inner 1 {1 :cell}))
|
||||
ids [(thi/id :outer) (thi/id :inner)]
|
||||
objects (reflow (:objects (thf/current-page file)) ids)
|
||||
card (get objects (thi/id :card))
|
||||
objects (->> objects
|
||||
(gm/set-objects-modifiers
|
||||
{(:id card) {:modifiers (ctm/rotation-modifiers card (gsh/shape->center card) 45)}})
|
||||
(gtr/apply-objects-modifiers objects))
|
||||
objects (reflow (assoc-in objects [(:id card) :layout-item-h-sizing] :fill) ids)
|
||||
inner (get objects (thi/id :inner))
|
||||
cell (get objects (thi/id :cell))
|
||||
[inner-h inner-v] (edges inner)
|
||||
[cell-h cell-v] (edges cell)]
|
||||
|
||||
(t/is (gpt/close? (gpt/scale inner-h (/ 1 3)) cell-h))
|
||||
(t/is (gpt/close? (gpt/scale inner-v (/ 1 3)) cell-v))
|
||||
(t/is (gpt/close? (first (:points inner)) (first (:points cell)))))))
|
||||
|
||||
@ -917,3 +917,11 @@
|
||||
:ops [[:library-transform 2 3 4 0] [:library-delete 0] [:library-sync] [:library-restore 0]
|
||||
[:library-sync] [:library-undo 0 0 0 0] [:library-transform 16 4 4 0]
|
||||
[:edit 17 1 1 :copy-head] [:reset 17]]}))))
|
||||
|
||||
(t/deftest generated-turned-fill-copy-skews-the-grid-children-it-holds
|
||||
;; a copy filling a main's grid cell is turned 45 degrees; the cell skews
|
||||
;; it, and the children of its nested grid skew with it, as a sync places
|
||||
;; them
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :rich-variants true
|
||||
:layout-children true :grid-empty true :layout-copies true :text true}]
|
||||
:ops [[:style 4 29 1] [:detach 0 0 0 0] [:rotate 5 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user