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-29 23:03:04 -05:00
|
|
|
func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
|
2022-11-14 14:30:28 -06:00
|
|
|
var newt andlabsT
|
2023-03-29 23:03:04 -05:00
|
|
|
w := a.Widget
|
|
|
|
log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Name)
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.tw = w
|
2023-04-03 10:26:47 -05:00
|
|
|
newt.WidgetType = a.WidgetType
|
2023-03-29 23:03:04 -05:00
|
|
|
newt.wId = a.WidgetId
|
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]
|
2023-03-29 23:03:04 -05:00
|
|
|
newt.commonChange(newt.tw, a.WidgetId)
|
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) {
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "gui.andlabs.AddDropdownName()", a.WidgetId, "add:", a.S)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
t := andlabs[a.WidgetId]
|
2022-11-14 14:30:28 -06:00
|
|
|
if (t == nil) {
|
2023-04-03 10:26:47 -05:00
|
|
|
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", a.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-29 23:03:04 -05:00
|
|
|
func SetDropdownName(a *toolkit.Action, s string) {
|
|
|
|
log(debugChange, "gui.andlabs.SetDropdown()", a.WidgetId, ",", s)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
t := andlabs[a.WidgetId]
|
2022-11-14 14:30:28 -06:00
|
|
|
if (t == nil) {
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", a.WidgetId, s)
|
2023-03-01 11:35:36 -06:00
|
|
|
listMap(debugError)
|
|
|
|
return
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
t.SetDropdown(1)
|
2023-03-29 23:03:04 -05:00
|
|
|
// TODO: send back to wit/gui goroutine with the chan
|
2023-03-01 11:35:36 -06:00
|
|
|
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) {
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "gui.andlabs.newDropdown()", a.Name)
|
2023-03-03 14:41:38 -06:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
t := andlabs[a.ParentId]
|
2023-03-03 14:41:38 -06:00
|
|
|
if (t == nil) {
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", a.WidgetId)
|
2023-03-03 14:41:38 -06:00
|
|
|
listMap(debugToolkit)
|
|
|
|
return
|
|
|
|
}
|
2023-03-29 23:03:04 -05:00
|
|
|
newt := t.newDropdown(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
place(a, t, newt)
|
2023-03-29 23:03:04 -05:00
|
|
|
// mapWidgetsToolkits(a, newt)
|
2023-03-03 14:41:38 -06:00
|
|
|
}
|