- // Demo code for the TabbedPanels primitive.
- package main
-
- import (
- "fmt"
-
- //"github.com/rivo/tview"
- "github.com/gdamore/tcell/v2"
- "code.rocketnine.space/tslocum/cview"
- )
-
- const panelCount = 5
-
-
- func demoBox(title string) *cview.Box {
- b := cview.NewBox()
- b.SetBorder(true)
- b.SetTitle(title)
- return b
- }
-
-
- func main() {
-
- app := cview.NewApplication()
- defer app.HandlePanic()
- app.EnableMouse(true)
-
- panels := NewTabbedPanels()
-
- for panel := 0; panel < panelCount; panel++ {
- func(panel int) {
- form := cview.NewForm()
- form.SetBorder(true)
- form.SetDrawFunc(func(screen tcell.Screen, x int, y int, width int, height int) (int, int, int, int) {
- //fix corners
- screen.SetContent(x, y, cview.BoxDrawingsLightVertical, nil, tcell.StyleDefault.Background(tcell.Color16))
- screen.SetContent(x+width-1, y, cview.BoxDrawingsLightVertical, nil, tcell.StyleDefault.Background(tcell.Color16))
- // Draw nothing across the top of the box.
- for cx := x + 1; cx < x+width-1; cx++ {
- screen.SetContent(cx, y, ' ', nil, tcell.StyleDefault.Background(tcell.Color16))
- }
- // Space for other content.
- return x + 1, y, width - 2, height - y +1
- })
- //form.SetTitle(fmt.Sprintf("This is tab %d. Choose another tab.", panel+1))
- form.AddButton("Next", func() {
- panels.SetCurrentTab(fmt.Sprintf("panel-%d", (panel+1)%panelCount))
- })
- form.AddButton("Quit", func() {
- app.Stop()
- })
- form.SetCancelFunc(func() {
- app.Stop()
- })
-
- panels.AddTab(fmt.Sprintf("panel-%d", panel), fmt.Sprintf("Panel #%d", panel), form)
- }(panel)
- }
-
- subFlex := cview.NewFlex()
- subFlex.SetDirection(cview.FlexRow)
- subFlex.AddItem(demoBox("Top"), 0, 1, false)
- subFlex.AddItem(panels, 0, 3, false)
- subFlex.AddItem(demoBox("Bottom (5 rows)"), 5, 1, false)
-
- flex := cview.NewFlex()
- flex.AddItem(demoBox("Left (1/2 x width of Top)"), 0, 1, false)
- flex.AddItem(subFlex, 0, 2, false)
- flex.AddItem(demoBox("Right (20 cols)"), 20, 1, false)
-
- app.SetRoot(flex, true)
- if err := app.Run(); err != nil {
- panic(err)
- }
-
- //app := cview.NewApplication()
- //defer app.HandlePanic()
-
-
-
-
-
- //app.SetRoot(panels, true)
- //if err := app.Run(); err != nil {
- // panic(err)
- //}
- }