summaryrefslogtreecommitdiff
path: root/button.go
blob: 7b01e1ea536a47c79388b757c21e27aa8b00638c (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
package gui

import "log"

func (n *Node) NewButton(name string, custom func()) *Node {
	if (n.toolkit == nil) {
		log.Println("gui.Node.NewButton() filed node.toolkit == nil")
		panic("gui.Node.NewButton() filed node.toolkit == nil")
		return n
	}
	newNode := n.New(name)
	newNode.toolkit = n.toolkit.NewButton(name)

	log.Println("gui.Node.NewButton()", name)
	if (PlugGocliOk) {
		log.Println("wit/gui gocui is loaded", PlugGocliOk)
		greeter.AddButton(name)
		log.Println("GOT HERE PlugGocliOk TRUE")
	} else {
		log.Println("GOT HERE PlugGocliOk FALSE")
	}

	// TODO: this is still confusing and probably wrong. This needs to communicate through a channel
	newNode.toolkit.Custom = func() {
		if (Config.Options.Debug) {
			log.Println("gui.Newutton() Button Clicked. Running custom() from outside toolkit START")
		}
		if (custom != nil) {
			custom()
		} else {
			log.Println("wit/gui No callback function is defined for button name =", name)
		}
		if (Config.Options.Debug) {
			log.Println("gui.NewButton() Button Clicked. Running custom() from outside toolkit END")
		}
	}
	newNode.custom = custom

	return newNode
}