mirror of
https://github.com/rivo/tview.git
synced 2025-04-26 13:49:06 +08:00
Merge 387d52311e20fab89831936f913ba7e2aa773ee9 into c76f7879f592d17e9e68a1d795a85faae6cb7414
This commit is contained in:
commit
fbf8941b28
34
table.go
34
table.go
@ -498,6 +498,10 @@ type Table struct {
|
||||
// versa).
|
||||
wrapHorizontally, wrapVertically bool
|
||||
|
||||
// When set to true, this flag will cause the selector to wrap around the text
|
||||
// instead of spanning across the entire column width.
|
||||
selectorWrap bool
|
||||
|
||||
// The number of rows/columns by which the table is scrolled down/to the
|
||||
// right.
|
||||
rowOffset, columnOffset int
|
||||
@ -869,6 +873,16 @@ func (t *Table) SetWrapSelection(vertical, horizontal bool) *Table {
|
||||
return t
|
||||
}
|
||||
|
||||
// SetSelectorWrap will ensure that the selector does not extend across the entire
|
||||
// column width, instead it will wrap around the length of the text in the currently
|
||||
// selected TableCell.
|
||||
//
|
||||
// The default value is false.
|
||||
func (t *Table) SetSelectorWrap(wrap bool) *Table {
|
||||
t.selectorWrap = wrap
|
||||
return t
|
||||
}
|
||||
|
||||
// Draw draws this primitive onto the screen.
|
||||
func (t *Table) Draw(screen tcell.Screen) {
|
||||
t.Box.DrawForSubclass(screen, t)
|
||||
@ -1303,9 +1317,27 @@ func (t *Table) Draw(screen tcell.Screen) {
|
||||
continue
|
||||
}
|
||||
bx, by, bw, bh := x+columnX, y+rowY, columnWidth+1, 1
|
||||
if t.selectorWrap {
|
||||
textlen := TaggedStringWidth(cell.Text)
|
||||
if columnWidth+1 >= textlen {
|
||||
if cell.Align == AlignRight {
|
||||
bx += (columnWidth - textlen)
|
||||
} else if cell.Align == AlignCenter {
|
||||
bx += ((columnWidth - textlen) / 2) + 1
|
||||
} else if cell.Align == AlignLeft && t.borders {
|
||||
bx += 2
|
||||
}
|
||||
|
||||
bw = textlen
|
||||
} else if columnWidth+1 < textlen {
|
||||
bw = columnWidth + 1
|
||||
}
|
||||
}
|
||||
if t.borders {
|
||||
by = y + rowY*2
|
||||
bw++
|
||||
if !t.selectorWrap {
|
||||
bw++
|
||||
}
|
||||
bh = 3
|
||||
}
|
||||
columnSelected := t.columnsSelectable && !t.rowsSelectable && column == t.selectedColumn
|
||||
|
Loading…
x
Reference in New Issue
Block a user