2023-08-19 09:12:26 +03:00
|
|
|
package tg
|
2023-07-09 01:28:59 +03:00
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
type WidgetSpecial int
|
|
|
|
const (
|
|
|
|
widgetEmpty WidgetSpecial = iota
|
|
|
|
widgetBack
|
2023-09-21 12:03:54 +03:00
|
|
|
)
|
|
|
|
|
2023-09-21 14:54:31 +03:00
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
func (w WidgetSpecial) Render(_ Context) UI {
|
|
|
|
return nil
|
2023-09-21 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
var (
|
|
|
|
Back = Widget(widgetBack)
|
|
|
|
)
|
2023-09-21 14:54:31 +03:00
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
/*// Unique identifier for the screen.
|
|
|
|
type Path int
|
|
|
|
const (
|
|
|
|
PathEmpty Path = 0
|
|
|
|
// Going to the path returns
|
|
|
|
// a context to the previous screen.
|
|
|
|
PathBack Path = -1
|
|
|
|
)
|
2023-09-21 12:03:54 +03:00
|
|
|
|
|
|
|
// Returns true if the path is empty.
|
|
|
|
func (p Path) IsEmpty() bool {
|
2024-07-21 16:02:47 +03:00
|
|
|
return p == 0
|
2023-09-21 12:03:54 +03:00
|
|
|
}
|
2023-07-09 01:28:59 +03:00
|
|
|
|
|
|
|
// Screen statement of the bot.
|
|
|
|
// Mostly what buttons to show.
|
|
|
|
type Screen struct {
|
2023-09-09 07:28:06 +03:00
|
|
|
// The widget to run when reaching the screen.
|
|
|
|
Widget Widget
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|
|
|
|
|
2023-09-21 12:03:54 +03:00
|
|
|
// The first node with the "/" path.
|
|
|
|
type RootNode struct {
|
|
|
|
Screen *Screen
|
|
|
|
Subs []*Node
|
|
|
|
}
|
|
|
|
|
2023-09-21 00:24:42 +03:00
|
|
|
// The node is a simple way to represent
|
|
|
|
// tree-like structured applications.
|
|
|
|
type Node struct {
|
2023-09-21 12:03:54 +03:00
|
|
|
Path Path
|
2023-09-21 00:24:42 +03:00
|
|
|
Screen *Screen
|
|
|
|
Subs []*Node
|
2024-07-21 16:02:47 +03:00
|
|
|
}*/
|
2023-09-21 00:24:42 +03:00
|
|
|
|
2023-09-21 12:03:54 +03:00
|
|
|
// Return new root node with the specified widget in the screen.
|
2024-07-21 16:02:47 +03:00
|
|
|
/*func NewRootNode(widget Widget, subs ...*Node) *RootNode {
|
2023-09-21 12:03:54 +03:00
|
|
|
ret := &RootNode{}
|
|
|
|
ret.Screen = NewScreen(widget)
|
|
|
|
ret.Subs = subs
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewNode(relPath Path, widget Widget, subs ...*Node) *Node {
|
2023-09-21 00:24:42 +03:00
|
|
|
ret := &Node{}
|
2023-09-21 12:03:54 +03:00
|
|
|
ret.Path = relPath
|
|
|
|
ret.Screen = NewScreen(widget)
|
2023-09-21 00:24:42 +03:00
|
|
|
ret.Subs = subs
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-09-21 12:03:54 +03:00
|
|
|
func (n *RootNode) ScreenMap() ScreenMap {
|
2023-09-21 00:24:42 +03:00
|
|
|
m := make(ScreenMap)
|
2023-09-21 12:03:54 +03:00
|
|
|
var root Path = "/"
|
|
|
|
m[root] = n.Screen
|
2023-09-21 00:24:42 +03:00
|
|
|
for _, sub := range n.Subs {
|
2023-09-21 12:03:54 +03:00
|
|
|
buf := sub.ScreenMap(root)
|
2023-09-21 00:24:42 +03:00
|
|
|
for k, v := range buf {
|
2023-09-21 12:03:54 +03:00
|
|
|
_, ok := m[k]
|
|
|
|
if ok {
|
|
|
|
panic("duplicate paths in node definition")
|
|
|
|
}
|
2023-09-21 00:24:42 +03:00
|
|
|
m[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2023-09-21 12:03:54 +03:00
|
|
|
func (n *Node) ScreenMap(root Path) ScreenMap {
|
2023-09-21 00:24:42 +03:00
|
|
|
m := make(ScreenMap)
|
2023-09-21 12:03:54 +03:00
|
|
|
pth := (root + n.Path).Clean()
|
|
|
|
m[pth] = n.Screen
|
2023-09-21 00:24:42 +03:00
|
|
|
for _, sub := range n.Subs {
|
2023-09-21 14:54:31 +03:00
|
|
|
buf := sub.ScreenMap(pth + "/")
|
2023-09-21 00:24:42 +03:00
|
|
|
for k, v := range buf {
|
2023-09-21 12:03:54 +03:00
|
|
|
_, ok := m[k]
|
|
|
|
if ok {
|
|
|
|
panic("duplicate paths in node definition")
|
|
|
|
}
|
2023-09-21 00:24:42 +03:00
|
|
|
m[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m
|
2024-07-21 16:02:47 +03:00
|
|
|
}*/
|
2023-09-21 00:24:42 +03:00
|
|
|
|
2023-07-09 01:28:59 +03:00
|
|
|
|
2023-09-09 07:28:06 +03:00
|
|
|
// Returns the new screen with specified name and widget.
|
2024-07-21 16:02:47 +03:00
|
|
|
/*func NewScreen(widget Widget) *Screen {
|
2023-08-10 15:49:25 +03:00
|
|
|
return &Screen{
|
2023-09-09 07:28:06 +03:00
|
|
|
Widget: widget,
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|
2024-07-21 16:02:47 +03:00
|
|
|
}*/
|
2023-07-09 01:28:59 +03:00
|
|
|
|