2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
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-14 14:30:28 -06:00
|
|
|
var newt andlabsT
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.Toolbox.NewDropdownCombobox()", title)
|
|
|
|
|
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) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "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) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "make map didn't work")
|
2022-10-20 06:55:42 -05:00
|
|
|
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) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.andlabs.NewDropdown()", w.Name)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
t := mapToolkits[parentW]
|
|
|
|
if (t == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "go.andlabs.NewDropdown() toolkit struct == nil. name=", parentW.Name, w.Name)
|
2022-11-14 14:30:28 -06:00
|
|
|
listMap()
|
|
|
|
}
|
|
|
|
newt := t.NewDropdown(w.Name)
|
2023-02-25 14:05:25 -06:00
|
|
|
newt.Custom = w.Custom
|
|
|
|
newt.tw = w
|
2022-11-14 14:30:28 -06:00
|
|
|
mapWidgetsToolkits(w, newt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func AddDropdownName(w *toolkit.Widget, s string) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.andlabs.AddDropdownName()", w.Name, "add:", s)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
t := mapToolkits[w]
|
|
|
|
if (t == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", w.Name, s)
|
2022-11-14 14:30:28 -06:00
|
|
|
listMap()
|
|
|
|
}
|
|
|
|
t.AddDropdownName(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetDropdown(w *toolkit.Widget, i int) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.andlabs.SetDropdown()", i)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
t := mapToolkits[w]
|
|
|
|
if (t == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "go.andlabs.SetDropdown() toolkit struct == nil. name=", w.Name, i)
|
2022-11-14 14:30:28 -06:00
|
|
|
listMap()
|
|
|
|
}
|
|
|
|
t.SetDropdown(i)
|
|
|
|
}
|