12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package tg
- // Using the interface and all related is
- // deprecated. Use the Paneler interface and function.
- type Rowser interface {
- MakeRows(c Context) []ButtonRow
- }
- 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 {
- InlineCompo
- Paneler Paneler
- }
- // Transform to the panel with dynamic rows.
- func (compo *MessageCompo) Panel(
- c Context, // The context to generate the first page of buttons.
- paneler Paneler, // The rows generator.
- ) *PanelCompo {
- ret := &PanelCompo{}
- ret.Paneler = paneler
- ret.InlineCompo = (*compo.Inline(
- NewKeyboard(
- ret.Paneler.GetPanelRows(ret, c)...,
- ).Inline(),
- ))
- return ret
- }
- // Implementing the Updater.
- func (panel *PanelCompo) Update(c Context) error {
- panel.Rows = panel.Paneler.GetPanelRows(panel, c)
- return panel.InlineCompo.Update(c)
- }
|