mirror of https://github.com/rivo/tview.git
Added SetAttributes() and SetStyle() to TableCell. Resolves #111
This commit is contained in:
parent
c0b219f400
commit
a26df4e781
24
table.go
24
table.go
|
@ -33,6 +33,9 @@ type TableCell struct {
|
|||
// The background color of the cell.
|
||||
BackgroundColor tcell.Color
|
||||
|
||||
// The style attributes of the cell.
|
||||
Attributes tcell.AttrMask
|
||||
|
||||
// If set to true, this cell cannot be selected.
|
||||
NotSelectable bool
|
||||
|
||||
|
@ -107,6 +110,22 @@ func (c *TableCell) SetBackgroundColor(color tcell.Color) *TableCell {
|
|||
return c
|
||||
}
|
||||
|
||||
// SetAttributes sets the cell's text attributes. You can combine different
|
||||
// attributes using bitmask operations:
|
||||
//
|
||||
// cell.SetAttributes(tcell.AttrUnderline | tcell.AttrBold)
|
||||
func (c *TableCell) SetAttributes(attr tcell.AttrMask) *TableCell {
|
||||
c.Attributes = attr
|
||||
return c
|
||||
}
|
||||
|
||||
// SetStyle sets the cell's style (foreground color, background color, and
|
||||
// attributes) all at once.
|
||||
func (c *TableCell) SetStyle(style tcell.Style) *TableCell {
|
||||
c.Color, c.BackgroundColor, c.Attributes = style.Decompose()
|
||||
return c
|
||||
}
|
||||
|
||||
// SetSelectable sets whether or not this cell can be selected by the user.
|
||||
func (c *TableCell) SetSelectable(selectable bool) *TableCell {
|
||||
c.NotSelectable = !selectable
|
||||
|
@ -684,11 +703,10 @@ ColumnLoop:
|
|||
finalWidth = width - columnX - 1
|
||||
}
|
||||
cell.x, cell.y, cell.width = x+columnX+1, y+rowY, finalWidth
|
||||
_, printed := Print(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, cell.Color)
|
||||
_, printed := printWithStyle(screen, cell.Text, x+columnX+1, y+rowY, finalWidth, cell.Align, tcell.StyleDefault.Foreground(cell.Color)|tcell.Style(cell.Attributes))
|
||||
if StringWidth(cell.Text)-printed > 0 && printed > 0 {
|
||||
_, _, style, _ := screen.GetContent(x+columnX+1+finalWidth-1, y+rowY)
|
||||
fg, _, _ := style.Decompose()
|
||||
Print(screen, string(GraphicsEllipsis), x+columnX+1+finalWidth-1, y+rowY, 1, AlignLeft, fg)
|
||||
printWithStyle(screen, string(GraphicsEllipsis), x+columnX+1+finalWidth-1, y+rowY, 1, AlignLeft, style)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue