Browse Source

Various improvements.

tablepad v0.1.1
Oliver 5 years ago
parent
commit
8c9be84ef8
  1. 13
      application.go
  2. 4
      frame.go
  3. 2
      modal.go
  4. 10
      pages.go
  5. 19
      table.go

13
application.go

@ -106,10 +106,6 @@ func (a *Application) Run() error { @@ -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 { @@ -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 { @@ -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)

4
frame.go

@ -64,8 +64,8 @@ func (f *Frame) AddText(text string, header bool, align int, color tcell.Color) @@ -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
}

2
modal.go

@ -111,7 +111,7 @@ func (m *Modal) Draw(screen tcell.Screen) { @@ -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)

10
pages.go

@ -78,6 +78,16 @@ func (p *Pages) RemovePage(name string) *Pages { @@ -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 {

19
table.go

@ -257,6 +257,12 @@ func (t *Table) SetCell(row, column int, cell *TableCell) *Table { @@ -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 { @@ -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.

Loading…
Cancel
Save