summaryrefslogtreecommitdiff
path: root/cmds/buttonplugin/main.go
blob: 0c72c3fb3077ce606f9685f0879bba87e7a0855a (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// This is a simple example
package main

import 	(
	"fmt"
	"log"
	"time"
	"strconv"
	"git.wit.org/wit/gui"
)

var title string = "Demo Plugin Window"

func main() {
	fmt.Println("\033]0;" + title + "\007")
	// time.Sleep(5 * time.Second)
	// var w *gui.Node
	// this doesn't seem to work
	captureSTDOUT()

	// gui.LoadToolkit("default")
	// panic("WTF gocui not happening")
	// gui.LoadToolkit("gocui")
//	gui.Init()

	// buttonWindow()
	go gui.Main(func () {
		log.Println("START Main f()")
		buttonWindow()
		/*
		log.Println("END NewWindow()")
		log.Println("START NewGroup()")
		g := w.NewGroup("new Group 22")
		log.Println("END NewGroup()")
		g.NewButton("asdjkl", func () {
			log.Println("world")
		})
		*/
		log.Println("END Main f()")
		// gui.StandardExit(nil)
	})
	log.Println("Main() END")
	time.Sleep(1 * time.Second)
	gui.Watchdog()
	gui.StandardExit()
}

var counter int = 5

// This creates a window
func buttonWindow() {
	var w, g *gui.Node
	gui.Config.Title = title
	gui.Config.Width = 640
	gui.Config.Height = 480

	w = gui.NewWindow()
	g = w.NewGroup("buttonGroup")

	g.NewButton("hello", func () {
		log.Println("world")
	})

	g.NewButton("NewButton()", func () {
		log.Println("new foobar 2. Adding button 'foobar 3'")
		name := "foobar " + strconv.Itoa(counter)
		counter += 1
		g.NewButton(name, func () {
			log.Println("Got all the way to main() name =", name)
		})
	})

	g.NewButton("NewGroup()", func () {
		log.Println("new foobar 2. Adding button 'foobar 3'")
		name := "neat " + strconv.Itoa(counter)
		counter += 1
		g.NewGroup(name)
	})

	g.NewButton("gui.DebugWindow()", func () {
		gui.DebugWindow()
	})

	g.NewButton("LoadToolkit(andlabs)", func () {
		gui.LoadToolkit("andlabs")
	})

	g.NewButton("LoadToolkit(gocui)", func () {
		gui.LoadToolkit("gocui")
	})

	g.NewButton("Init()", func () {
		log.Println("gui.Init() is deprecated(?)")
		//gui.Init()
	})

	g.NewButton("Main()", func () {
		go gui.Main(func () {
			w := gui.NewWindow()
			w.NewGroup("buttonGroup")
		})
	})
}