Debian Codegraph @

demos/presentation/grid.go

raw symbols SCIP
1 package mainscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/
2
3 import (
4 "github.com/gdamore/tcell/v2scip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/"
5 "github.com/darkhz/tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/"
6 )
7
8 // Grid demonstrates the grid layout.
9 func Gridscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/presentation`/Grid().(nextSlide func()) (title string, content tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.Primitivescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Primitive#) {
10 modalShown := false
11 pages := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewPagesscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewPages().()
12
13 newPrimitive := func(text string) tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.Primitivescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Primitive# {
14 return tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewFramescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewFrame().(nil).
15 SetBordersscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Frame#SetBorders().(0, 0, 0, 0, 0, 0).
16 AddTextscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Frame#AddText().(text, true, tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.AlignCenterscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/AlignCenter., tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.ColorWhitescip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/ColorWhite.)
17 }
18
19 menu := newPrimitive("Menu")
20 main := newPrimitive("Main content")
21 sideBar := newPrimitive("Side Bar")
22
23 grid := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewGridscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewGrid().().
24 SetRowsscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#SetRows().(3, 0, 3).
25 SetColumnsscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#SetColumns().(0, -4, 0).
26 SetBordersscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#SetBorders().(true).
27 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(newPrimitive("Header"), 0, 0, 1, 3, 0, 0, true).
28 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(newPrimitive("Footer"), 2, 0, 1, 3, 0, 0, false)
29 grid.SetInputCapturescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetInputCapture().(func(event *tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.EventKeyscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/EventKey#) *tcellscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/.EventKeyscip-go gomod github.com/gdamore/tcell/v2 v2.7.4 `github.com/gdamore/tcell/v2`/EventKey# {
30 if modalShown {
31 nextSlide()
32 modalShown = false
33 } else {
34 pages.ShowPagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#ShowPage().("modal")
35 modalShown = true
36 }
37 return event
38 })
39
40 // Layout for screens narrower than 100 cells (menu and side bar are hidden).
41 grid.AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(menu, 0, 0, 0, 0, 0, 0, false).
42 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(main, 1, 0, 1, 3, 0, 0, false).
43 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(sideBar, 0, 0, 0, 0, 0, 0, false)
44
45 // Layout for screens wider than 100 cells.
46 grid.AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(menu, 1, 0, 1, 1, 0, 100, false).
47 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(main, 1, 1, 1, 1, 0, 100, false).
48 AddItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Grid#AddItem().(sideBar, 1, 2, 1, 1, 0, 100, false)
49
50 modal := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewModalscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewModal().().
51 SetTextscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Modal#SetText().("Resize the window to see how the grid layout adapts").
52 AddButtonsscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Modal#AddButtons().([]string{"Ok"}).SetDoneFuncscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Modal#SetDoneFunc().(func(buttonIndex int, buttonLabel string) {
53 pages.HidePagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#HidePage().("modal")
54 })
55
56 pages.AddPagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#AddPage().("grid", grid, true, true).
57 AddPagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#AddPage().("modal", modal, false, false)
58
59 return "Grid", pages
60 }