mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Size a grid's fill child in the frame a turn leaves it in
A fill child of a grid takes the size of its content, resized along its own axes. Those axes were read from the stored shape, while the same modifiers may be turning it: turning a grid copy whose child fills its width resized the child along its unturned axes and skewed it, and a full sync then placed it unskewed. The content size, and the check for a child turned in its grid, use the frame the modifiers being calculated leave the shape in. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 21.852 | 0.62 | | edit-through-a-chain-of-dependents | 68.931 | 39.822 | 0.58 | | library-update-into-copies | 83.083 | 47.443 | 0.57 | | main-edit-among-many-shapes | 4.837 | 2.162 | 0.45 | | main-edit-into-10-copies | 1.79 | 1.028 | 0.57 | | main-edit-into-100-copies | 15.415 | 10.453 | 0.68 | | main-edit-into-1000-copies | 153.086 | 103.422 | 0.68 | | variant-switch-into-copies | 32.052 | 20.087 | 0.63 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
1f332c396f
commit
4266de0f7c
@ -197,12 +197,24 @@
|
||||
([objects bounds ignore-constraints modif-tree shapes]
|
||||
(reduce #(set-modifiers-layout objects bounds ignore-constraints %1 %2) modif-tree shapes)))
|
||||
|
||||
(defn- current-transform
|
||||
"The transform and its inverse of the shape `id` as the modifiers being
|
||||
calculated leave it in `bounds`, or as it is stored in `objects`."
|
||||
[objects bounds id]
|
||||
(if-let [points (some-> (get bounds id) deref)]
|
||||
(let [[_ transform transform-inverse] (gtr/calculate-geometry points)]
|
||||
[(or transform (gmt/matrix)) (or transform-inverse (gmt/matrix))])
|
||||
(let [shape (get objects id)]
|
||||
[(or (:transform shape) (gmt/matrix)) (or (:transform-inverse shape) (gmt/matrix))])))
|
||||
|
||||
(defn- turned-in-parent?
|
||||
"Whether the axes of `shape` are turned against those of `parent`, so that
|
||||
a size along one of them does not follow a size along the other."
|
||||
[shape parent]
|
||||
(let [{:keys [b c]} (gmt/multiply (or (:transform-inverse parent) (gmt/matrix))
|
||||
(or (:transform shape) (gmt/matrix)))]
|
||||
"Whether the axes of the shape `id` are turned against those of its parent,
|
||||
as the modifiers being calculated leave them, so that a size along one of
|
||||
them does not follow a size along the other."
|
||||
[objects bounds id]
|
||||
(let [[transform _] (current-transform objects bounds id)
|
||||
[_ parent-inverse] (current-transform objects bounds (get-in objects [id :parent-id]))
|
||||
{:keys [b c]} (gmt/multiply parent-inverse transform)]
|
||||
(not (and (mth/close? b 0 0.0001) (mth/close? c 0 0.0001)))))
|
||||
|
||||
(defn- calc-auto-modifiers
|
||||
@ -213,6 +225,8 @@
|
||||
[objects bounds parent]
|
||||
(let [parent-id (:id parent)
|
||||
parent-bounds (get bounds parent-id)
|
||||
;; the frame the modifiers being calculated leave the shape in
|
||||
[transform transform-inverse] (current-transform objects bounds parent-id)
|
||||
|
||||
set-parent-auto-width
|
||||
(fn [modifiers auto-width]
|
||||
@ -220,7 +234,7 @@
|
||||
current-width (gpo/width-points @parent-bounds)
|
||||
scale-width (/ auto-width current-width)]
|
||||
(-> modifiers
|
||||
(ctm/resize (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent)))))
|
||||
(ctm/resize (gpt/point scale-width 1) origin transform transform-inverse))))
|
||||
|
||||
set-parent-auto-height
|
||||
(fn [modifiers auto-height]
|
||||
@ -228,14 +242,14 @@
|
||||
current-height (gpo/height-points @parent-bounds)
|
||||
scale-height (/ auto-height current-height)]
|
||||
(-> modifiers
|
||||
(ctm/resize (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent)))))
|
||||
(ctm/resize (gpt/point 1 scale-height) origin transform transform-inverse))))
|
||||
|
||||
children (->> (cfh/get-immediate-children objects parent-id)
|
||||
(remove ctl/position-absolute?)
|
||||
(remove gco/invalid-geometry?))
|
||||
|
||||
grid-fill? (and (ctl/grid-layout? objects (:parent-id parent))
|
||||
(not (turned-in-parent? parent (get objects (:parent-id parent)))))
|
||||
(not (turned-in-parent? objects bounds parent-id)))
|
||||
auto? (or (ctl/auto? parent)
|
||||
(and grid-fill? (ctl/fill? parent)))
|
||||
auto-width? (or (ctl/auto-width? parent)
|
||||
|
||||
@ -1169,3 +1169,12 @@
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:transform 1 4 0 0] [:delete 5 0 0 0] [:delete 0] [:restore 0]
|
||||
[:transform 1 4 0 0] [:switch 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-turning-a-grid-turns-its-fill-child-rigidly
|
||||
;; a grid copy whose child fills its width is turned 45 degrees: the child
|
||||
;; turns with it, unskewed, as a full sync places it
|
||||
(t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library-variants true :stale-libraries true
|
||||
:layout :grid :layout-item-margins false :grid-square false :library-depth 1
|
||||
:library true :rich-variants true :layout-children true :library-text true
|
||||
:grid-empty true :layout-copies true :text true}]
|
||||
:ops [[:style 13 29 1] [:rotate 6 0 0 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user