2021-12-22 08:09:01 -07:00
|
|
|
package ui
|
2021-10-17 20:43:21 -06:00
|
|
|
|
|
|
|
import (
|
2021-11-15 09:19:42 -07:00
|
|
|
"github.com/aditya-K2/tview"
|
2021-10-24 01:56:10 -06:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2021-10-17 20:43:21 -06:00
|
|
|
)
|
|
|
|
|
2022-03-15 15:18:53 -06:00
|
|
|
var (
|
|
|
|
ImgY int
|
|
|
|
ImgW int
|
|
|
|
ImgH int
|
|
|
|
ImgX int
|
2022-09-01 13:55:33 -06:00
|
|
|
Ui *Application
|
2022-03-15 15:18:53 -06:00
|
|
|
)
|
2021-10-24 01:56:10 -06:00
|
|
|
|
2021-10-17 20:43:21 -06:00
|
|
|
type Application struct {
|
|
|
|
App *tview.Application
|
2021-11-13 04:27:54 -07:00
|
|
|
ExpandedView *tview.Table
|
2021-10-17 20:43:21 -06:00
|
|
|
Navbar *tview.Table
|
2021-11-15 04:01:46 -07:00
|
|
|
SearchBar *tview.InputField
|
2022-08-29 06:06:36 -06:00
|
|
|
ProgressBar *ProgressBar
|
2021-11-13 04:10:33 -07:00
|
|
|
Pages *tview.Pages
|
2021-10-17 20:43:21 -06:00
|
|
|
}
|
|
|
|
|
2021-12-22 08:09:01 -07:00
|
|
|
func NewApplication() *Application {
|
2021-10-17 20:43:21 -06:00
|
|
|
|
2022-08-29 06:06:36 -06:00
|
|
|
pBar := NewProgressBar()
|
2022-10-03 04:07:26 -06:00
|
|
|
pBar.SetProgressFunc(ProgressFunction)
|
2021-10-17 20:43:21 -06:00
|
|
|
expandedView := tview.NewTable()
|
|
|
|
Navbar := tview.NewTable()
|
2021-11-15 04:01:46 -07:00
|
|
|
searchBar := tview.NewInputField()
|
2021-11-15 09:48:27 -07:00
|
|
|
searchBar.SetFieldBackgroundColor(tcell.ColorDefault)
|
2021-10-23 14:08:55 -06:00
|
|
|
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) {
|
2022-03-15 15:18:53 -06:00
|
|
|
ImgX, ImgY, ImgW, ImgH = imagePreviewer.GetRect()
|
2021-10-24 01:56:10 -06:00
|
|
|
return imagePreviewer.GetInnerRect()
|
|
|
|
})
|
2021-10-17 20:43:21 -06:00
|
|
|
|
2021-12-16 12:36:18 -07:00
|
|
|
expandedView.SetBackgroundColor(tcell.ColorDefault)
|
|
|
|
Navbar.SetBackgroundColor(tcell.ColorDefault)
|
|
|
|
searchBar.SetBackgroundColor(tcell.ColorDefault)
|
|
|
|
imagePreviewer.SetBackgroundColor(tcell.ColorDefault)
|
|
|
|
|
2021-11-15 04:01:46 -07:00
|
|
|
searchBar.SetTitle("Search").SetTitleAlign(tview.AlignLeft)
|
2021-12-30 04:47:58 -07:00
|
|
|
searchBar.SetAutocompleteBackgroundColor(tcell.ColorBlack)
|
|
|
|
searchBar.SetAutocompleteSelectBackgroundColor(tcell.ColorWhite)
|
|
|
|
searchBar.SetAutocompleteMainTextColor(tcell.ColorDarkGray)
|
|
|
|
searchBar.SetAutocompleteSelectedTextColor(tcell.ColorBlack)
|
2021-10-17 20:43:21 -06:00
|
|
|
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"))
|
2021-10-17 20:43:21 -06:00
|
|
|
|
|
|
|
searchNavFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
2021-10-23 14:08:55 -06:00
|
|
|
AddItem(Navbar, 0, 4, false).
|
2021-10-24 01:56:10 -06:00
|
|
|
AddItem(imagePreviewer, 9, 3, false)
|
2021-10-17 20:43:21 -06:00
|
|
|
|
|
|
|
sNavExpViewFlex := tview.NewFlex().
|
2021-10-24 01:56:10 -06:00
|
|
|
AddItem(searchNavFlex, 17, 1, false).
|
2021-10-17 20:43:21 -06:00
|
|
|
AddItem(expandedView, 0, 4, false)
|
|
|
|
|
2021-11-15 04:01:46 -07:00
|
|
|
searchBar.SetBorder(true)
|
|
|
|
searchBarFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
|
|
|
AddItem(searchBar, 3, 1, false).
|
|
|
|
AddItem(sNavExpViewFlex, 0, 1, false)
|
|
|
|
|
2021-12-24 08:45:17 -07:00
|
|
|
MainFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
2021-11-15 04:01:46 -07:00
|
|
|
AddItem(searchBarFlex, 0, 8, false).
|
2022-08-29 06:06:36 -06:00
|
|
|
AddItem(pBar, 5, 1, false)
|
2021-10-17 20:43:21 -06:00
|
|
|
|
|
|
|
expandedView.SetBorderPadding(1, 1, 1, 1).SetBorder(true)
|
|
|
|
expandedView.SetSelectable(true, false)
|
|
|
|
|
2021-11-13 04:10:33 -07:00
|
|
|
rootPages := tview.NewPages()
|
2021-12-24 08:45:17 -07:00
|
|
|
rootPages.AddPage("Main", MainFlex, true, true)
|
2021-11-13 04:10:33 -07:00
|
|
|
|
2021-10-17 20:43:21 -06:00
|
|
|
App := tview.NewApplication()
|
2021-11-13 04:10:33 -07:00
|
|
|
App.SetRoot(rootPages, true).SetFocus(expandedView)
|
2021-10-17 20:43:21 -06:00
|
|
|
|
2021-11-15 09:19:42 -07:00
|
|
|
searchBar.SetDoneFunc(func(k tcell.Key) {
|
|
|
|
switch k {
|
|
|
|
case tcell.KeyEscape:
|
|
|
|
{
|
|
|
|
App.SetFocus(expandedView)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-17 20:43:21 -06:00
|
|
|
return &Application{
|
|
|
|
App: App,
|
2021-11-13 04:27:54 -07:00
|
|
|
ExpandedView: expandedView,
|
2021-10-17 20:43:21 -06:00
|
|
|
Navbar: Navbar,
|
2021-11-13 04:27:54 -07:00
|
|
|
SearchBar: searchBar,
|
|
|
|
ProgressBar: pBar,
|
2021-11-13 04:10:33 -07:00
|
|
|
Pages: rootPages,
|
2021-10-17 20:43:21 -06:00
|
|
|
}
|
2021-10-18 01:51:09 -06:00
|
|
|
|
2021-10-17 20:43:21 -06:00
|
|
|
}
|