tg/panel.go

41 lines
879 B
Go
Raw Normal View History

package tg
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)
}
// 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
Rowser Rowser
}
// 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.
rowser Rowser, // The rows generator.
) *PanelCompo {
ret := &PanelCompo{}
2024-03-29 14:30:48 +03:00
ret.InlineCompo = (*compo.Inline(
NewKeyboard(
rowser.MakeRows(c)...,
).Inline(),
2024-03-29 14:30:48 +03:00
))
ret.Rowser = rowser
return ret
}
2024-03-29 14:30:48 +03:00
func (compo *PanelCompo) Update(c Context) {
compo.Rows = compo.Rowser.MakeRows(c)
compo.InlineCompo.Update(c)
}