screen.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package tg
  2. type WidgetSpecial int
  3. const (
  4. widgetEmpty WidgetSpecial = iota
  5. widgetBack
  6. )
  7. func (w WidgetSpecial) Render(_ Context) UI {
  8. return nil
  9. }
  10. var (
  11. Back = Widget(widgetBack)
  12. )
  13. /*// Unique identifier for the screen.
  14. type Path int
  15. const (
  16. PathEmpty Path = 0
  17. // Going to the path returns
  18. // a context to the previous screen.
  19. PathBack Path = -1
  20. )
  21. // Returns true if the path is empty.
  22. func (p Path) IsEmpty() bool {
  23. return p == 0
  24. }
  25. // Screen statement of the bot.
  26. // Mostly what buttons to show.
  27. type Screen struct {
  28. // The widget to run when reaching the screen.
  29. Widget Widget
  30. }
  31. // The first node with the "/" path.
  32. type RootNode struct {
  33. Screen *Screen
  34. Subs []*Node
  35. }
  36. // The node is a simple way to represent
  37. // tree-like structured applications.
  38. type Node struct {
  39. Path Path
  40. Screen *Screen
  41. Subs []*Node
  42. }*/
  43. // Return new root node with the specified widget in the screen.
  44. /*func NewRootNode(widget Widget, subs ...*Node) *RootNode {
  45. ret := &RootNode{}
  46. ret.Screen = NewScreen(widget)
  47. ret.Subs = subs
  48. return ret
  49. }
  50. func NewNode(relPath Path, widget Widget, subs ...*Node) *Node {
  51. ret := &Node{}
  52. ret.Path = relPath
  53. ret.Screen = NewScreen(widget)
  54. ret.Subs = subs
  55. return ret
  56. }
  57. func (n *RootNode) ScreenMap() ScreenMap {
  58. m := make(ScreenMap)
  59. var root Path = "/"
  60. m[root] = n.Screen
  61. for _, sub := range n.Subs {
  62. buf := sub.ScreenMap(root)
  63. for k, v := range buf {
  64. _, ok := m[k]
  65. if ok {
  66. panic("duplicate paths in node definition")
  67. }
  68. m[k] = v
  69. }
  70. }
  71. return m
  72. }
  73. func (n *Node) ScreenMap(root Path) ScreenMap {
  74. m := make(ScreenMap)
  75. pth := (root + n.Path).Clean()
  76. m[pth] = n.Screen
  77. for _, sub := range n.Subs {
  78. buf := sub.ScreenMap(pth + "/")
  79. for k, v := range buf {
  80. _, ok := m[k]
  81. if ok {
  82. panic("duplicate paths in node definition")
  83. }
  84. m[k] = v
  85. }
  86. }
  87. return m
  88. }*/
  89. // Returns the new screen with specified name and widget.
  90. /*func NewScreen(widget Widget) *Screen {
  91. return &Screen{
  92. Widget: widget,
  93. }
  94. }*/