2024-03-29 14:30:48 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-05-15 20:41:53 +03:00
|
|
|
"surdeus.su/core/tg"
|
2024-03-29 14:30:48 +03:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
// A simple example widget to show
|
|
|
|
// how to store and get session data values
|
|
|
|
// and working with dynamic panels.
|
2024-03-29 14:30:48 +03:00
|
|
|
var IncDecWidget = tg.RenderFunc(func(c tg.Context) tg.UI {
|
2024-07-25 17:48:02 +03:00
|
|
|
const format = "Press the buttons" +
|
|
|
|
"to increment and decrement.\n" +
|
2024-03-29 14:30:48 +03:00
|
|
|
"Current counter value = %d"
|
2024-07-25 17:48:02 +03:00
|
|
|
d := ExtractSessionData(c)
|
2024-03-29 14:30:48 +03:00
|
|
|
return tg.UI{
|
2024-07-25 17:48:02 +03:00
|
|
|
tg.Messagef(format, d.Counter).Panel(
|
|
|
|
c,
|
|
|
|
tg.PanelFunc(func(
|
|
|
|
panel *tg.PanelCompo,
|
|
|
|
c tg.Context,
|
|
|
|
) []tg.ButtonRow {
|
|
|
|
d := ExtractSessionData(c)
|
|
|
|
row := tg.ButtonRow{}
|
|
|
|
if d.Counter != -5 {
|
|
|
|
row = append(
|
|
|
|
row,
|
|
|
|
tg.Buttonf(
|
|
|
|
"-",
|
|
|
|
).WithAction(tg.Func(func(c tg.Context){
|
|
|
|
d.Counter--
|
|
|
|
panel.Text = fmt.Sprintf(format, d.Counter)
|
|
|
|
c.Update(panel)
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if d.Counter != +5 {
|
|
|
|
row = append(
|
|
|
|
row,
|
|
|
|
tg.Buttonf(
|
|
|
|
"+",
|
|
|
|
).WithAction(tg.Func(func(c tg.Context){
|
|
|
|
d.Counter++
|
|
|
|
panel.Text = fmt.Sprintf(format, d.Counter)
|
|
|
|
c.Update(panel)
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return []tg.ButtonRow{row}
|
|
|
|
}),
|
|
|
|
),
|
2024-03-29 14:30:48 +03:00
|
|
|
tg.Messagef("Use the reply keyboard to get back").Reply(
|
|
|
|
BackKeyboard.Reply(),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
})
|