2
0
mirror of https://github.com/rivo/tview.git synced 2024-11-03 09:40:25 +00:00

Various improvements.

This commit is contained in:
Oliver 2018-01-01 21:50:20 +01:00
parent 759602af1b
commit 8c9be84ef8
5 changed files with 41 additions and 7 deletions

View File

@ -106,10 +106,6 @@ func (a *Application) Run() error {
}()
// Draw the screen for the first time.
if a.rootAutoSize && a.root != nil {
width, height := a.screen.Size()
a.root.SetRect(0, 0, width, height)
}
a.Unlock()
a.Draw()
@ -201,6 +197,12 @@ func (a *Application) Draw() *Application {
return a
}
// Resize if requested.
if a.rootAutoSize && a.root != nil {
width, height := a.screen.Size()
a.root.SetRect(0, 0, width, height)
}
// Draw all primitives.
a.root.Draw(a.screen)
@ -219,6 +221,9 @@ func (a *Application) SetRoot(root Primitive, autoSize bool) *Application {
a.Lock()
a.root = root
a.rootAutoSize = autoSize
if a.screen != nil {
a.screen.Clear()
}
a.Unlock()
a.SetFocus(root)

View File

@ -64,8 +64,8 @@ func (f *Frame) AddText(text string, header bool, align int, color tcell.Color)
return f
}
// ClearText removes all text from the frame.
func (f *Frame) ClearText() *Frame {
// Clear removes all text from the frame.
func (f *Frame) Clear() *Frame {
f.text = nil
return f
}

View File

@ -111,7 +111,7 @@ func (m *Modal) Draw(screen tcell.Screen) {
// width is now without the box border.
// Reset the text and find out how wide it is.
m.frame.ClearText()
m.frame.Clear()
lines := WordWrap(m.text, width)
for _, line := range lines {
m.frame.AddText(line, true, AlignCenter, m.textColor)

View File

@ -78,6 +78,16 @@ func (p *Pages) RemovePage(name string) *Pages {
return p
}
// HasPage returns true if a page with the given name exists in this object.
func (p *Pages) HasPage(name string) bool {
for _, page := range p.pages {
if page.Name == name {
return true
}
}
return false
}
// ShowPage sets a page's visibility to "true" (in addition to any other pages
// which are already visible).
func (p *Pages) ShowPage(name string) *Pages {

View File

@ -257,6 +257,12 @@ func (t *Table) SetCell(row, column int, cell *TableCell) *Table {
return t
}
// SetCellSimple calls SetCell() with the given text, left-aligned, in white.
func (t *Table) SetCellSimple(row, column int, text string) *Table {
t.SetCell(row, column, &TableCell{Text: text, Align: AlignLeft, Color: tcell.ColorWhite})
return t
}
// GetCell returns the contents of the cell at the specified position. A valid
// TableCell object is always returns but it will be uninitialized if the cell
// was not previously set.
@ -267,6 +273,19 @@ func (t *Table) GetCell(row, column int) *TableCell {
return t.cells[row][column]
}
// GetRowCount returns the number of rows in the table.
func (t *Table) GetRowCount() int {
return len(t.cells)
}
// GetColumnCount returns the (maximum) number of columns in the table.
func (t *Table) GetColumnCount() int {
if len(t.cells) == 0 {
return 0
}
return t.lastColumn + 1
}
// ScrollToBeginning scrolls the table to the beginning to that the top left
// corner of the table is shown. Note that this position may be corrected if
// there is a selection.