diff --git a/application.go b/application.go index 9b5db65..cdf01bf 100644 --- a/application.go +++ b/application.go @@ -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) diff --git a/frame.go b/frame.go index a1a5b72..473df78 100644 --- a/frame.go +++ b/frame.go @@ -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 } diff --git a/modal.go b/modal.go index 57aed4d..51d3e6b 100644 --- a/modal.go +++ b/modal.go @@ -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) diff --git a/pages.go b/pages.go index b2166fd..6e83d2c 100644 --- a/pages.go +++ b/pages.go @@ -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 { diff --git a/table.go b/table.go index b1e1c73..94a9328 100644 --- a/table.go +++ b/table.go @@ -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.