tg/panel.go
2024-03-29 16:30:48 +05:00

40 lines
879 B
Go

package tg
type Rowser interface {
MakeRows(c Context) []ButtonRow
}
type RowserFunc func(c Context) []ButtonRow
func (fn RowserFunc) MakeRows(c Context) []ButtonRow {
return fn(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 {
InlineCompo
Rowser Rowser
}
// Transform to the panel with dynamic rows.
func (compo *MessageCompo) Panel(
c Context, // The context to generate the first page of buttons.
rowser Rowser, // The rows generator.
) *PanelCompo {
ret := &PanelCompo{}
ret.InlineCompo = (*compo.Inline(
NewKeyboard(
rowser.MakeRows(c)...,
).Inline(),
))
ret.Rowser = rowser
return ret
}
func (compo *PanelCompo) Update(c Context) {
compo.Rows = compo.Rowser.MakeRows(c)
compo.InlineCompo.Update(c)
}