reworked calculation for expandable column width

This also fixes two bugs:

1. the background for selected cells/colums now matches the
   actual column
2. the remaining space was off by one, when the table has no
   border
pull/62/head
Dominik Menke 7 years ago
parent a8999a4a2d
commit a934652b35

@ -601,18 +601,26 @@ ColumnLoop:
screen.SetContent(x+colX, y+rowY, ch, nil, borderStyle)
}
// Helper function which returns the width for a column. If there's enough
// horizontal space, and the given index matches the expandableColumn,
// this will increase a columns width by remaining horizontal space.
expandX := width - tableWidth
colWidth := func(columnIndex int) (w int) {
w = widths[columnIndex]
if t.expandableColumn == columnIndex && tableWidth < width {
w += expandX
}
return w
}
// Draw the cells (and borders).
var columnX int
if !t.borders {
expandX++
columnX--
}
for columnIndex, column := range columns {
columnWidth := widths[columnIndex]
// Consume remaining horizontal space.
if t.expandableColumn == columnIndex && tableWidth < width {
columnWidth += width - tableWidth
}
columnWidth := colWidth(columnIndex)
for rowY, row := range rows {
if t.borders {
@ -732,7 +740,7 @@ ColumnLoop:
columnX := 0
rowSelected := t.rowsSelectable && !t.columnsSelectable && row == t.selectedRow
for columnIndex, column := range columns {
columnWidth := widths[columnIndex]
columnWidth := colWidth(columnIndex)
cell := getCell(row, column)
if cell == nil {
continue

Loading…
Cancel
Save