1
0
mirror of https://github.com/gizak/termui.git synced 2025-04-27 13:48:51 +08:00

Merge e2f763c193b4e4d9af3e51b6637d4acca8132fe3 into 2b8f0c7960e9553acea6d579a740713066da5e13

This commit is contained in:
Igor Pidik 2024-01-30 02:58:06 -08:00 committed by GitHub
commit 6619b760f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 12 deletions

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT license that can // Use of this source code is governed by a MIT license that can
// be found in the LICENSE file. // be found in the LICENSE file.
//go:build ignore
// +build ignore // +build ignore
package main package main
@ -61,6 +62,21 @@ func main() {
ui.Render(table3) ui.Render(table3)
borderlessTable := widgets.NewTable()
borderlessTable.Rows = [][]string{
[]string{"header1", "header2", "header3"},
[]string{"Foundations", "Go-lang is so cool", "Im working on Ruby"},
[]string{"2016", "11", "11"},
}
borderlessTable.TextStyle = ui.NewStyle(ui.ColorWhite)
borderlessTable.TextAlignment = ui.AlignCenter
borderlessTable.SetRect(0, 30, 60, 35)
borderlessTable.Border = false
borderlessTable.RowSeparator = false
borderlessTable.ColSeparator = false
ui.Render(borderlessTable)
uiEvents := ui.PollEvents() uiEvents := ui.PollEvents()
for { for {
e := <-uiEvents e := <-uiEvents

View File

@ -25,6 +25,7 @@ type Table struct {
ColumnWidths []int ColumnWidths []int
TextStyle Style TextStyle Style
RowSeparator bool RowSeparator bool
ColSeparator bool
TextAlignment Alignment TextAlignment Alignment
RowStyles map[int]Style RowStyles map[int]Style
FillRow bool FillRow bool
@ -38,6 +39,7 @@ func NewTable() *Table {
Block: *NewBlock(), Block: *NewBlock(),
TextStyle: Theme.Table.Text, TextStyle: Theme.Table.Text,
RowSeparator: true, RowSeparator: true,
ColSeparator: true,
RowStyles: make(map[int]Style), RowStyles: make(map[int]Style),
ColumnResizer: func() {}, ColumnResizer: func() {},
} }
@ -107,9 +109,10 @@ func (self *Table) Draw(buf *Buffer) {
colXCoordinate += columnWidths[j] + 1 colXCoordinate += columnWidths[j] + 1
} }
// draw vertical separators
separatorStyle := self.Block.BorderStyle separatorStyle := self.Block.BorderStyle
if self.ColSeparator {
// draw vertical separators
separatorXCoordinate := self.Inner.Min.X separatorXCoordinate := self.Inner.Min.X
verticalCell := NewCell(VERTICAL_LINE, separatorStyle) verticalCell := NewCell(VERTICAL_LINE, separatorStyle)
for i, width := range columnWidths { for i, width := range columnWidths {
@ -123,6 +126,7 @@ func (self *Table) Draw(buf *Buffer) {
buf.SetCell(verticalCell, image.Pt(separatorXCoordinate, yCoordinate)) buf.SetCell(verticalCell, image.Pt(separatorXCoordinate, yCoordinate))
separatorXCoordinate++ separatorXCoordinate++
} }
}
yCoordinate++ yCoordinate++