tg/screen.go

110 lines
1.9 KiB
Go

package tg
type WidgetSpecial int
const (
widgetEmpty WidgetSpecial = iota
widgetBack
)
func (w WidgetSpecial) Render(_ Context) UI {
return nil
}
var (
Back = Widget(widgetBack)
)
/*// 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
)
// Returns true if the path is empty.
func (p Path) IsEmpty() bool {
return p == 0
}
// Screen statement of the bot.
// Mostly what buttons to show.
type Screen struct {
// The widget to run when reaching the screen.
Widget Widget
}
// The first node with the "/" path.
type RootNode struct {
Screen *Screen
Subs []*Node
}
// The node is a simple way to represent
// tree-like structured applications.
type Node struct {
Path Path
Screen *Screen
Subs []*Node
}*/
// Return new root node with the specified widget in the screen.
/*func NewRootNode(widget Widget, subs ...*Node) *RootNode {
ret := &RootNode{}
ret.Screen = NewScreen(widget)
ret.Subs = subs
return ret
}
func NewNode(relPath Path, widget Widget, subs ...*Node) *Node {
ret := &Node{}
ret.Path = relPath
ret.Screen = NewScreen(widget)
ret.Subs = subs
return ret
}
func (n *RootNode) ScreenMap() ScreenMap {
m := make(ScreenMap)
var root Path = "/"
m[root] = n.Screen
for _, sub := range n.Subs {
buf := sub.ScreenMap(root)
for k, v := range buf {
_, ok := m[k]
if ok {
panic("duplicate paths in node definition")
}
m[k] = v
}
}
return m
}
func (n *Node) ScreenMap(root Path) ScreenMap {
m := make(ScreenMap)
pth := (root + n.Path).Clean()
m[pth] = n.Screen
for _, sub := range n.Subs {
buf := sub.ScreenMap(pth + "/")
for k, v := range buf {
_, ok := m[k]
if ok {
panic("duplicate paths in node definition")
}
m[k] = v
}
}
return m
}*/
// Returns the new screen with specified name and widget.
/*func NewScreen(widget Widget) *Screen {
return &Screen{
Widget: widget,
}
}*/