From 31dbec2b5610ae4ef5016189199085c9eea7f865 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 13 Jan 2024 21:28:41 -0600 Subject: [PATCH] hidden widgets Signed-off-by: Jeff Carr --- andlabs/action.go | 7 ++++ andlabs/addText.go | 4 +- andlabs/combobox.go | 11 +++++- andlabs/dropdown.go | 71 ++++++++++++++++++---------------- nocui/common.go | 93 ++++++++++++++++++++++++--------------------- 5 files changed, 107 insertions(+), 79 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) + + // 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) + } + cur := widget.GetString(n.value) + log.Warn("add dropdown: set default value on create", n.progname, cur) + n.setDropdownName(cur) } -func (t *guiWidget) addDropdownName(title string) { - t.uiCombobox.Append(title) - if (t.val == nil) { + +func (n *node) SetDropdownInt(i int) { + if ! n.ready() { return } + n.tk.uiCombobox.SetSelected(i) +} + +func (n *node) addDropdownName(s string) { + if ! n.ready() { return } + log.Log(INFO, "addDropdownName()", n.WidgetId, "add:", s) + + n.tk.uiCombobox.Append(s) + if (n.tk.val == nil) { log.Log(INFO, "make map didn't work") return } - t.val[t.c] = title + n.tk.val[n.tk.c] = s // 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) + if (n.tk.c == 0) { + log.Log(INFO, "THIS IS THE FIRST Dropdown", s) + n.tk.uiCombobox.SetSelected(0) } - t.c = t.c + 1 + n.tk.c = n.tk.c + 1 } -func (t *guiWidget) SetDropdown(i int) { - t.uiCombobox.SetSelected(i) -} +func (n *node) setDropdownName(s string) bool { + if ! n.ready() { return false} + log.Log(INFO, "SetDropdownName()", n.WidgetId, ",", s) -func (n *node) AddDropdownName(s string) { - 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) - 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.addDropdownName(s) -} - -func (n *node) SetDropdownName(a *widget.Action, s string) { - log.Log(INFO, "SetDropdown()", n.WidgetId, ",", s) - - t := n.tk - if (t == nil) { - log.Log(ERROR, "SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s) - return - } - t.SetDropdown(1) - // TODO: send back to wit/gui goroutine with the chan - n.value = s + log.Warn("SetDropdownName() failed", s) + return false } diff --git a/nocui/common.go b/nocui/common.go index 9a13323..35d8f22 100644 --- a/nocui/common.go +++ b/nocui/common.go @@ -49,6 +49,8 @@ type node struct { // values from things like checkboxes & dropdown's value any + strings []string + // This is used for things like a slider(0,100) X int Y int @@ -106,50 +108,6 @@ func (n *node) doUserEvent() { return } -func addNode(a *widget.Action) *node { - n := new(node) - n.WidgetType = a.WidgetType - n.WidgetId = a.WidgetId - n.ParentId = a.ParentId - - // copy the data from the action message - n.progname = a.ProgName - n.value = a.Value - n.direction = a.Direction - - n.X = a.X - n.Y = a.Y - - n.W = a.W - n.H = a.H - n.AtW = a.AtW - n.AtH = a.AtH - - // store the internal toolkit information - n.tk = initWidget(n) - // n.tk = new(guiWidget) - - if (a.WidgetType == widget.Root) { - log.Log(INFO, "addNode() Root") - return n - } - - if (me.rootNode.findWidgetId(a.WidgetId) != nil) { - log.Log(ERROR, "addNode() WidgetId already exists", a.WidgetId) - return me.rootNode.findWidgetId(a.WidgetId) - } - - // add this new widget on the binary tree - n.parent = me.rootNode.findWidgetId(a.ParentId) - if n.parent != nil { - n.parent.children = append(n.parent.children, n) - //w := n.tk - //w.parent = n.parent.tk - //w.parent.children = append(w.parent.children, w) - } - return n -} - // Other goroutines must use this to access the GUI // // You can not acess / process the GUI thread directly from @@ -181,6 +139,7 @@ func convertString(val any) string { } */ +// this is in common.go, do not move it func getString(A any) string { if A == nil { log.Warn("getString() got nil") @@ -208,3 +167,49 @@ func getString(A any) string { } return "" } + +// this is in common.go, do not move it +func addNode(a *widget.Action) *node { + n := new(node) + n.WidgetType = a.WidgetType + n.WidgetId = a.WidgetId + n.ParentId = a.ParentId + + // copy the data from the action message + n.progname = a.ProgName + n.value = a.Value + n.direction = a.Direction + n.strings = a.Strings + + // TODO: these need to be rethought + n.X = a.X + n.Y = a.Y + n.W = a.W + n.H = a.H + n.AtW = a.AtW + n.AtH = a.AtH + + // store the internal toolkit information + n.tk = initWidget(n) + // n.tk = new(guiWidget) + + if (a.WidgetType == widget.Root) { + log.Log(INFO, "addNode() Root") + return n + } + + if (me.rootNode.findWidgetId(a.WidgetId) != nil) { + log.Log(ERROR, "addNode() WidgetId already exists", a.WidgetId) + return me.rootNode.findWidgetId(a.WidgetId) + } + + // add this new widget on the binary tree + n.parent = me.rootNode.findWidgetId(a.ParentId) + if n.parent != nil { + n.parent.children = append(n.parent.children, n) + //w := n.tk + //w.parent = n.parent.tk + //w.parent.children = append(w.parent.children, w) + } + return n +}