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

import "log"
import "reflect"
// import "image/color"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew"


// TODO: bring this generic mouse click function back
//
// This is the default mouse click handler
// Every mouse click that hasn't been assigned to
// something specific will fall into this routine
// By default, all it runs is the call back to
// the main program that is using this library
//
// This routine MUST be here as this is how the andlabs/ui works
// This is the raw routine passed to every button in andlabs libui / ui
//
//

func (n *Node) AddButton(name string, custom func(*Node)) *Node {
	if (n.uiBox == nil) {
		log.Println("gui.Node.AppendButton() filed node.UiBox == nil")
		return n
	}
	button := ui.NewButton(name)
	if (Config.Debug) {
		log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox))
		log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button))
	}
	// true == expand, false == make normal size button
	n.uiBox.Append(button, false)
	n.uiButton = button

	newNode := n.makeNode(name, 888, 888 + Config.counter)
	newNode.uiButton = button
	newNode.custom = custom

	button.OnClicked(func(*ui.Button) {
		log.Println("gui.AppendButton() Button Clicked. Running custom()")
		custom(newNode)
	})
	return newNode
}

func (n *Node) CreateFontButton(action string) *Node {
	n.uiFontButton	= ui.NewFontButton()

	n.uiFontButton.OnChanged(func (*ui.FontButton) {
		log.Println("FontButton.OnChanged() START")
		n.Dump()
	})
	return n
}

func (n *Node) CreateColorButton(custom func(*Node), name string, values interface {}) *Node {
        // create a 'fake' button entry for the mouse clicks
	n.uiColorButton	= ui.NewColorButton()
	n.custom	= custom
	n.values	= values

	n.uiColorButton.OnChanged(func (*ui.ColorButton) {
		log.Println("ColorButton.OnChanged() START Color Button Click")
		rgba := n.Color
		r, g, b, a := rgba.R, rgba.G, rgba.B, rgba.A
		log.Println("ColorButton.OnChanged() Color() =", r, g, b, a)
		if (n.custom != nil) {
			n.custom(n)
		} else if (Data.MouseClick != nil) {
			Data.MouseClick(n)
		}
	})
	n.uiBox.Append(n.uiColorButton, false)
	return n
}