Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Dec 4, 2023
1 parent 0342764 commit fb95145
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
12 changes: 6 additions & 6 deletions app/masterpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ type MasterPage struct {
func NewMasterPage(id string, startPage Page) *MasterPage {
mp := &MasterPage{
GenericPageModal: NewGenericPageModal(id),
subPages: NewPageStack(id),
}

if startPage == nil {
return mp
if startPage != nil {
// Bind the navigator to the page.
startPage.OnAttachedToNavigator(mp)
mp.subPages.pages = append(mp.subPages.pages, startPage)
}

// Bind the navigator to the page.
startPage.OnAttachedToNavigator(mp)
mp.subPages.pages = append(mp.subPages.pages, startPage)
mp.subPages = NewPageStack(id, startPage)

return mp
}

Expand Down
24 changes: 17 additions & 7 deletions app/pagestack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ type PageStack struct {
pages []Page
}

// NewPageStack creates a new PageStack object.
func NewPageStack(name string) *PageStack {
return &PageStack{
// NewPageStack creates a new PageStack object. startPage is optional but should
// have it's navigator already attached if provided.
func NewPageStack(name string, startPage Page) *PageStack {
ps := &PageStack{
name: name,
}

if startPage != nil {
ps.pages = append(ps.pages, startPage)
}

return ps
}

// Top returns the page that is at the top of the stack. Returns nil if the
Expand Down Expand Up @@ -72,16 +79,19 @@ func (pageStack *PageStack) Pop() bool {
return false
}

pageToPop := pageStack.pages[l-1]
var topPageIndex = l - 1
pageToPop := pageStack.pages[topPageIndex]
pageToPop.OnNavigatedFrom()
if closeablePage, ok := pageToPop.(Closable); ok {
closeablePage.OnClosed()
}

pageStack.pages = pageStack.pages[:l-1]
if l > 1 {
pageStack.pages[l-2].OnNavigatedTo() // get previous page ready for display
pageStack.pages = pageStack.pages[:topPageIndex] // remove page.
if topPageIndex == 0 { // we popped the last page
return true
}

pageStack.pages[len(pageStack.pages)-1].OnNavigatedTo() // get the top page ready for display
return true
}

Expand Down
2 changes: 1 addition & 1 deletion app/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SimpleWindowNavigator struct {
func NewSimpleWindowNavigator(reloadDisplayFn func()) *SimpleWindowNavigator {
w := &SimpleWindowNavigator{
reloadDisplayFn: reloadDisplayFn,
subPages: NewPageStack("main window"),
subPages: NewPageStack("main window", nil),
}
return w
}
Expand Down

0 comments on commit fb95145

Please sign in to comment.