Newer
Older
GoModules / TabTitleMenu / main.go
0xRoM on 7 Feb 2023 2 KB TabTitleMenu's added
  1. // Demo code for the TabbedPanels primitive.
  2. package main
  3.  
  4. import (
  5. "fmt"
  6.  
  7. //"github.com/rivo/tview"
  8. "github.com/gdamore/tcell/v2"
  9. "code.rocketnine.space/tslocum/cview"
  10. )
  11.  
  12. const panelCount = 5
  13.  
  14.  
  15. func demoBox(title string) *cview.Box {
  16. b := cview.NewBox()
  17. b.SetBorder(true)
  18. b.SetTitle(title)
  19. return b
  20. }
  21.  
  22.  
  23. func main() {
  24.  
  25. app := cview.NewApplication()
  26. defer app.HandlePanic()
  27. app.EnableMouse(true)
  28.  
  29. panels := NewTabbedPanels()
  30.  
  31. for panel := 0; panel < panelCount; panel++ {
  32. func(panel int) {
  33. form := cview.NewForm()
  34. form.SetBorder(true)
  35. form.SetDrawFunc(func(screen tcell.Screen, x int, y int, width int, height int) (int, int, int, int) {
  36. //fix corners
  37. screen.SetContent(x, y, cview.BoxDrawingsLightVertical, nil, tcell.StyleDefault.Background(tcell.Color16))
  38. screen.SetContent(x+width-1, y, cview.BoxDrawingsLightVertical, nil, tcell.StyleDefault.Background(tcell.Color16))
  39. // Draw nothing across the top of the box.
  40. for cx := x + 1; cx < x+width-1; cx++ {
  41. screen.SetContent(cx, y, ' ', nil, tcell.StyleDefault.Background(tcell.Color16))
  42. }
  43. // Space for other content.
  44. return x + 1, y, width - 2, height - y +1
  45. })
  46. //form.SetTitle(fmt.Sprintf("This is tab %d. Choose another tab.", panel+1))
  47. form.AddButton("Next", func() {
  48. panels.SetCurrentTab(fmt.Sprintf("panel-%d", (panel+1)%panelCount))
  49. })
  50. form.AddButton("Quit", func() {
  51. app.Stop()
  52. })
  53. form.SetCancelFunc(func() {
  54. app.Stop()
  55. })
  56.  
  57. panels.AddTab(fmt.Sprintf("panel-%d", panel), fmt.Sprintf("Panel #%d", panel), form)
  58. }(panel)
  59. }
  60.  
  61. subFlex := cview.NewFlex()
  62. subFlex.SetDirection(cview.FlexRow)
  63. subFlex.AddItem(demoBox("Top"), 0, 1, false)
  64. subFlex.AddItem(panels, 0, 3, false)
  65. subFlex.AddItem(demoBox("Bottom (5 rows)"), 5, 1, false)
  66.  
  67. flex := cview.NewFlex()
  68. flex.AddItem(demoBox("Left (1/2 x width of Top)"), 0, 1, false)
  69. flex.AddItem(subFlex, 0, 2, false)
  70. flex.AddItem(demoBox("Right (20 cols)"), 20, 1, false)
  71.  
  72. app.SetRoot(flex, true)
  73. if err := app.Run(); err != nil {
  74. panic(err)
  75. }
  76.  
  77. //app := cview.NewApplication()
  78. //defer app.HandlePanic()
  79.  
  80.  
  81.  
  82. //app.SetRoot(panels, true)
  83. //if err := app.Run(); err != nil {
  84. // panic(err)
  85. //}
  86. }
Buy Me A Coffee