Skip to content
Snippets Groups Projects

V.0.1.0 Codename Threadbare

Closed Ghost User requested to merge v.0.1.0-codename-threadbare into master
4 files
+ 61
4
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 68
0
package app
//TODO: App should be a Singleton i guess
import (
"github.com/rivo/tview"
)
type view interface {
GetContent() tview.Primitive
}
//App is a GUI-Application bases on tview
type App struct {
app *tview.Application
pages *tview.Pages
}
//NewApp creates a new GUI-Application
func NewApp() *App {
a := &App{
app: tview.NewApplication(),
}
return a
}
//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)
}
//Run starts the GUI-Application
func (a *App) Run() error {
return a.app.Run()
}
//Stop stops the GUI-Application
func (a *App) Stop() {
a.app.Stop()
}
//Draw calls tview.Draw()
func (a *App) Draw() {
a.app.Draw()
}
//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)
}
Loading