2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
import (
|
|
|
|
"github.com/andlabs/ui"
|
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
)
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT {
|
2022-11-14 14:30:28 -06:00
|
|
|
var newt andlabsT
|
2023-03-03 14:41:38 -06:00
|
|
|
log(debugToolkit, "gui.Toolbox.newDropdown() START", w.Name)
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.tw = w
|
2022-10-20 06:55:42 -05:00
|
|
|
s := ui.NewCombobox()
|
|
|
|
newt.uiCombobox = s
|
2023-03-23 12:35:12 -05:00
|
|
|
newt.uiControl = s
|
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-03-01 11:35:36 -06:00
|
|
|
log(debugChange, "make map didn't work")
|
2022-11-14 14:30:28 -06:00
|
|
|
newt.text = "error"
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.tw.S = newt.val[i]
|
|
|
|
newt.commonChange(newt.tw)
|
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
|
2023-03-01 11:35:36 -06:00
|
|
|
|
|
|
|
// If this is the first menu added, set the dropdown to it
|
|
|
|
if (t.c == 0) {
|
|
|
|
log(debugChange, "THIS IS THE FIRST Dropdown", title)
|
2023-03-12 08:47:16 -05:00
|
|
|
t.uiCombobox.SetSelected(0)
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
2022-10-20 06:55:42 -05:00
|
|
|
t.c = t.c + 1
|
|
|
|
}
|
|
|
|
|
2023-03-03 14:41:38 -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
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
func AddDropdownName(a *toolkit.Action) {
|
|
|
|
log(debugToolkit, "gui.andlabs.AddDropdownName()", a.Widget.Name, "add:", a.S)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
t := mapToolkits[a.Widget]
|
2022-11-14 14:30:28 -06:00
|
|
|
if (t == nil) {
|
2023-03-23 12:35:12 -05:00
|
|
|
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", a.Widget.Name, a.S)
|
2023-03-01 11:35:36 -06:00
|
|
|
listMap(debugToolkit)
|
|
|
|
return
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
2023-03-23 12:35:12 -05:00
|
|
|
t.AddDropdownName(a.S)
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func SetDropdownName(w *toolkit.Widget, s string) {
|
|
|
|
log(debugChange, "gui.andlabs.SetDropdown()", w.Name, ",", s)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
t := mapToolkits[w]
|
|
|
|
if (t == nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", w.Name, s)
|
|
|
|
listMap(debugError)
|
|
|
|
return
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
t.SetDropdown(1)
|
|
|
|
t.tw.S = s
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
2023-03-03 14:41:38 -06:00
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
func newDropdown(a *toolkit.Action) {
|
|
|
|
w := a.Widget
|
|
|
|
parentW := a.Where
|
2023-03-03 14:41:38 -06:00
|
|
|
log(debugToolkit, "gui.andlabs.newDropdown()", w.Name)
|
|
|
|
|
|
|
|
t := mapToolkits[parentW]
|
|
|
|
if (t == nil) {
|
|
|
|
log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", parentW.Name, w.Name)
|
|
|
|
listMap(debugToolkit)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newt := t.newDropdown(w)
|
2023-03-23 12:35:12 -05:00
|
|
|
place(a, t, newt)
|
|
|
|
mapWidgetsToolkits(a, newt)
|
2023-03-03 14:41:38 -06:00
|
|
|
}
|