package tg type PanelPager interface { GetPanelPage( panel *PanelPagerCompo, c Context, page, size int, ) PanelPage } type PanelPage struct { Next, Prev bool Rows []ButtonRow } type PanelPagerFunc func( panel *PanelPagerCompo, c Context, page, size int, ) PanelPage func (fn PanelPagerFunc) GetPanelPage( panel *PanelPagerCompo, c Context, page, size int, ) PanelPage { return fn(panel, c, page, size) } type PanelPagerCompo struct { PanelCompo page int size int nextFormat, prevFormat, delFormat string pager PanelPager } func (compo *MessageCompo) PanelPager( c Context, startPage, size int, pager PanelPager, ) (*PanelPagerCompo) { ret := &PanelPagerCompo{} ret.page = startPage ret.size = size ret.pager = pager ret.prevFormat = "<<<" ret.nextFormat = ">>>" ret.delFormat = "..." ret.PanelCompo = (*compo.Panel( c, ret, )) return ret } func (panel *PanelPagerCompo) GetPanelRows( pcompo *PanelCompo, c Context, ) []ButtonRow { page := panel.pager.GetPanelPage( panel, c, panel.page, panel.size, ) controlRow := ButtonRow{} rows := page.Rows next := func(c Context){ panel.page++ panel.Update(c) } prev := func(c Context){ panel.page-- panel.Update(c) } if page.Prev { if panel.delFormat != "" { rows = append( []ButtonRow{ ButtonRow{ Buttonf(panel.delFormat).Rand(). WithAction(Func(prev)), }, }, rows..., ) } controlRow = append( controlRow, Buttonf(panel.prevFormat).Rand(). WithAction(Func(prev)), ) } if page.Next { if panel.delFormat != "" { rows = append( rows, ButtonRow{ Buttonf(panel.delFormat).Rand(). WithAction(Func(next)), }, ) } controlRow = append( controlRow, Buttonf(panel.nextFormat).Rand(). WithAction(Func(next)), ) } return append( rows, controlRow, ) }