From c19e0159985e90035692d40e7ad99a397f84a6c5 Mon Sep 17 00:00:00 2001 From: Igor Pidik Date: Sat, 1 Oct 2022 12:32:12 +0200 Subject: [PATCH 1/2] table col separator control --- widgets/table.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/widgets/table.go b/widgets/table.go index 05391ad..467f973 100644 --- a/widgets/table.go +++ b/widgets/table.go @@ -25,6 +25,7 @@ type Table struct { ColumnWidths []int TextStyle Style RowSeparator bool + ColSeparator bool TextAlignment Alignment RowStyles map[int]Style FillRow bool @@ -38,6 +39,7 @@ func NewTable() *Table { Block: *NewBlock(), TextStyle: Theme.Table.Text, RowSeparator: true, + ColSeparator: true, RowStyles: make(map[int]Style), ColumnResizer: func() {}, } @@ -107,21 +109,23 @@ func (self *Table) Draw(buf *Buffer) { colXCoordinate += columnWidths[j] + 1 } - // draw vertical separators separatorStyle := self.Block.BorderStyle - separatorXCoordinate := self.Inner.Min.X - verticalCell := NewCell(VERTICAL_LINE, separatorStyle) - for i, width := range columnWidths { - if self.FillRow && i < len(columnWidths)-1 { - verticalCell.Style.Bg = rowStyle.Bg - } else { - verticalCell.Style.Bg = self.Block.BorderStyle.Bg - } + if self.ColSeparator { + // draw vertical separators + separatorXCoordinate := self.Inner.Min.X + verticalCell := NewCell(VERTICAL_LINE, separatorStyle) + for i, width := range columnWidths { + if self.FillRow && i < len(columnWidths)-1 { + verticalCell.Style.Bg = rowStyle.Bg + } else { + verticalCell.Style.Bg = self.Block.BorderStyle.Bg + } - separatorXCoordinate += width - buf.SetCell(verticalCell, image.Pt(separatorXCoordinate, yCoordinate)) - separatorXCoordinate++ + separatorXCoordinate += width + buf.SetCell(verticalCell, image.Pt(separatorXCoordinate, yCoordinate)) + separatorXCoordinate++ + } } yCoordinate++ From e2f763c193b4e4d9af3e51b6637d4acca8132fe3 Mon Sep 17 00:00:00 2001 From: Igor Pidik Date: Sun, 2 Oct 2022 19:46:53 +0200 Subject: [PATCH 2/2] example of borderless table --- _examples/table.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/_examples/table.go b/_examples/table.go index af74957..eb2fa2b 100644 --- a/_examples/table.go +++ b/_examples/table.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a MIT license that can // be found in the LICENSE file. +//go:build ignore // +build ignore package main @@ -61,6 +62,21 @@ func main() { 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() for { e := <-uiEvents