tg/cmd/test/panel.go

56 lines
998 B
Go
Raw Normal View History

2024-03-29 14:30:48 +03:00
package main
import (
"surdeus.su/core/tg"
2024-03-29 14:30:48 +03:00
)
const (
PanelPath tg.Path = "panel"
)
var PanelWidget = tg.RenderFunc(func(c tg.Context) tg.UI {
var (
n = 0
ln = 4
2024-03-29 14:30:48 +03:00
panel *tg.PanelCompo
)
panel = tg.Messagef(
"Some panel",
).Panel(c, tg.RowserFunc(func(c tg.Context) []tg.ButtonRow {
btns := []tg.ButtonRow{
tg.ButtonRow{tg.Buttonf("Page %d", n)},
}
for i := 0; i < ln; i++ {
num := 1 + n*ln + i
btns = append(btns, tg.ButtonRow{
tg.Buttonf("%d", num).Rand().WithAction(tg.Func(func(c tg.Context) {
_, err := c.Sendf("%d", num*num)
if err != nil {
}
})),
tg.Buttonf("%d", num*num),
})
}
btns = append(btns, tg.ButtonRow{
tg.Buttonf("Prev").WithAction(tg.Func(func(c tg.Context) {
n--
panel.Update(c)
})),
tg.Buttonf("Next").WithAction(tg.Func(func(c tg.Context) {
n++
panel.Update(c)
})),
})
return btns
}))
return tg.UI{
panel,
tg.Messagef("").Reply(
BackKeyboard.Reply(),
),
}
})