Refactored the Startup Setup into A new Struct
- Added A new Struct Application which has all the other components as its fields -- the `newApplication()` Function returns a pointer to the newly created Application from which other fields can be accessed. The fields are as follows | App *tview.Application | expandedView *tview.Table | Navbar *tview.Table | searchBar *tview.Table | pBar *progressBar - Minor changes to main.go
This commit is contained in:
55
App.go
Normal file
55
App.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/fhs/gompd/mpd"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
App *tview.Application
|
||||
expandedView *tview.Table
|
||||
Navbar *tview.Table
|
||||
searchBar *tview.Table
|
||||
pBar *progressBar
|
||||
}
|
||||
|
||||
func newApplication(conn mpd.Client) *Application {
|
||||
|
||||
var pBar *progressBar = newProgressBar(conn)
|
||||
expandedView := tview.NewTable()
|
||||
Navbar := tview.NewTable()
|
||||
searchBar := tview.NewTable()
|
||||
|
||||
searchBar.SetBorder(true).SetTitle("Search").SetTitleAlign(tview.AlignLeft)
|
||||
Navbar.SetBorder(true)
|
||||
Navbar.SetSelectable(true, false)
|
||||
Navbar.SetCell(0, 0, tview.NewTableCell("PlayList"))
|
||||
Navbar.SetCell(1, 0, tview.NewTableCell("Files"))
|
||||
Navbar.SetCell(2, 0, tview.NewTableCell("Most Played"))
|
||||
|
||||
searchNavFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(searchBar, 0, 1, false).
|
||||
AddItem(Navbar, 0, 7, false)
|
||||
|
||||
sNavExpViewFlex := tview.NewFlex().
|
||||
AddItem(searchNavFlex, 0, 1, false).
|
||||
AddItem(expandedView, 0, 4, false)
|
||||
|
||||
mainFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(sNavExpViewFlex, 0, 8, false).
|
||||
AddItem(pBar.t, 0, 1, false)
|
||||
|
||||
expandedView.SetBorderPadding(1, 1, 1, 1).SetBorder(true)
|
||||
expandedView.SetSelectable(true, false)
|
||||
|
||||
App := tview.NewApplication()
|
||||
App.SetRoot(mainFlex, true).SetFocus(expandedView)
|
||||
|
||||
return &Application{
|
||||
App: App,
|
||||
expandedView: expandedView,
|
||||
Navbar: Navbar,
|
||||
searchBar: searchBar,
|
||||
pBar: pBar,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user