mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🚑 Lay out a single-line flex board aligned by space-between
A wrapped flex board whose content is aligned by space-between shares its free space between its lines, dividing it by the number of lines minus one. With a single line and integer sizes that is a division by zero, which throws in Clojure. The gap after a single line goes unused, so it now takes the layout's own gap. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.49 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 41.045 | 0.60 | | library-update-into-copies | 83.083 | 51.057 | 0.61 | | main-edit-among-many-shapes | 4.837 | 2.253 | 0.47 | | main-edit-into-10-copies | 1.79 | 1.055 | 0.59 | | main-edit-into-100-copies | 15.415 | 9.948 | 0.65 | | main-edit-into-1000-copies | 153.086 | 108.962 | 0.71 | | variant-switch-into-copies | 32.052 | 21.743 | 0.68 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
3beb329bc7
commit
c73b30cb56
@ -98,7 +98,8 @@
|
||||
stretch?
|
||||
(/ free-width num-lines)
|
||||
|
||||
between?
|
||||
;; a single line has no gap to share
|
||||
(and between? (> num-lines 1))
|
||||
(/ free-width (dec num-lines))
|
||||
|
||||
around?
|
||||
@ -118,7 +119,7 @@
|
||||
stretch?
|
||||
(/ free-height num-lines)
|
||||
|
||||
between?
|
||||
(and between? (> num-lines 1))
|
||||
(/ free-height (dec num-lines))
|
||||
|
||||
around?
|
||||
|
||||
@ -60,6 +60,15 @@
|
||||
(t/is (== (if (= children 1) (if row? 7 11) (if row? 100 140)) gap))
|
||||
(t/is (every? mth/finite? (map line [:layout-gap-col :layout-gap-row :margin-x :margin-y]))))))
|
||||
|
||||
(t/deftest next-line-after-a-single-space-between-line-is-finite
|
||||
(doseq [direction [:row :column]]
|
||||
(let [frame (make-col-frame :layout-flex-dir direction
|
||||
:layout-align-content :space-between)
|
||||
bounds (rect->bounds (grc/make-rect 0 0 200 200))
|
||||
base-p (flp/get-base-line frame bounds 50 30 1)
|
||||
next-p (flp/get-next-line frame bounds {:line-width 50 :line-height 30} base-p 50 30 1)]
|
||||
(t/is (every? mth/finite? [(:x next-p) (:y next-p)])))))
|
||||
|
||||
;; ---- get-base-line (around? branch) ----
|
||||
;;
|
||||
;; Bug: in positions.cljc the col? + around? branch had a mis-parenthesised
|
||||
|
||||
@ -1019,3 +1019,10 @@
|
||||
:library-depth 1 :library true :rich-variants true :library-text true
|
||||
:layout-copies true :text true}]
|
||||
:ops [[:transform 0 4 0 2] [:switch 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-single-line-flex-set-to-space-between-lays-out
|
||||
;; aligning the content of a one-line wrapped flex main by space-between
|
||||
;; leaves no gap to share between its lines
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :layout :flex :library true
|
||||
:rich-variants true :layout-copies true :text true}]
|
||||
:ops [[:style 0 23 18 0]]}))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user