mirror of https://github.com/rivo/tview.git
Added SetSelectorWrap
This commit is contained in:
parent
8e58f395ad
commit
387d52311e
34
table.go
34
table.go
|
@ -461,6 +461,10 @@ type Table struct {
|
||||||
// versa).
|
// versa).
|
||||||
wrapHorizontally, wrapVertically bool
|
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
|
// The number of rows/columns by which the table is scrolled down/to the
|
||||||
// right.
|
// right.
|
||||||
rowOffset, columnOffset int
|
rowOffset, columnOffset int
|
||||||
|
@ -829,6 +833,16 @@ func (t *Table) SetWrapSelection(vertical, horizontal bool) *Table {
|
||||||
return t
|
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.
|
// Draw draws this primitive onto the screen.
|
||||||
func (t *Table) Draw(screen tcell.Screen) {
|
func (t *Table) Draw(screen tcell.Screen) {
|
||||||
t.Box.DrawForSubclass(screen, t)
|
t.Box.DrawForSubclass(screen, t)
|
||||||
|
@ -1258,9 +1272,27 @@ func (t *Table) Draw(screen tcell.Screen) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bx, by, bw, bh := x+columnX, y+rowY, columnWidth+1, 1
|
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 {
|
if t.borders {
|
||||||
by = y + rowY*2
|
by = y + rowY*2
|
||||||
bw++
|
if !t.selectorWrap {
|
||||||
|
bw++
|
||||||
|
}
|
||||||
bh = 3
|
bh = 3
|
||||||
}
|
}
|
||||||
columnSelected := t.columnsSelectable && !t.rowsSelectable && column == t.selectedColumn
|
columnSelected := t.columnsSelectable && !t.rowsSelectable && column == t.selectedColumn
|
||||||
|
|
Loading…
Reference in New Issue