From cc4971543caef40bb3692b94da99a562c149b7ff Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Mon, 1 May 2023 13:09:07 +0530 Subject: [PATCH] Embed Pages in Root --- ui/app.go | 2 +- ui/notify.go | 4 ++-- ui/root.go | 21 ++++++++------------- ui/utils.go | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/ui/app.go b/ui/app.go index 9698ae4..a7de870 100644 --- a/ui/app.go +++ b/ui/app.go @@ -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() diff --git a/ui/notify.go b/ui/notify.go index eccc7c6..d213849 100644 --- a/ui/notify.go +++ b/ui/notify.go @@ -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() diff --git a/ui/root.go b/ui/root.go index b77f2af..b1022db 100644 --- a/ui/root.go +++ b/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 diff --git a/ui/utils.go b/ui/utils.go index 8e4817b..bff8f13 100644 --- a/ui/utils.go +++ b/ui/utils.go @@ -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") }