debian/andlabs/dropdown.go

81 lines
1.6 KiB
Go
Raw Normal View History

2024-01-01 16:11:54 -06:00
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/gui/widget"
2024-01-01 16:11:54 -06:00
)
func (p *node) newDropdown(n *node) {
newt := new(guiWidget)
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) {
log.Log(ERROR, "make map didn't work")
n.value = "map did not work. ui.Combobox error"
2024-01-01 16:11:54 -06:00
} else {
n.value = newt.val[i]
2024-01-01 16:11:54 -06:00
}
n.doUserEvent()
})
n.tk = newt
p.place(n)
}
func (t *guiWidget) addDropdownName(title string) {
t.uiCombobox.Append(title)
if (t.val == nil) {
log.Log(INFO, "make map didn't work")
2024-01-01 16:11:54 -06:00
return
}
t.val[t.c] = title
// If this is the first menu added, set the dropdown to it
if (t.c == 0) {
log.Log(INFO, "THIS IS THE FIRST Dropdown", title)
2024-01-01 16:11:54 -06:00
t.uiCombobox.SetSelected(0)
}
t.c = t.c + 1
}
func (t *guiWidget) SetDropdown(i int) {
t.uiCombobox.SetSelected(i)
}
func (n *node) AddDropdownName(s string) {
log.Log(INFO, "AddDropdownName()", n.WidgetId, "add:", s)
2024-01-01 16:11:54 -06:00
t := n.tk
if (t == nil) {
log.Log(INFO, "AddDropdownName() toolkit struct == nil. name=", n.progname, s)
2024-01-01 16:11:54 -06:00
return
}
t.addDropdownName(s)
}
func (n *node) SetDropdownName(a *widget.Action, s string) {
log.Log(INFO, "SetDropdown()", n.WidgetId, ",", s)
2024-01-01 16:11:54 -06:00
t := n.tk
if (t == nil) {
log.Log(ERROR, "SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s)
2024-01-01 16:11:54 -06:00
return
}
t.SetDropdown(1)
// TODO: send back to wit/gui goroutine with the chan
n.value = s
2024-01-01 16:11:54 -06:00
}