tg/panel.go

56 lines
1.3 KiB
Go
Raw Normal View History

package tg
// Using the interface and all related is
// deprecated. Use the Paneler interface and function.
type Rowser interface {
2024-03-29 14:30:48 +03:00
MakeRows(c Context) []ButtonRow
}
2024-03-29 14:30:48 +03:00
type RowserFunc func(c Context) []ButtonRow
func (fn RowserFunc) MakeRows(c Context) []ButtonRow {
return fn(c)
}
type Paneler interface {
GetPanelRows(*PanelCompo, Context) []ButtonRow
}
type PanelFunc func(*PanelCompo, Context) []ButtonRow
func (fn PanelFunc) GetPanelRows(
panel *PanelCompo, c Context,
) []ButtonRow {
return fn(panel, c)
}
// The type represents the inline panel with
// scrollable via buttons content.
// Can be used for example to show users via SQL and offset
// or something like that.
type PanelCompo struct {
2024-03-29 14:30:48 +03:00
InlineCompo
Paneler Paneler
}
// Transform to the panel with dynamic rows.
func (compo *MessageCompo) Panel(
2024-03-29 14:30:48 +03:00
c Context, // The context to generate the first page of buttons.
paneler Paneler, // The rows generator.
) *PanelCompo {
ret := &PanelCompo{}
ret.Paneler = paneler
2024-03-29 14:30:48 +03:00
ret.InlineCompo = (*compo.Inline(
NewKeyboard(
ret.Paneler.GetPanelRows(ret, c)...,
).Inline(),
2024-03-29 14:30:48 +03:00
))
return ret
}
// Implementing the Updater.
func (panel *PanelCompo) Update(c Context) error {
panel.Rows = panel.Paneler.GetPanelRows(panel, c)
return panel.InlineCompo.Update(c)
}