From c1b4809f2e519e2901638822f6b496e3d944f733 Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Wed, 27 Dec 2017 22:28:16 +0100 Subject: [PATCH] Contained pages need to be resized if requested. --- demos/pages/main.go | 1 + pages.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/demos/pages/main.go b/demos/pages/main.go index d1f6c1d..6023a70 100644 --- a/demos/pages/main.go +++ b/demos/pages/main.go @@ -24,6 +24,7 @@ func main() { app.Stop() } }), + false, page == 0) }(page) } diff --git a/pages.go b/pages.go index 3ebfe95..4dbadc3 100644 --- a/pages.go +++ b/pages.go @@ -8,6 +8,7 @@ import ( type page struct { Name string // The page's name. Item Primitive // The page's primitive. + Resize bool // Whether or not to resize the page when it is drawn. Visible bool // Whether or not this page is visible. } @@ -50,9 +51,11 @@ func (p *Pages) SetChangedFunc(handler func()) *Pages { // functions. // // Visible pages will be drawn in the order they were added (unless that order -// was changed in one of the other functions). -func (p *Pages) AddPage(name string, item Primitive, visible bool) *Pages { - p.pages = append(p.pages, &page{Item: item, Name: name, Visible: visible}) +// 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 { + p.pages = append(p.pages, &page{Item: item, Name: name, Resize: resize, Visible: visible}) if p.changed != nil { p.changed() } @@ -207,6 +210,10 @@ func (p *Pages) Draw(screen tcell.Screen) { if !page.Visible { continue } + if page.Resize { + x, y, width, height := p.GetInnerRect() + page.Item.SetRect(x, y, width, height) + } page.Item.Draw(screen) } }