diff options
Diffstat (limited to 'andlabs')
| -rw-r--r-- | andlabs/action.go | 7 | ||||
| -rw-r--r-- | andlabs/addText.go | 4 | ||||
| -rw-r--r-- | andlabs/combobox.go | 11 | ||||
| -rw-r--r-- | andlabs/dropdown.go | 69 |
4 files changed, 57 insertions, 34 deletions
diff --git a/andlabs/action.go b/andlabs/action.go index e0cdcff..0e4791d 100644 --- a/andlabs/action.go +++ b/andlabs/action.go @@ -8,6 +8,12 @@ import ( "go.wit.com/gui/widget" ) +func (n *node) ready() bool { + if n == nil { return false } + if n.tk == nil { return false } + return true +} + func (n *node) show(b bool) { if n.tk == nil { return @@ -225,6 +231,7 @@ func rawAction(a *widget.Action) { case widget.Enable: n.enable(true) case widget.Disable: + log.Warn("andlabs got disable for", n.WidgetId, n.progname) n.enable(false) case widget.Get: n.setText(a) diff --git a/andlabs/addText.go b/andlabs/addText.go index 74249a4..5dfe568 100644 --- a/andlabs/addText.go +++ b/andlabs/addText.go @@ -16,9 +16,9 @@ func (n *node) addText(a *widget.Action) { switch n.WidgetType { case widget.Dropdown: - n.AddDropdownName(getString(a.Value)) + n.addDropdownName(getString(a.Value)) case widget.Combobox: - t.AddComboboxName(getString(a.Value)) + t.addComboboxName(getString(a.Value)) default: log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType) } diff --git a/andlabs/combobox.go b/andlabs/combobox.go index cc3603e..3a25692 100644 --- a/andlabs/combobox.go +++ b/andlabs/combobox.go @@ -5,6 +5,7 @@ import ( _ "github.com/andlabs/ui/winmanifest" "go.wit.com/log" + "go.wit.com/gui/widget" ) func (p *node) newCombobox(n *node) { @@ -26,9 +27,17 @@ func (p *node) newCombobox(n *node) { n.tk = newt p.place(n) + + // add the initial dropdown entries + for i, s := range n.strings { + log.Warn("add dropdown entries on create", i, s) + n.addDropdownName(s) + } + cur := widget.GetString(n.value) + n.tk.addComboboxName(cur) } -func (t *guiWidget) AddComboboxName(title string) { +func (t *guiWidget) addComboboxName(title string) { t.uiEditableCombobox.Append(title) if (t.val == nil) { return diff --git a/andlabs/dropdown.go b/andlabs/dropdown.go index d2c493b..a189bf7 100644 --- a/andlabs/dropdown.go +++ b/andlabs/dropdown.go @@ -31,50 +31,57 @@ func (p *node) newDropdown(n *node) { n.doUserEvent() }) + n.tk = newt p.place(n) -} -func (t *guiWidget) addDropdownName(title string) { - t.uiCombobox.Append(title) - if (t.val == nil) { - log.Log(INFO, "make map didn't work") - return - } - t.val[t.c] = title - - // If this is the first menu added, set the dropdown to it - if (t.c == 0) { - log.Log(INFO, "THIS IS THE FIRST Dropdown", title) - t.uiCombobox.SetSelected(0) + // add the initial dropdown entries + for i, s := range n.strings { + log.Warn("add dropdown: add entries on create", n.progname, i, s) + n.addDropdownName(s) } - t.c = t.c + 1 + cur := widget.GetString(n.value) + log.Warn("add dropdown: set default value on create", n.progname, cur) + n.setDropdownName(cur) } -func (t *guiWidget) SetDropdown(i int) { - t.uiCombobox.SetSelected(i) + +func (n *node) SetDropdownInt(i int) { + if ! n.ready() { return } + n.tk.uiCombobox.SetSelected(i) } -func (n *node) AddDropdownName(s string) { - log.Log(INFO, "AddDropdownName()", n.WidgetId, "add:", s) +func (n *node) addDropdownName(s string) { + if ! n.ready() { return } + log.Log(INFO, "addDropdownName()", n.WidgetId, "add:", s) - t := n.tk - if (t == nil) { - log.Log(INFO, "AddDropdownName() toolkit struct == nil. name=", n.progname, s) + n.tk.uiCombobox.Append(s) + if (n.tk.val == nil) { + log.Log(INFO, "make map didn't work") return } - t.addDropdownName(s) + n.tk.val[n.tk.c] = s + + // If this is the first menu added, set the dropdown to it + if (n.tk.c == 0) { + log.Log(INFO, "THIS IS THE FIRST Dropdown", s) + n.tk.uiCombobox.SetSelected(0) + } + n.tk.c = n.tk.c + 1 } -func (n *node) SetDropdownName(a *widget.Action, s string) { - log.Log(INFO, "SetDropdown()", n.WidgetId, ",", s) +func (n *node) setDropdownName(s string) bool { + if ! n.ready() { return false} + log.Log(INFO, "SetDropdownName()", n.WidgetId, ",", s) - t := n.tk - if (t == nil) { - log.Log(ERROR, "SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s) - return + for i, tmp := range n.tk.val { + if s == tmp { + n.value = s + n.SetDropdownInt(i) + log.Warn("SetDropdownInt() worked", tmp, i) + return true + } } - t.SetDropdown(1) - // TODO: send back to wit/gui goroutine with the chan - n.value = s + log.Warn("SetDropdownName() failed", s) + return false } |
