mirror of
https://github.com/penpot/penpot.git
synced 2026-10-28 21:40:34 +00:00
🐛 Keep single-child flex spacing finite
Compute a space-between gap only when a line has at least two children. A one-child line keeps its configured gap instead of dividing by zero. Cover both row and column directions, including reversed layouts, finite spacing fields and unchanged two-child distribution. AI-assisted-by: GPT-6
This commit is contained in:
parent
ceb24fbf6d
commit
4a40c10962
@ -361,7 +361,7 @@
|
||||
(and row? space-around?)
|
||||
(/ (max layout-gap-col (/ (- width line-width) num-children)) 2)
|
||||
|
||||
(and row? space-between? (not auto-width?))
|
||||
(and row? space-between? (not auto-width?) (> num-children 1))
|
||||
(max layout-gap-col (/ (- width line-width) (dec num-children)))
|
||||
|
||||
:else
|
||||
@ -374,7 +374,7 @@
|
||||
(and col? space-around?)
|
||||
(/ (max layout-gap-row (/ (- height line-height) num-children)) 2)
|
||||
|
||||
(and col? space-between? (not auto-height?))
|
||||
(and col? space-between? (not auto-height?) (> num-children 1))
|
||||
(max layout-gap-row (/ (- height line-height) (dec num-children)))
|
||||
|
||||
:else
|
||||
|
||||
@ -44,6 +44,22 @@
|
||||
bounds (rect->bounds (grc/make-rect 0 0 200 200))]
|
||||
(t/is (= [] (:layout-lines (fld/calc-layout-data frame bounds [] {} {})))))))
|
||||
|
||||
(t/deftest space-between-distributes-gap-only-between-several-children
|
||||
(doseq [direction [:row :row-reverse :column :column-reverse]
|
||||
children [1 2]]
|
||||
(let [row? (#{:row :row-reverse} direction)
|
||||
frame (make-col-frame :layout-flex-dir direction
|
||||
:layout-justify-content :space-between
|
||||
:layout-gap {:row-gap 11 :column-gap 7})
|
||||
bounds (rect->bounds (grc/make-rect 0 0 200 200))
|
||||
line (fld/add-line-spacing frame bounds false
|
||||
{:num-children children
|
||||
:line-width (if row? (* 50 children) 50)
|
||||
:line-height (if row? 30 (* 30 children))})
|
||||
gap (get line (if row? :layout-gap-col :layout-gap-row))]
|
||||
(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]))))))
|
||||
|
||||
;; ---- get-base-line (around? branch) ----
|
||||
;;
|
||||
;; Bug: in positions.cljc the col? + around? branch had a mis-parenthesised
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user