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

import (
	"github.com/andlabs/ui"
	_ "github.com/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 dropdown entries
	for i, s := range n.strings {
		log.Warn("add dropdown entries on create", i, s)
		n.addDropdownName(s)
	}
	cur := widget.GetString(n.value)
	n.tk.addComboboxName(cur)
}

func (t *guiWidget) addComboboxName(title string) {
	t.uiEditableCombobox.Append(title)
	if (t.val == nil) {
		return
	}
	t.val[t.c] = title

	// If this is the first menu added, set the dropdown to it
	// if (t.c == 0) {
	// }
	t.c = t.c + 1
}