2018-10-17 23:40:28 +08:00
|
|
|
// Demo code for the Grid primitive.
|
2018-02-20 03:23:01 +08:00
|
|
|
package main
|
|
|
|
|
2018-02-20 18:19:30 +08:00
|
|
|
import (
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
)
|
2018-02-20 03:23:01 +08:00
|
|
|
|
|
|
|
func main() {
|
2018-02-20 18:19:30 +08:00
|
|
|
newPrimitive := func(text string) tview.Primitive {
|
|
|
|
return tview.NewTextView().
|
|
|
|
SetTextAlign(tview.AlignCenter).
|
|
|
|
SetText(text)
|
|
|
|
}
|
|
|
|
menu := newPrimitive("Menu")
|
|
|
|
main := newPrimitive("Main content")
|
|
|
|
sideBar := newPrimitive("Side Bar")
|
|
|
|
|
2018-02-20 03:23:01 +08:00
|
|
|
grid := tview.NewGrid().
|
2018-02-20 18:19:30 +08:00
|
|
|
SetRows(3, 0, 3).
|
|
|
|
SetColumns(30, 0, 30).
|
|
|
|
SetBorders(true).
|
|
|
|
AddItem(newPrimitive("Header"), 0, 0, 1, 3, 0, 0, false).
|
|
|
|
AddItem(newPrimitive("Footer"), 2, 0, 1, 3, 0, 0, false)
|
|
|
|
|
|
|
|
// Layout for screens narrower than 100 cells (menu and side bar are hidden).
|
|
|
|
grid.AddItem(menu, 0, 0, 0, 0, 0, 0, false).
|
|
|
|
AddItem(main, 1, 0, 1, 3, 0, 0, false).
|
|
|
|
AddItem(sideBar, 0, 0, 0, 0, 0, 0, false)
|
|
|
|
|
|
|
|
// Layout for screens wider than 100 cells.
|
|
|
|
grid.AddItem(menu, 1, 0, 1, 1, 0, 100, false).
|
|
|
|
AddItem(main, 1, 1, 1, 1, 0, 100, false).
|
|
|
|
AddItem(sideBar, 1, 2, 1, 1, 0, 100, false)
|
|
|
|
|
2020-03-28 01:41:44 +08:00
|
|
|
if err := tview.NewApplication().SetRoot(grid, true).EnableMouse(true).Run(); err != nil {
|
2018-02-20 03:23:01 +08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|