mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Fix the layout sizing of a main that update-main resizes or turns
When a copy resizes or turns a main that fills or hugs in a layout, the update main pushed the size, the layout gave the main its own size back, and the copy followed and lost its size. When the copy shape authors its geometry, the push now fixes each fill or auto axis it changes, on both axes when it turns the shape in its parent, as a resize of a fill child does in the editor. The main and the copy take the same sizing; a shape that is not a layout drops it, which leaves it fixed like its copies. A sizing the copy authors is pushed as it is. A shape the copy does not resize, such as a fill child that a copy's grid padding resizes, keeps its sizing: the main's layout gives it the same size. Tests: updating-a-fill-main-from-a-resized-copy-fixes-the-main-size, updating-a-turned-fill-main-from-its-copy-fixes-the-main-size (the variant gate programs of round 11, seeds 252148030 and 333977410), updating-a-main-with-a-turned-copy-keeps-the-fill-of-its-laid-out-children and updating-a-main-whose-copy-padding-resized-a-fill-child-keeps-its-fill (round 12, seed 333977410). Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 20.989 | 21.843 | 0.6 | | edit-through-a-chain-of-dependents | 68.931 | 42.083 | 43.11 | 0.61 | | library-update-into-copies | 83.083 | 54.201 | 55.537 | 0.65 | | main-edit-among-many-shapes | 4.837 | 2.43 | 2.533 | 0.5 | | main-edit-into-10-copies | 1.79 | 1.047 | 1.117 | 0.58 | | main-edit-into-100-copies | 15.415 | 11.084 | 11.219 | 0.72 | | main-edit-into-1000-copies | 153.086 | 101.1 | 110.921 | 0.66 | | variant-switch-into-copies | 32.052 | 22.903 | 23.542 | 0.71 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
e8ab93d6fb
commit
5f20d4c8cd
@ -928,6 +928,46 @@
|
||||
(= :path (:type shape-inst)) (conj :content))]
|
||||
(merge shape-inst (select-keys (reposition-shape shape-main root-main root-inst) attrs))))
|
||||
|
||||
(defn- set-sizing
|
||||
"Set the layout `sizing` of `shape` of `container`, with its undo."
|
||||
[changes container shape sizing]
|
||||
(let [operations (fn [values]
|
||||
(mapv (fn [attr] {:type :set :attr attr :val (get values attr) :ignore-touched true})
|
||||
(keys sizing)))]
|
||||
(pcb/add-changes changes container
|
||||
[{:type :mod-obj :id (:id shape) :operations (operations sizing)}]
|
||||
[{:type :mod-obj :id (:id shape) :operations (operations shape)}])))
|
||||
|
||||
(defn- pushed-size-sizing
|
||||
"The layout sizing that `shape-main` of `objects` takes when an update main
|
||||
pushes the geometry of `source`, the copy shape `shape-inst` of
|
||||
`inst-objects`, into it: fixed on each axis that a layout sizes (fill or
|
||||
auto) and that the push resizes, or on both when it turns the shape in its
|
||||
parent, since a layout resizes a turned child. Only a copy that authors
|
||||
its geometry resizes or turns the main; the layout sizes the rest. A shape
|
||||
that is not a layout drops the sizing, which leaves it fixed as its copies
|
||||
are. A sizing the copy authors is pushed as it is."
|
||||
[objects shape-main inst-objects shape-inst source]
|
||||
(let [laid? (and (ctk/touched-group? shape-inst :geometry-group)
|
||||
(or (ctsl/any-layout-immediate-child? objects shape-main)
|
||||
(ctsl/any-layout? shape-main)))
|
||||
;; the axes of a shape relative to its parent's
|
||||
in-parent (fn [objects shape]
|
||||
(cond-> (axes-matrix shape)
|
||||
(cfh/frame-shape? (get objects (:parent-id shape)))
|
||||
(gmt/multiply (gmt/inverse (axes-matrix (get objects (:parent-id shape)))))))
|
||||
turned? (not (gmt/unit? (gmt/multiply (in-parent inst-objects shape-inst)
|
||||
(gmt/inverse (in-parent objects shape-main)))))
|
||||
fix? (fn [sizing size]
|
||||
(and laid?
|
||||
(not (ctk/touched-group? shape-inst sizing))
|
||||
(contains? #{:fill :auto} (get shape-main sizing))
|
||||
(or turned? (not (mth/close? (get source size) (get shape-main size))))))
|
||||
fixed (when (ctsl/any-layout? shape-main) :fix)]
|
||||
(cond-> {}
|
||||
(fix? :layout-item-h-sizing :width) (assoc :layout-item-h-sizing fixed)
|
||||
(fix? :layout-item-v-sizing :height) (assoc :layout-item-v-sizing fixed))))
|
||||
|
||||
(defn- update-main-shape
|
||||
"Push the copy shape `shape-inst` into `shape-main`, the main shape it
|
||||
pairs with: the copy's values, overrides included, go into the main, and
|
||||
@ -937,18 +977,26 @@
|
||||
[changes {:keys [container main-container root-inst root-main remote-synced inherited-turn kept? keep-name?]} shape-inst shape-main]
|
||||
(let [;; the root of a variant keeps its name, and the copy its override of it
|
||||
keep-name? (and keep-name? (= (:id shape-inst) (:id root-inst)))
|
||||
inst-touched (cond-> (:touched shape-inst) keep-name? (disj :name-group))]
|
||||
inst-touched (cond-> (:touched shape-inst) keep-name? (disj :name-group))
|
||||
source (cond-> shape-inst
|
||||
keep-name? (assoc :name (:name shape-main))
|
||||
(some? inherited-turn) inherited-turn
|
||||
kept? (with-main-geometry shape-main
|
||||
(cond-> root-inst (some? inherited-turn) inherited-turn)
|
||||
root-main))
|
||||
;; the axes a layout sized that take the pushed size, fixed as a resize fixes them
|
||||
fixed (when-not kept? (pushed-size-sizing (:objects main-container) shape-main
|
||||
(:objects container) shape-inst source))]
|
||||
(cond-> (-> changes
|
||||
(update-attrs shape-main
|
||||
(cond-> shape-inst
|
||||
keep-name? (assoc :name (:name shape-main))
|
||||
(some? inherited-turn) inherited-turn
|
||||
kept? (with-main-geometry shape-main
|
||||
(cond-> root-inst (some? inherited-turn) inherited-turn)
|
||||
root-main))
|
||||
source
|
||||
root-main
|
||||
(cond-> root-inst (some? inherited-turn) inherited-turn)
|
||||
main-container false)
|
||||
;; the copy keeps the sizing it pushed
|
||||
(cond-> (seq fixed)
|
||||
(-> (set-sizing main-container shape-main fixed)
|
||||
(set-sizing container shape-inst fixed)))
|
||||
;; the copy keeps its swap, and the main takes the copy's overrides
|
||||
(set-touched shape-inst container
|
||||
(not-empty (cond-> #{}
|
||||
|
||||
@ -2125,6 +2125,32 @@
|
||||
[:nest 6 3 3] [:add-variant 1 5 5] [:rotate 0 4 5] [:nest 3 3 4] [:switch]
|
||||
[:switch] [:transform 0 4 0 2] [:update-main]]}))))
|
||||
|
||||
(t/deftest updating-a-fill-main-from-a-resized-copy-fixes-the-main-size
|
||||
(t/is (map? (cg/run {:world [1 0 {:variants true :text-styles false :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants false
|
||||
:layout-children false :grid-empty false :layout-copies false :text false}]
|
||||
:ops [[:combine] [:swap] [:make-variant] [:style 0 30 1] [:detach] [:detach]
|
||||
[:switch] [:resize] [:nest] [:switch] [:update-main]]}))))
|
||||
|
||||
(t/deftest updating-a-turned-fill-main-from-its-copy-fixes-the-main-size
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles false :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:remove-child 12] [:combine 6] [:combine 18] [:combine] [:make-variant 18]
|
||||
[:style 4 30 1] [:rotate 8] [:make-variant 5] [:update-main]]}))))
|
||||
|
||||
(t/deftest updating-a-main-with-a-turned-copy-keeps-the-fill-of-its-laid-out-children
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :flex :layout-item-margins false
|
||||
:grid-square false :library true :rich-variants true :layout-children false
|
||||
:grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:style 0 29 1] [:rotate 23 0 0 0] [:edit 3 0 1 1] [:update-main 3]]}))))
|
||||
|
||||
(t/deftest updating-a-main-whose-copy-padding-resized-a-fill-child-keeps-its-fill
|
||||
(t/is (map? (cg/run {:world [1 2 {:variants false :text-styles false :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants false
|
||||
:layout-children true :grid-empty true :layout-copies true :text true}]
|
||||
:ops [[:make-variant 1] [:style 4 29 1] [:style 7 12] [:update-main]]}))))
|
||||
|
||||
(t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry
|
||||
(t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user