summaryrefslogtreecommitdiff
path: root/andlabs/combobox.go
blob: 0dd16c640e413bd2cc846de76f0c2e5f4c0dc5d1 (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
package main

import (
	"go.wit.com/dev/andlabs/ui"
	_ "go.wit.com/dev/andlabs/ui/winmanifest"

	"go.wit.com/log"
	"go.wit.com/gui/widget"
)

func (p *node) newCombobox(n *node) {
	newt := new(guiWidget)

	cb := ui.NewEditableCombobox()
	newt.uiEditableCombobox = cb
	newt.uiControl = cb

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

	cb.OnChanged(func(spin *ui.EditableCombobox) {
		n.value = spin.Text()
		log.Warn("combobox changed =" + spin.Text() + ".")
		n.doUserEvent()
	})

	n.tk = newt
	p.place(n)

	// add the initial combobox entries
	for i, s := range n.strings {
		log.Warn("add combobox entries on create", n.progname, i, s)
		n.addComboboxName(s)
	}
	cur := widget.GetString(n.value)
	log.Warn("add combobox: TODO: set default value on create", n.progname, cur)
	n.setComboboxName(cur)
}

func (n *node) addComboboxName(s string) {
	if ! n.ready() { return }
	log.Log(INFO, "addComboboxName()", n.WidgetId, "add:", s)

	n.tk.uiEditableCombobox.Append(s)
	if (n.tk.val == nil) {
		log.Log(INFO, "make map didn't work")
		return
	}
	n.tk.val[n.tk.c] = s

	// If this is the first menu added, set the dropdown to it
	if (n.tk.c == 0) {
		log.Log(INFO, "THIS IS THE FIRST combobox", s)
		n.tk.uiEditableCombobox.SetText(s)
	}
	n.tk.c = n.tk.c + 1
}

func (n *node) setComboboxName(s string) bool {
	if ! n.ready() { return false}
	log.Log(INFO, "SetComboboxName()", n.WidgetId, ",", s)
	n.tk.uiEditableCombobox.SetText(s)
	return false
}