2024-01-17 23:54:19 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/dev/andlabs/ui"
|
|
|
|
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/toolkits/tree"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newDropdown(p, n *tree.Node) {
|
|
|
|
if notNew(n) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newt := new(guiWidget)
|
|
|
|
log.Log(INFO, "gui.Toolbox.newDropdown() START", n.GetProgName())
|
|
|
|
|
|
|
|
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")
|
2024-02-05 15:04:01 -06:00
|
|
|
n.State.CurrentS = "map did not work. ui.Combobox error"
|
2024-01-17 23:54:19 -06:00
|
|
|
} else {
|
2024-02-05 15:04:01 -06:00
|
|
|
n.State.CurrentS = newt.val[i]
|
2024-01-17 23:54:19 -06:00
|
|
|
}
|
2024-01-19 02:52:57 -06:00
|
|
|
me.myTree.SendUserEvent(n)
|
2024-01-17 23:54:19 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
n.TK = newt
|
|
|
|
place(p, n)
|
|
|
|
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "add dropdown entries on create:", n.State.Strings)
|
2024-01-17 23:54:19 -06:00
|
|
|
if n.State.Strings == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// add the initial dropdown entries
|
|
|
|
for i, s := range n.State.Strings {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "add dropdown: add entries on create", n.GetProgName(), i, s)
|
2024-01-17 23:54:19 -06:00
|
|
|
addDropdownName(n, s)
|
|
|
|
}
|
|
|
|
cur := n.String()
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "add dropdown: set default value on create", n.GetProgName(), cur)
|
2024-01-17 23:54:19 -06:00
|
|
|
setDropdownName(n, cur)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setDropdownInt(n *tree.Node, i int) {
|
|
|
|
if !ready(n) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
|
|
|
tk.uiCombobox.SetSelected(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func addDropdownName(n *tree.Node, s string) {
|
|
|
|
if !ready(n) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
|
|
|
log.Log(INFO, "addDropdownName()", n.WidgetId, "add:", s)
|
|
|
|
|
|
|
|
tk.uiCombobox.Append(s)
|
|
|
|
if tk.val == nil {
|
|
|
|
log.Log(INFO, "make map didn't work")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tk.val[tk.c] = s
|
|
|
|
|
|
|
|
// If this is the first menu added, set the dropdown to it
|
|
|
|
if tk.c == 0 {
|
|
|
|
log.Log(INFO, "THIS IS THE FIRST Dropdown", s)
|
|
|
|
tk.uiCombobox.SetSelected(0)
|
|
|
|
}
|
|
|
|
tk.c = tk.c + 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func setDropdownName(n *tree.Node, s string) bool {
|
|
|
|
if !ready(n) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
|
|
|
log.Log(INFO, "SetDropdownName()", n.WidgetId, ",", s)
|
|
|
|
|
|
|
|
for i, tmp := range tk.val {
|
|
|
|
if s == tmp {
|
2024-02-05 15:04:01 -06:00
|
|
|
n.State.CurrentS = s
|
2024-01-17 23:54:19 -06:00
|
|
|
setDropdownInt(n, i)
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "SetDropdownInt() worked", tmp, i)
|
2024-01-17 23:54:19 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "SetDropdownName() failed", s, n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return false
|
|
|
|
}
|