summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/dropdown.go
blob: fd28965066ed00e1e432af5f963bc529e2bb0a2c (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
package main

import (
	"github.com/andlabs/ui"
	_ "github.com/andlabs/ui/winmanifest"

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

func (p *node) newDropdown(n *node) {
	newt := new(andlabsT)
	log(debugToolkit, "gui.Toolbox.newDropdown() START", n.Name)

	cb := ui.NewCombobox()
	newt.uiCombobox = cb
	newt.uiControl = cb

	// initialize the index
	newt.c = 0
	newt.val = make(map[int]string)

	cb.OnSelected(func(spin *ui.Combobox) {
		i := spin.Selected()
		if (newt.val == nil) {
			log(debugChange, "make map didn't work")
			newt.text = "error"
		}
		newt.s = newt.val[i]
		newt.doUserEvent()
	})

	n.tk = newt
	p.place(n)
}

func (t *andlabsT) addDropdownName(title string) {
	t.uiCombobox.Append(title)
	if (t.val == nil) {
		log(debugToolkit, "make map didn't work")
		return
	}
	t.val[t.c] = title

	// If this is the first menu added, set the dropdown to it
	if (t.c == 0) {
		log(debugChange, "THIS IS THE FIRST Dropdown", title)
		t.uiCombobox.SetSelected(0)
	}
	t.c = t.c + 1
}

func (t *andlabsT) SetDropdown(i int) {
	t.uiCombobox.SetSelected(i)
}

func (n *node) AddDropdownName(a *toolkit.Action) {
	log(debugToolkit, "gui.andlabs.AddDropdownName()", n.WidgetId, "add:", a.S)

	t := n.tk
	if (t == nil) {
		log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", n.Name, a.S)
		listMap(debugToolkit)
		return
	}
	t.addDropdownName(a.S)
}

func (n *node) SetDropdownName(a *toolkit.Action, s string) {
	log(debugChange, "gui.andlabs.SetDropdown()", n.WidgetId, ",", s)

	t := n.tk
	if (t == nil) {
		log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s)
		listMap(debugError)
		return
	}
	t.SetDropdown(1)
	// TODO: send back to wit/gui goroutine with the chan
	t.s = s
}