2023-12-19 22:35:57 +03:00
|
|
|
package tg
|
|
|
|
|
2024-07-25 17:48:02 +03:00
|
|
|
// Using the interface and all related is
|
|
|
|
// deprecated. Use the Paneler interface and function.
|
2023-12-19 22:35:57 +03:00
|
|
|
type Rowser interface {
|
2024-03-29 14:30:48 +03:00
|
|
|
MakeRows(c Context) []ButtonRow
|
2023-12-19 22:35:57 +03:00
|
|
|
}
|
|
|
|
|
2024-03-29 14:30:48 +03:00
|
|
|
type RowserFunc func(c Context) []ButtonRow
|
|
|
|
func (fn RowserFunc) MakeRows(c Context) []ButtonRow {
|
2023-12-19 22:35:57 +03:00
|
|
|
return fn(c)
|
|
|
|
}
|
|
|
|
|
2024-07-25 17:48:02 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-12-19 22:35:57 +03:00
|
|
|
// 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
|
2024-07-25 17:48:02 +03:00
|
|
|
Paneler Paneler
|
2023-12-19 22:35:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2024-07-25 17:48:02 +03:00
|
|
|
paneler Paneler, // The rows generator.
|
2023-12-19 22:35:57 +03:00
|
|
|
) *PanelCompo {
|
|
|
|
ret := &PanelCompo{}
|
2024-07-25 17:48:02 +03:00
|
|
|
ret.Paneler = paneler
|
|
|
|
|
2024-03-29 14:30:48 +03:00
|
|
|
ret.InlineCompo = (*compo.Inline(
|
2023-12-19 22:35:57 +03:00
|
|
|
NewKeyboard(
|
2024-07-25 17:48:02 +03:00
|
|
|
ret.Paneler.GetPanelRows(ret, c)...,
|
2023-12-19 22:35:57 +03:00
|
|
|
).Inline(),
|
2024-03-29 14:30:48 +03:00
|
|
|
))
|
2023-12-19 22:35:57 +03:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2024-07-25 17:48:02 +03:00
|
|
|
// Implementing the Updater.
|
|
|
|
func (panel *PanelCompo) Update(c Context) error {
|
|
|
|
panel.Rows = panel.Paneler.GetPanelRows(panel, c)
|
|
|
|
return panel.InlineCompo.Update(c)
|
2023-12-19 22:35:57 +03:00
|
|
|
}
|
|
|
|
|