2024-07-22 18:45:53 +03:00
|
|
|
package tg
|
|
|
|
|
2024-07-23 15:05:20 +03:00
|
|
|
type PanelPager interface {
|
2024-07-25 17:48:02 +03:00
|
|
|
GetPanelPage(
|
|
|
|
panel *PanelPagerCompo,
|
|
|
|
c Context, page, size int,
|
|
|
|
) PanelPage
|
2024-07-23 15:05:20 +03:00
|
|
|
}
|
|
|
|
|
2024-07-22 18:45:53 +03:00
|
|
|
type PanelPage struct {
|
|
|
|
Next, Prev bool
|
|
|
|
Rows []ButtonRow
|
|
|
|
}
|
|
|
|
|
2024-07-23 15:05:20 +03:00
|
|
|
type PanelPagerFunc func(
|
2024-07-25 17:48:02 +03:00
|
|
|
panel *PanelPagerCompo,
|
2024-07-22 18:45:53 +03:00
|
|
|
c Context, page, size int,
|
|
|
|
) PanelPage
|
2024-07-23 15:05:20 +03:00
|
|
|
func (fn PanelPagerFunc) GetPanelPage(
|
2024-07-25 17:48:02 +03:00
|
|
|
panel *PanelPagerCompo, c Context, page, size int,
|
2024-07-23 15:05:20 +03:00
|
|
|
) PanelPage {
|
2024-07-25 17:48:02 +03:00
|
|
|
return fn(panel, c, page, size)
|
2024-07-23 15:05:20 +03:00
|
|
|
}
|
2024-07-22 18:45:53 +03:00
|
|
|
|
2024-07-23 15:05:20 +03:00
|
|
|
type PanelPagerCompo struct {
|
2024-07-22 18:45:53 +03:00
|
|
|
PanelCompo
|
|
|
|
page int
|
|
|
|
size int
|
|
|
|
nextFormat, prevFormat, delFormat string
|
2024-07-23 15:05:20 +03:00
|
|
|
pager PanelPager
|
2024-07-22 18:45:53 +03:00
|
|
|
}
|
|
|
|
|
2024-07-23 15:05:20 +03:00
|
|
|
func (compo *MessageCompo) PanelPager(
|
2024-07-22 18:45:53 +03:00
|
|
|
c Context,
|
|
|
|
startPage, size int,
|
2024-07-23 15:05:20 +03:00
|
|
|
pager PanelPager,
|
|
|
|
) (*PanelPagerCompo) {
|
|
|
|
ret := &PanelPagerCompo{}
|
2024-07-22 18:45:53 +03:00
|
|
|
ret.page = startPage
|
|
|
|
ret.size = size
|
2024-07-23 15:05:20 +03:00
|
|
|
ret.pager = pager
|
2024-07-22 18:45:53 +03:00
|
|
|
ret.prevFormat = "<<<"
|
|
|
|
ret.nextFormat = ">>>"
|
|
|
|
ret.delFormat = "..."
|
|
|
|
|
|
|
|
ret.PanelCompo = (*compo.Panel(
|
|
|
|
c, ret,
|
|
|
|
))
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2024-07-25 17:48:02 +03:00
|
|
|
func (panel *PanelPagerCompo) GetPanelRows(
|
|
|
|
pcompo *PanelCompo, c Context,
|
2024-07-22 18:45:53 +03:00
|
|
|
) []ButtonRow {
|
2024-07-23 15:05:20 +03:00
|
|
|
page := panel.pager.GetPanelPage(
|
2024-07-25 17:48:02 +03:00
|
|
|
panel, c, panel.page, panel.size,
|
2024-07-22 18:45:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|