Add MaxPageButtons to the Pager widget
This commit is contained in:
parent
8433b1b216
commit
c32601391a
18
pager.go
18
pager.go
|
@ -11,10 +11,13 @@ import (
|
||||||
type Pager struct {
|
type Pager struct {
|
||||||
BaseWidget
|
BaseWidget
|
||||||
|
|
||||||
// Config settings.
|
// Config settings. NOTE: these are copied in the constructor,
|
||||||
|
// be sure to update it there too if you add a new option!
|
||||||
|
Name string // totally optional name
|
||||||
Page int // default 1
|
Page int // default 1
|
||||||
Pages int
|
Pages int
|
||||||
PerPage int // default 20
|
PerPage int // default 20
|
||||||
|
MaxPageButtons int // max no. of individual pages to show, 0 = no limit
|
||||||
Font render.Text
|
Font render.Text
|
||||||
OnChange func(page, perPage int)
|
OnChange func(page, perPage int)
|
||||||
|
|
||||||
|
@ -34,6 +37,7 @@ func NewPager(config Pager) *Pager {
|
||||||
Page: config.Page,
|
Page: config.Page,
|
||||||
Pages: config.Pages,
|
Pages: config.Pages,
|
||||||
PerPage: config.PerPage,
|
PerPage: config.PerPage,
|
||||||
|
MaxPageButtons: config.MaxPageButtons,
|
||||||
Font: config.Font,
|
Font: config.Font,
|
||||||
OnChange: config.OnChange,
|
OnChange: config.OnChange,
|
||||||
buttons: []Widget{},
|
buttons: []Widget{},
|
||||||
|
@ -93,6 +97,18 @@ func (w *Pager) setup() *Frame {
|
||||||
for i := 1; i <= w.Pages; i++ {
|
for i := 1; i <= w.Pages; i++ {
|
||||||
page := fmt.Sprintf("%d", i)
|
page := fmt.Sprintf("%d", i)
|
||||||
|
|
||||||
|
if w.MaxPageButtons > 0 {
|
||||||
|
if i > w.MaxPageButtons {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// The final button shown; make this one always reflect the
|
||||||
|
// current page IF the current page is greater than this one.
|
||||||
|
if w.Page >= i && w.Page != i {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
btn := NewRadioButton(
|
btn := NewRadioButton(
|
||||||
"Page "+page,
|
"Page "+page,
|
||||||
&w.page,
|
&w.page,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user