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
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
if t.broken() {
|
2022-10-20 06:55:42 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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
|
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-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)
|
|
|
|
t.uiCombobox.SetSelected(1)
|
|
|
|
}
|
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
|
|
|
|
|
|
|
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)
|
2023-03-01 11:35:36 -06:00
|
|
|
listMap(debugToolkit)
|
|
|
|
return
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
|
|
|
t.AddDropdownName(s)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
func newDropdown(parentW *toolkit.Widget, w *toolkit.Widget) {
|
|
|
|
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)
|
|
|
|
mapWidgetsToolkits(w, newt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func doDropdown(p *toolkit.Widget, c *toolkit.Widget) {
|
|
|
|
if broken(c) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (c.Action == "New") {
|
|
|
|
newDropdown(p, c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ct := mapToolkits[c]
|
|
|
|
if (ct == nil) {
|
|
|
|
log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ct.broken() {
|
|
|
|
log(true, "Dropdown() ct.broken", ct)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (ct.uiCombobox == nil) {
|
|
|
|
log(true, "Dropdown() uiCombobox == nil", ct)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log(true, "Going to attempt:", c.Action)
|
|
|
|
switch c.Action {
|
|
|
|
case "Add":
|
|
|
|
ct.AddDropdownName(c.S)
|
|
|
|
// ct.uiCombobox.Enable()
|
|
|
|
case "Enable":
|
|
|
|
ct.uiCombobox.Enable()
|
|
|
|
case "Disable":
|
|
|
|
ct.uiCombobox.Disable()
|
|
|
|
case "Show":
|
|
|
|
ct.uiCombobox.Show()
|
|
|
|
case "Hide":
|
|
|
|
ct.uiCombobox.Hide()
|
|
|
|
case "Set":
|
|
|
|
ct.uiCombobox.SetSelected(1)
|
|
|
|
default:
|
|
|
|
log(true, "Can't do", c.Action, "to a Dropdown")
|
|
|
|
}
|
|
|
|
}
|