2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
import "log"
|
|
|
|
// import "time"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
import "git.wit.org/wit/gui/toolkit"
|
|
|
|
|
|
|
|
func (t *andlabsT) NewDropdown(title string) *andlabsT {
|
2022-10-20 06:55:42 -05:00
|
|
|
// make new node here
|
2022-11-05 10:19:04 -05:00
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolbox.NewDropdownCombobox()", title)
|
|
|
|
}
|
2022-11-14 14:30:28 -06:00
|
|
|
var newt andlabsT
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
if t.broken() {
|
2022-10-20 06:55:42 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
s := ui.NewCombobox()
|
|
|
|
newt.uiCombobox = s
|
2022-10-21 11:40:08 -05:00
|
|
|
newt.uiBox = t.uiBox
|
|
|
|
t.uiBox.Append(s, stretchy)
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
// initialize the index
|
|
|
|
newt.c = 0
|
|
|
|
newt.val = make(map[int]string)
|
|
|
|
|
|
|
|
s.OnSelected(func(spin *ui.Combobox) {
|
|
|
|
i := spin.Selected()
|
|
|
|
if (newt.val == nil) {
|
|
|
|
log.Println("make map didn't work")
|
2022-11-14 14:30:28 -06:00
|
|
|
newt.text = "error"
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|
|
|
|
newt.text = newt.val[i]
|
2022-10-21 11:40:08 -05:00
|
|
|
newt.commonChange("Dropdown")
|
2022-10-20 06:55:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
return &newt
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
func (t *andlabsT) AddDropdownName(title string) {
|
2022-10-20 06:55:42 -05:00
|
|
|
t.uiCombobox.Append(title)
|
|
|
|
if (t.val == nil) {
|
|
|
|
log.Println("make map didn't work")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.val[t.c] = title
|
|
|
|
t.c = t.c + 1
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
func (t andlabsT) SetDropdown(i int) {
|
2022-10-20 06:55:42 -05:00
|
|
|
t.uiCombobox.SetSelected(i)
|
|
|
|
}
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
func NewDropdown(parentW *toolkit.Widget, w *toolkit.Widget) {
|
|
|
|
log.Println("gui.andlabs.NewDropdown()", w.Name)
|
|
|
|
|
|
|
|
t := mapToolkits[parentW]
|
|
|
|
if (t == nil) {
|
|
|
|
log.Println("go.andlabs.NewDropdown() toolkit struct == nil. name=", parentW.Name, w.Name)
|
|
|
|
listMap()
|
|
|
|
}
|
|
|
|
newt := t.NewDropdown(w.Name)
|
|
|
|
mapWidgetsToolkits(w, newt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func AddDropdownName(w *toolkit.Widget, s string) {
|
|
|
|
log.Println("gui.andlabs.AddDropdownName()", w.Name, "add:", s)
|
|
|
|
|
|
|
|
t := mapToolkits[w]
|
|
|
|
if (t == nil) {
|
|
|
|
log.Println("go.andlabs.AddDropdownName() toolkit struct == nil. name=", w.Name, s)
|
|
|
|
listMap()
|
|
|
|
}
|
|
|
|
t.AddDropdownName(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetDropdown(w *toolkit.Widget, i int) {
|
|
|
|
log.Println("gui.andlabs.SetDropdown()", i)
|
|
|
|
|
|
|
|
t := mapToolkits[w]
|
|
|
|
if (t == nil) {
|
|
|
|
log.Println("go.andlabs.SetDropdown() toolkit struct == nil. name=", w.Name, i)
|
|
|
|
listMap()
|
|
|
|
}
|
|
|
|
t.SetDropdown(i)
|
|
|
|
}
|