fix: distribute-sizes rounding remainder, render-screen uses backend-size
This commit is contained in:
@@ -76,7 +76,8 @@
|
||||
"Compute child sizes given available space and gap.
|
||||
HORIZONTAL is non-nil when distributing width (row layout).
|
||||
Each child starts from its fixed size (if any). Remaining space
|
||||
is distributed by grow ratio; overflow is reduced by shrink ratio."
|
||||
is distributed by grow ratio; overflow is reduced by shrink ratio.
|
||||
Rounding errors are amortized across the first N children."
|
||||
(let* ((n (length children))
|
||||
(gap-total (* gap (max 0 (1- n))))
|
||||
(base (mapcar (lambda (c)
|
||||
@@ -89,14 +90,25 @@ is distributed by grow ratio; overflow is reduced by shrink ratio."
|
||||
(remaining (- avail base-total gap-total))
|
||||
(grow-total (reduce #'+ (mapcar #'layout-node-grow children)))
|
||||
(shrink-total (reduce #'+ (mapcar #'layout-node-shrink children))))
|
||||
(mapcar (lambda (c b)
|
||||
(let ((sz b))
|
||||
(when (and (plusp remaining) (plusp grow-total))
|
||||
(incf sz (round (* remaining (/ (layout-node-grow c) grow-total)))))
|
||||
(when (and (minusp remaining) (plusp shrink-total))
|
||||
(decf sz (round (* (abs remaining) (/ (layout-node-shrink c) shrink-total)))))
|
||||
(max 1 sz)))
|
||||
children base)))
|
||||
(let ((sizes (mapcar (lambda (c b)
|
||||
(let ((sz b))
|
||||
(when (and (plusp remaining) (plusp grow-total))
|
||||
(incf sz (round (* remaining (/ (layout-node-grow c) grow-total)))))
|
||||
(when (and (minusp remaining) (plusp shrink-total))
|
||||
(decf sz (round (* (abs remaining) (/ (layout-node-shrink c) shrink-total)))))
|
||||
(max 1 sz)))
|
||||
children base)))
|
||||
;; Distribute rounding remainder to first N children so that
|
||||
;; the total of sizes exactly fills avail minus gap-total.
|
||||
;; Only correct when grow or shrink was actually applied —
|
||||
;; otherwise children keep their fixed sizes and may not fill space.
|
||||
(when (or (and (plusp remaining) (plusp grow-total))
|
||||
(and (minusp remaining) (plusp shrink-total)))
|
||||
(let ((delta (- avail gap-total (reduce #'+ sizes))))
|
||||
(when (/= delta 0)
|
||||
(loop :for i :from 0 :below (min (abs delta) n)
|
||||
:do (incf (nth i sizes) (signum delta))))))
|
||||
sizes)))
|
||||
|
||||
(defun compute-layout (root available-width available-height)
|
||||
"Layout all children of ROOT within the given dimensions.
|
||||
|
||||
Reference in New Issue
Block a user