hidden widgets

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-13 21:28:41 -06:00
parent 34f33db94a
commit 31dbec2b56
5 changed files with 107 additions and 79 deletions

View File

@ -8,6 +8,12 @@ import (
"go.wit.com/gui/widget" "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) { func (n *node) show(b bool) {
if n.tk == nil { if n.tk == nil {
return return
@ -225,6 +231,7 @@ func rawAction(a *widget.Action) {
case widget.Enable: case widget.Enable:
n.enable(true) n.enable(true)
case widget.Disable: case widget.Disable:
log.Warn("andlabs got disable for", n.WidgetId, n.progname)
n.enable(false) n.enable(false)
case widget.Get: case widget.Get:
n.setText(a) n.setText(a)

View File

@ -16,9 +16,9 @@ func (n *node) addText(a *widget.Action) {
switch n.WidgetType { switch n.WidgetType {
case widget.Dropdown: case widget.Dropdown:
n.AddDropdownName(getString(a.Value)) n.addDropdownName(getString(a.Value))
case widget.Combobox: case widget.Combobox:
t.AddComboboxName(getString(a.Value)) t.addComboboxName(getString(a.Value))
default: default:
log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType) log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType)
} }

View File

@ -5,6 +5,7 @@ import (
_ "github.com/andlabs/ui/winmanifest" _ "github.com/andlabs/ui/winmanifest"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/widget"
) )
func (p *node) newCombobox(n *node) { func (p *node) newCombobox(n *node) {
@ -26,9 +27,17 @@ func (p *node) newCombobox(n *node) {
n.tk = newt n.tk = newt
p.place(n) 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) t.uiEditableCombobox.Append(title)
if (t.val == nil) { if (t.val == nil) {
return return

View File

@ -31,50 +31,57 @@ func (p *node) newDropdown(n *node) {
n.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt
p.place(n) 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) func (n *node) SetDropdownInt(i int) {
if (t.val == nil) { 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") log.Log(INFO, "make map didn't work")
return 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 this is the first menu added, set the dropdown to it
if (t.c == 0) { if (n.tk.c == 0) {
log.Log(INFO, "THIS IS THE FIRST Dropdown", title) log.Log(INFO, "THIS IS THE FIRST Dropdown", s)
t.uiCombobox.SetSelected(0) n.tk.uiCombobox.SetSelected(0)
} }
t.c = t.c + 1 n.tk.c = n.tk.c + 1
} }
func (t *guiWidget) SetDropdown(i int) { func (n *node) setDropdownName(s string) bool {
t.uiCombobox.SetSelected(i) if ! n.ready() { return false}
} log.Log(INFO, "SetDropdownName()", n.WidgetId, ",", s)
func (n *node) AddDropdownName(s string) { for i, tmp := range n.tk.val {
log.Log(INFO, "AddDropdownName()", n.WidgetId, "add:", s) if s == tmp {
n.value = s
t := n.tk n.SetDropdownInt(i)
if (t == nil) { log.Warn("SetDropdownInt() worked", tmp, i)
log.Log(INFO, "AddDropdownName() toolkit struct == nil. name=", n.progname, s) return true
return }
} }
t.addDropdownName(s) log.Warn("SetDropdownName() failed", s)
} return false
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
} }

View File

@ -49,6 +49,8 @@ type node struct {
// values from things like checkboxes & dropdown's // values from things like checkboxes & dropdown's
value any value any
strings []string
// This is used for things like a slider(0,100) // This is used for things like a slider(0,100)
X int X int
Y int Y int
@ -106,50 +108,6 @@ func (n *node) doUserEvent() {
return 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 // Other goroutines must use this to access the GUI
// //
// You can not acess / process the GUI thread directly from // 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 { func getString(A any) string {
if A == nil { if A == nil {
log.Warn("getString() got nil") log.Warn("getString() got nil")
@ -208,3 +167,49 @@ func getString(A any) string {
} }
return "" 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
}