/
simple.go
84 lines (69 loc) · 2.18 KB
/
simple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"github.com/jojomi/gonsole"
"github.com/nsf/termbox-go"
)
func main() {
app := gonsole.NewApp()
app.CloseKey = termbox.KeyEsc
//app.CloseKey = 'q'
win := gonsole.NewWindow("winMain")
panel := gonsole.NewPanel("panel1")
panel.Position = gonsole.Position{"25%", "25%", "50%", "50%"}
panel.Title = "Test Controls"
//panel.TitleAlignment =
//panel.Background = termbox.ColorWhite
panel.SetBorder(gonsole.LineDashed)
win.AddControl(panel)
//win.Background = termbox.ColorBlue
ctrl := gonsole.NewLabel("lblStatus")
ctrl.Position = gonsole.Position{"2", "2", "30", "3"}
ctrl.Text = "Test"
ctrl.SetBorder(gonsole.LineSingle)
ctrl.Margin = gonsole.Sides{0, 1, 0, 1}
win.AddControl(ctrl)
ctrlChk := gonsole.NewCheckbox("chkActive")
ctrlChk.Position = gonsole.Position{"2", "2", "30", "3"}
ctrlChk.Checked = true
ctrlChk.Text = "Test"
ctrlChk.SetBorder(gonsole.LineDouble)
panel.AddControl(ctrlChk)
ctrlChk2 := gonsole.NewCheckbox("chkActive2")
ctrlChk2.Position = gonsole.Position{"2", "7", "30", "3"}
ctrlChk2.Checked = false
ctrlChk2.Text = "Test with more text"
panel.AddControl(ctrlChk2)
ctrlBtn := gonsole.NewButton("MyButton")
ctrlBtn.Position = gonsole.Position{"2", "10", "40", "3"}
ctrlBtn.Text = "This is a button. Push me!"
ctrlBtn.SetBorder(gonsole.LineSingle)
panel.AddControl(ctrlBtn)
ctrlBtn2 := gonsole.NewButton("MyButton2")
ctrlBtn2.Position = gonsole.Position{"2", "14", "40", "3"}
ctrlBtn2.Text = "This is my second magic button..."
ctrlBtn2.SetBorder(gonsole.LineSingle)
panel.AddControl(ctrlBtn2)
ctrlChk2.Focus()
app.AddWindow(win)
// events
ctrlBtn.AddEventListener("clicked", func(ev *gonsole.Event) bool {
ctrlBtn.Text = "--- clicked ---"
return true
})
ctrlBtn2.AddEventListener("clicked", func(ev *gonsole.Event) bool {
btn := ev.Source.(*gonsole.Button)
btn.Text = "Clicked button"
return true
})
ctrlChk2.AddEventListener("checked", func(ev *gonsole.Event) bool {
chk := ev.Source.(*gonsole.Checkbox)
chk.Text = "works"
return true
})
ctrlChk2.AddEventListener("unchecked", func(ev *gonsole.Event) bool {
chk := ev.Source.(*gonsole.Checkbox)
chk.Text = "does not work"
return true
})
app.Run()
}