mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-07 21:13:50 -05:00
Embed Pages in Root
This commit is contained in:
@@ -389,7 +389,7 @@ func NewApplication() *tview.Application {
|
||||
AddItem(progressBar, 5, 1, false)
|
||||
|
||||
root.Primitive("Main", Flex)
|
||||
App.SetRoot(root.Root, true).SetFocus(Main)
|
||||
App.SetRoot(root, true).SetFocus(Main)
|
||||
|
||||
// Start Routines
|
||||
InitNotifier()
|
||||
|
||||
@@ -136,7 +136,7 @@ func notify(n *notification) {
|
||||
npos = posArr.GetNextPosition()
|
||||
}
|
||||
n.position = npos
|
||||
root.Root.AddPage(currentTime, n, false, true)
|
||||
root.AddPage(currentTime, n, false, true)
|
||||
App.Draw()
|
||||
App.SetFocus(Main)
|
||||
if n.msg != nil {
|
||||
@@ -144,7 +144,7 @@ func notify(n *notification) {
|
||||
App.Draw()
|
||||
}
|
||||
time.Sleep(n.timer)
|
||||
root.Root.RemovePage(currentTime)
|
||||
root.RemovePage(currentTime)
|
||||
posArr.Free(npos)
|
||||
App.SetFocus(Main)
|
||||
App.Draw()
|
||||
|
||||
21
ui/root.go
21
ui/root.go
@@ -4,26 +4,21 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aditya-K2/gspt/config"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type Root struct {
|
||||
Root *tview.Pages
|
||||
*tview.Pages
|
||||
after func()
|
||||
}
|
||||
|
||||
func NewRoot() *Root {
|
||||
m := &Root{}
|
||||
|
||||
Root := tview.NewPages()
|
||||
|
||||
m.Root = Root
|
||||
return m
|
||||
return &Root{tview.NewPages(), nil}
|
||||
}
|
||||
|
||||
func (m *Root) Primitive(name string, t tview.Primitive) {
|
||||
m.Root.AddPage(name, t, true, true)
|
||||
m.AddPage(name, t, true, true)
|
||||
}
|
||||
|
||||
func (m *Root) AfterContextClose(f func()) {
|
||||
@@ -42,16 +37,16 @@ func (m *Root) AddCenteredWidget(t CenteredWidget) {
|
||||
closec := make(chan bool)
|
||||
currentTime := time.Now().String()
|
||||
sHandler := t.SelectionHandler()
|
||||
_, _, w, h := m.Root.GetRect()
|
||||
_, _, w, h := m.GetRect()
|
||||
|
||||
closeCtx := func() {
|
||||
m.Root.RemovePage(currentTime)
|
||||
m.RemovePage(currentTime)
|
||||
if m.after != nil {
|
||||
m.after()
|
||||
}
|
||||
}
|
||||
drawCtx := func() {
|
||||
m.Root.AddPage(currentTime, t.Primitive(), false, true)
|
||||
m.AddPage(currentTime, t.Primitive(), false, true)
|
||||
p.SetRect(t.Size(w, h))
|
||||
}
|
||||
redraw := func() {
|
||||
@@ -87,7 +82,7 @@ func (m *Root) AddCenteredWidget(t CenteredWidget) {
|
||||
select {
|
||||
case <-tck.C:
|
||||
{
|
||||
_, _, _w, _h := m.Root.GetRect()
|
||||
_, _, _w, _h := m.GetRect()
|
||||
if _w != w || _h != h {
|
||||
w = _w
|
||||
h = _h
|
||||
|
||||
@@ -57,7 +57,7 @@ func getFontWidth() (int, int, error) {
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
_, _, rw, rh := root.Root.GetRect()
|
||||
_, _, rw, rh := root.GetRect()
|
||||
if rw == 0 || rh == 0 {
|
||||
return 0, 0, errors.New("Unable to get row width and height")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user