pull/44/head
Tony Worm 7 years ago
parent aed9ddc0cf
commit ab3a995d4b

@ -71,6 +71,7 @@ func (a *Application) Run() error {
a.Unlock()
return err
}
a.Unlock()
// We catch panics to clean up because they mess up the terminal.
defer func() {
@ -83,7 +84,6 @@ func (a *Application) Run() error {
}()
// Draw the screen for the first time.
a.Unlock()
a.Draw()
// Start event loop.

@ -129,6 +129,9 @@ func (b *Box) wrapInputHandler(inputHandler func(tcell.Event, func(p Primitive))
}
}
}
func (b *Box) WrapInputHandler(inputHandler func(tcell.Event, func(p Primitive))) func(tcell.Event, func(p Primitive)) {
return b.wrapInputHandler(inputHandler)
}
// InputHandler returns nil.
func (b *Box) InputHandler() func(event tcell.Event, setFocus func(p Primitive)) {
@ -272,6 +275,11 @@ func (b *Box) Mount(context map[string]interface{}) error {
return nil
}
// Mount is called when this primitive is mounted (by the router).
func (b *Box) Refresh(context map[string]interface{}) error {
return nil
}
// Unmount is called when this primitive is unmounted.
func (b *Box) Unmount() error {
b.isMounted = false

@ -164,6 +164,10 @@ func (p *Pages) HidePage(name string) *Pages {
// visibility to "false".
func (p *Pages) SwitchToPage(name string, context map[string]interface{}) *Pages {
if p.curr != nil {
if p.curr.Name == name {
p.curr.Item.Refresh(context)
return p
}
p.curr.Item.Unmount()
}
for _, page := range p.pages {

@ -53,6 +53,9 @@ type Primitive interface {
// Mount is a longer term context for bringing a widget into scope
Mount(context map[string]interface{}) error
// Refresh is a longer term context for bringing a widget into scope
Refresh(context map[string]interface{}) error
// Unmount is the opposite of mount
Unmount() error

@ -161,6 +161,9 @@ func (c *TableCell) GetLastPosition() (x, y, width int) {
type Table struct {
*Box
// If the table is smaller than the space, how to position
align int
// Whether or not this table has borders around each cell.
borders bool
@ -228,6 +231,13 @@ func (t *Table) Clear() *Table {
return t
}
// SetAlign sets the table's positioning within the space.
// This only takes effect when the table is smaller than the space provided
func (t *Table) SetAlign(align int) *Table {
t.align = align
return t
}
// SetBorders sets whether or not each cell in the table is surrounded by a
// border.
func (t *Table) SetBorders(show bool) *Table {
@ -428,7 +438,7 @@ func (t *Table) Draw(screen tcell.Screen) {
return t.cells[row][column]
}
// If this cell is not selectable, find the next one.
// If this cell is selectable, find the next one.
if t.rowsSelectable || t.columnsSelectable {
if t.selectedColumn < 0 {
t.selectedColumn = 0
@ -470,10 +480,14 @@ func (t *Table) Draw(screen tcell.Screen) {
if t.borders {
if 2*(len(t.cells)-t.rowOffset) < height {
t.trackEnd = true
} else {
t.trackEnd = false
}
} else {
if len(t.cells)-t.rowOffset < height {
t.trackEnd = true
} else {
t.trackEnd = false
}
}
if t.trackEnd {
@ -584,6 +598,16 @@ ColumnLoop:
}
t.columnOffset = skipped
// If we are smaller than our space and have alignment
if tableWidth < width {
if t.align == AlignCenter {
x += (width - tableWidth) / 2
}
if t.align == AlignRight {
x += (width - tableWidth)
}
}
// Helper function which draws border runes.
borderStyle := tcell.StyleDefault.Background(t.backgroundColor).Foreground(t.bordersColor)
drawBorder := func(colX, rowY int, ch rune) {

Loading…
Cancel
Save