refactor(layout): share the equal column width between fixed and cascade
- commit
- 90ccc85322e811f65957842dff90035428286d80
- author
- brice · · 2026-10-07 15:54 UTC
- parent
- 9376c1c
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +9 -8
M internal/core/cascade.go +7 -1
| @@ -19,7 +19,13 @@ func (w *Workspace) cascadeBands() (n, spacing int) { | |||
| 19 | 19 | // fills it. | |
| 20 | 20 | func (w *Workspace) cellWidth(i int) int { | |
| 21 | 21 | first, last := w.laneBounds(w.band(i)) | |
| 22 | - | k := max(last-first+1, 1) | |
| 22 | + | return w.equalShare(last - first + 1) | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | // equalShare is the width of each of k columns sharing the usable width | |
| 26 | + | // after gaps; a remainder under k pixels stays empty. | |
| 27 | + | func (w *Workspace) equalShare(k int) int { | |
| 28 | + | k = max(k, 1) | |
| 23 | 29 | return max((w.Usable.W-w.gap()*(k+1))/k, 0) | |
| 24 | 30 | } | |
| 25 | 31 | func (w *Workspace) cellInBand(b int) int { | |
| @@ -19,7 +19,13 @@ func (w *Workspace) cascadeBands() (n, spacing int) { | |||||
| 19 | // fills it. | 19 | // fills it. | ||
| 20 | func (w *Workspace) cellWidth(i int) int { | 20 | func (w *Workspace) cellWidth(i int) int { | ||
| 21 | first, last := w.laneBounds(w.band(i)) | 21 | first, last := w.laneBounds(w.band(i)) | ||
| 22 | - | k := max(last-first+1, 1) | 22 | + | return w.equalShare(last - first + 1) |
| 23 | + | } | |||
| 24 | + | ||||
| 25 | + | // equalShare is the width of each of k columns sharing the usable width | |||
| 26 | + | // after gaps; a remainder under k pixels stays empty. | |||
| 27 | + | func (w *Workspace) equalShare(k int) int { | |||
| 28 | + | k = max(k, 1) | |||
| 23 | return max((w.Usable.W-w.gap()*(k+1))/k, 0) | 29 | return max((w.Usable.W-w.gap()*(k+1))/k, 0) | ||
| 24 | } | 30 | } | ||
| 25 | func (w *Workspace) cellInBand(b int) int { | 31 | func (w *Workspace) cellInBand(b int) int { | ||
M internal/core/layout.go +2 -7
| @@ -1393,12 +1393,7 @@ func (w *Workspace) columnWidthFor(i int, ignoreFullWidth bool) int { | |||
| 1393 | 1393 | return w.cellWidth(i) | |
| 1394 | 1394 | } | |
| 1395 | 1395 | if w.Columns[i].Width == (Width{}) || w.policy().equalCells { | |
| 1396 | - | if len(w.Columns) == 1 { | |
| 1397 | - | return max(w.Usable.W-2*g, 0) | |
| 1398 | - | } | |
| 1399 | - | // Equal shares of the width left after gaps; a remainder under k pixels stays empty. | |
| 1400 | - | k := min(len(w.Columns), max(w.MaxColumns, 1)) | |
| 1401 | - | return max((w.Usable.W-g*(k+1))/k, 0) | |
| 1396 | + | return w.equalShare(min(len(w.Columns), max(w.MaxColumns, 1))) | |
| 1402 | 1397 | } | |
| 1403 | 1398 | return w.Columns[i].Width.Resolve(w.Usable.W, g) | |
| 1404 | 1399 | } | |
| @@ -1492,7 +1487,7 @@ func (w *Workspace) columnRectsInto(dst []Rect, ignoreFullWidth bool) []Rect { | |||
| 1492 | 1487 | // right; the two strips share the last cell. | |
| 1493 | 1488 | func (w *Workspace) expandedRects(rects []Rect, e, k, y, h int) []Rect { | |
| 1494 | 1489 | g := w.gap() | |
| 1495 | - | cell := max((w.Usable.W-g*(k+1))/k, 0) | |
| 1490 | + | cell := w.equalShare(k) | |
| 1496 | 1491 | wide := (k-1)*cell + (k-2)*g | |
| 1497 | 1492 | rest := max(w.Usable.W-2*g-wide-g, 0) | |
| 1498 | 1493 | before, after := w.Columns[:e], w.Columns[e+1:] | |
| @@ -1393,12 +1393,7 @@ func (w *Workspace) columnWidthFor(i int, ignoreFullWidth bool) int { | |||||
| 1393 | return w.cellWidth(i) | 1393 | return w.cellWidth(i) | ||
| 1394 | } | 1394 | } | ||
| 1395 | if w.Columns[i].Width == (Width{}) || w.policy().equalCells { | 1395 | if w.Columns[i].Width == (Width{}) || w.policy().equalCells { | ||
| 1396 | - | if len(w.Columns) == 1 { | 1396 | + | return w.equalShare(min(len(w.Columns), max(w.MaxColumns, 1))) |
| 1397 | - | return max(w.Usable.W-2*g, 0) | |||
| 1398 | - | } | |||
| 1399 | - | // Equal shares of the width left after gaps; a remainder under k pixels stays empty. | |||
| 1400 | - | k := min(len(w.Columns), max(w.MaxColumns, 1)) | |||
| 1401 | - | return max((w.Usable.W-g*(k+1))/k, 0) | |||
| 1402 | } | 1397 | } | ||
| 1403 | return w.Columns[i].Width.Resolve(w.Usable.W, g) | 1398 | return w.Columns[i].Width.Resolve(w.Usable.W, g) | ||
| 1404 | } | 1399 | } | ||
| @@ -1492,7 +1487,7 @@ func (w *Workspace) columnRectsInto(dst []Rect, ignoreFullWidth bool) []Rect { | |||||
| 1492 | // right; the two strips share the last cell. | 1487 | // right; the two strips share the last cell. | ||
| 1493 | func (w *Workspace) expandedRects(rects []Rect, e, k, y, h int) []Rect { | 1488 | func (w *Workspace) expandedRects(rects []Rect, e, k, y, h int) []Rect { | ||
| 1494 | g := w.gap() | 1489 | g := w.gap() | ||
| 1495 | - | cell := max((w.Usable.W-g*(k+1))/k, 0) | 1490 | + | cell := w.equalShare(k) |
| 1496 | wide := (k-1)*cell + (k-2)*g | 1491 | wide := (k-1)*cell + (k-2)*g | ||
| 1497 | rest := max(w.Usable.W-2*g-wide-g, 0) | 1492 | rest := max(w.Usable.W-2*g-wide-g, 0) | ||
| 1498 | before, after := w.Columns[:e], w.Columns[e+1:] | 1493 | before, after := w.Columns[:e], w.Columns[e+1:] | ||