2024-01-01 16:11:54 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/andlabs/ui"
|
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2024-01-08 21:19:42 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-05 13:30:00 -06:00
|
|
|
"go.wit.com/gui/widget"
|
2024-01-01 16:11:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func (p *node) newDropdown(n *node) {
|
|
|
|
newt := new(guiWidget)
|
2024-01-11 17:19:47 -06:00
|
|
|
log.Log(INFO, "gui.Toolbox.newDropdown() START", n.progname)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
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) {
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(ERROR, "make map didn't work")
|
2024-01-11 17:19:47 -06:00
|
|
|
n.value = "map did not work. ui.Combobox error"
|
2024-01-01 16:11:54 -06:00
|
|
|
} else {
|
2024-01-11 17:19:47 -06:00
|
|
|
n.value = newt.val[i]
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
n.doUserEvent()
|
|
|
|
})
|
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
|
2024-01-01 16:11:54 -06:00
|
|
|
n.tk = newt
|
|
|
|
p.place(n)
|
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
// add the initial dropdown entries
|
|
|
|
for i, s := range n.strings {
|
|
|
|
log.Warn("add dropdown: add entries on create", n.progname, i, s)
|
|
|
|
n.addDropdownName(s)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-13 21:28:41 -06:00
|
|
|
cur := widget.GetString(n.value)
|
|
|
|
log.Warn("add dropdown: set default value on create", n.progname, cur)
|
|
|
|
n.setDropdownName(cur)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
|
|
|
|
func (n *node) SetDropdownInt(i int) {
|
|
|
|
if ! n.ready() { return }
|
|
|
|
n.tk.uiCombobox.SetSelected(i)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
func (n *node) addDropdownName(s string) {
|
|
|
|
if ! n.ready() { return }
|
|
|
|
log.Log(INFO, "addDropdownName()", n.WidgetId, "add:", s)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
n.tk.uiCombobox.Append(s)
|
|
|
|
if (n.tk.val == nil) {
|
|
|
|
log.Log(INFO, "make map didn't work")
|
2024-01-01 16:11:54 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-13 21:28:41 -06:00
|
|
|
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 Dropdown", s)
|
|
|
|
n.tk.uiCombobox.SetSelected(0)
|
|
|
|
}
|
|
|
|
n.tk.c = n.tk.c + 1
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
func (n *node) setDropdownName(s string) bool {
|
|
|
|
if ! n.ready() { return false}
|
|
|
|
log.Log(INFO, "SetDropdownName()", n.WidgetId, ",", s)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-13 21:28:41 -06:00
|
|
|
for i, tmp := range n.tk.val {
|
|
|
|
if s == tmp {
|
|
|
|
n.value = s
|
|
|
|
n.SetDropdownInt(i)
|
|
|
|
log.Warn("SetDropdownInt() worked", tmp, i)
|
|
|
|
return true
|
|
|
|
}
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-13 21:28:41 -06:00
|
|
|
log.Warn("SetDropdownName() failed", s)
|
|
|
|
return false
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|