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

import "git.wit.org/wit/gui/toolkit"

func (n *Node) NewButton(name string, custom func()) *Node {
	newNode := n.newNode(name, toolkit.Button, custom)

	var a toolkit.Action
	a.Name = name
	a.Text = name
	a.ActionType = toolkit.Add
	newaction(&a, newNode, n)

	return newNode
}

// deprecate this once andlabs is refactored
func callback(i int) bool {
	log(debugError, "callback() for widget id =", i)
	n := me.rootNode.FindId(i)
	log(debugError, "callback() found node =", n)
	// running custom here means the button get's clicked twice
	if (n.Custom == nil) {
		log(debugError, "callback() = nil. SKIPPING")
		return false
	}
	n.Custom()
	return true
}

// find widget by number
func (n *Node) FindId(i int) (*Node) {
	if (n == nil) {
		return nil
	}

	if (n.id == i) {
		return n
	}

	for _, child := range n.children {
		newN := child.FindId(i)
		if (newN != nil) {
			return newN
		}
	}
	return nil
}