panel.go 874 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package tg
  2. type Rowser interface {
  3. MakeRows(c *Context) []ButtonRow
  4. }
  5. type RowserFunc func(c *Context) []ButtonRow
  6. func (fn RowserFunc) MakeRows(c *Context) []ButtonRow {
  7. return fn(c)
  8. }
  9. // The type represents the inline panel with
  10. // scrollable via buttons content.
  11. // Can be used for example to show users via SQL and offset
  12. // or something like that.
  13. type PanelCompo struct {
  14. *InlineCompo
  15. Rowser Rowser
  16. }
  17. // Transform to the panel with dynamic rows.
  18. func (compo *MessageCompo) Panel(
  19. c *Context, // The context that all the buttons will get.
  20. rowser Rowser, // The rows generator.
  21. ) *PanelCompo {
  22. ret := &PanelCompo{}
  23. ret.InlineCompo = compo.Inline(
  24. NewKeyboard(
  25. rowser.MakeRows(c)...,
  26. ).Inline(),
  27. )
  28. ret.Rowser = rowser
  29. return ret
  30. }
  31. func (compo *PanelCompo) Update(c *Context) {
  32. compo.Rows = compo.Rowser.MakeRows(c)
  33. compo.InlineCompo.Update(c)
  34. }