Adding a page and switching to it is now possible.

This commit is contained in:
Oliver 2018-01-19 21:12:33 +01:00
parent 7c086b1113
commit 89ae756605
1 changed files with 17 additions and 3 deletions

View File

@ -48,15 +48,21 @@ func (p *Pages) SetChangedFunc(handler func()) *Pages {
return p
}
// AddPage adds a new page with the given name and primitive. Leaving the name
// empty or using the same name for multiple items may cause conflicts in other
// functions.
// AddPage adds a new page with the given name and primitive. If there was
// previously a page with the same name, it is overwritten. Leaving the name
// empty may cause conflicts in other functions.
//
// Visible pages will be drawn in the order they were added (unless that order
// was changed in one of the other functions). If "resize" is set to true, the
// primitive will be set to the size available to the Pages primitive whenever
// the pages are drawn.
func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Pages {
for index, pg := range p.pages {
if pg.Name == name {
p.pages = append(p.pages[:index], p.pages[index+1:]...)
break
}
}
p.pages = append(p.pages, &page{Item: item, Name: name, Resize: resize, Visible: visible})
if p.changed != nil {
p.changed()
@ -65,6 +71,14 @@ func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Page
return p
}
// AddAndSwitchToPage calls AddPage(), then SwitchToPage() on that newly added
// page.
func (p *Pages) AddAndSwitchToPage(name string, item Primitive, resize bool) *Pages {
p.AddPage(name, item, resize, true)
p.SwitchToPage(name)
return p
}
// RemovePage removes the page with the given name.
func (p *Pages) RemovePage(name string) *Pages {
for index, page := range p.pages {