gomp/ui/app.go

95 lines
2.7 KiB
Go
Raw Normal View History

package ui
import (
"github.com/aditya-K2/tview"
2021-10-24 01:56:10 -06:00
"github.com/gdamore/tcell/v2"
)
2021-10-24 01:56:10 -06:00
var IMG_X, IMG_Y, IMG_W, IMG_H int
type Application struct {
App *tview.Application
2021-11-13 04:27:54 -07:00
ExpandedView *tview.Table
Navbar *tview.Table
SearchBar *tview.InputField
2021-11-13 04:27:54 -07:00
ProgressBar *progressBar
Pages *tview.Pages
}
func NewApplication() *Application {
2021-12-22 05:24:14 -07:00
var pBar *progressBar = newProgressBar()
expandedView := tview.NewTable()
Navbar := tview.NewTable()
searchBar := tview.NewInputField()
searchBar.SetFieldBackgroundColor(tcell.ColorDefault)
imagePreviewer := tview.NewBox()
imagePreviewer.SetBorder(true)
2021-10-24 01:56:10 -06:00
imagePreviewer.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
IMG_X, IMG_Y, IMG_W, IMG_H = imagePreviewer.GetRect()
return imagePreviewer.GetInnerRect()
})
expandedView.SetBackgroundColor(tcell.ColorDefault)
Navbar.SetBackgroundColor(tcell.ColorDefault)
searchBar.SetBackgroundColor(tcell.ColorDefault)
imagePreviewer.SetBackgroundColor(tcell.ColorDefault)
searchBar.SetTitle("Search").SetTitleAlign(tview.AlignLeft)
searchBar.SetAutocompleteBackgroundColor(tcell.GetColor("#15191a"))
searchBar.SetAutocompleteSelectBackgroundColor(tcell.GetColor("#e5e5e5"))
searchBar.SetAutocompleteMainTextColor(tcell.GetColor("#7f7f7f"))
searchBar.SetAutocompleteSelectedTextColor(tcell.GetColor("#111111"))
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"))
2021-11-16 07:36:12 -07:00
Navbar.SetCell(3, 0, tview.NewTableCell("Search"))
searchNavFlex := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(Navbar, 0, 4, false).
2021-10-24 01:56:10 -06:00
AddItem(imagePreviewer, 9, 3, false)
sNavExpViewFlex := tview.NewFlex().
2021-10-24 01:56:10 -06:00
AddItem(searchNavFlex, 17, 1, false).
AddItem(expandedView, 0, 4, false)
searchBar.SetBorder(true)
searchBarFlex := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(searchBar, 3, 1, false).
AddItem(sNavExpViewFlex, 0, 1, false)
lex := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(searchBarFlex, 0, 8, false).
AddItem(pBar.t, 5, 1, false)
expandedView.SetBorderPadding(1, 1, 1, 1).SetBorder(true)
expandedView.SetSelectable(true, false)
rootPages := tview.NewPages()
rootPages.AddPage("Main", lex, true, true)
App := tview.NewApplication()
App.SetRoot(rootPages, true).SetFocus(expandedView)
searchBar.SetDoneFunc(func(k tcell.Key) {
switch k {
case tcell.KeyEscape:
{
App.SetFocus(expandedView)
}
}
})
return &Application{
App: App,
2021-11-13 04:27:54 -07:00
ExpandedView: expandedView,
Navbar: Navbar,
2021-11-13 04:27:54 -07:00
SearchBar: searchBar,
ProgressBar: pBar,
Pages: rootPages,
}
}