Newer
Older
import (
"github.com/rivo/tview"
)
type view interface {
GetContent() tview.Primitive
}
//App is a GUI-Application bases on tview
//NewApp creates a new GUI-Application
func NewApp() *App {
a := &App{
app: tview.NewApplication(),
}
//SetRoot sets the root of the GUI-Application
func (a *App) SetRoot(v view) {
a.pages = v.GetContent().(*tview.Pages)
a.app.SetRoot(a.pages, true)
}
//SwitchPage switches to the given (as string) tview page
func (a *App) SwitchPage(s string) {
if a.pages.HasPage(s) {
a.pages.SwitchToPage(s)
}
}
//AddPage adds a new view as page that can be switched to
func (a *App) AddPage(name string, p view) {
a.pages.AddPage(name, p.GetContent(), true, false)
func (a *App) Run() error {
return a.app.Run()
}
//QueueUpdateDraw calls tview.QueueUpdateDraw()
func (a *App) QueueUpdateDraw(f func()) {
a.app.QueueUpdateDraw(f)
}
//SetFocus sets the focus on new tview.Primitive
func (a *App) SetFocus(v tview.Primitive) {
a.app.SetFocus(v)
}