TEXT: fix OnChanged() handling

This commit is contained in:
Jeff Carr 2021-10-31 15:46:31 -05:00
parent f7ead697d3
commit e7bcb14d6c
3 changed files with 20 additions and 5 deletions

18
box.go
View File

@ -187,12 +187,16 @@ func VerticalBreak(box *GuiBox) {
}
func (n *Node) AddComboBox(title string, s ...string) *Node {
newNode := n.AddNode(title)
box := n.uiBox
if (box == nil) {
return n
}
ecbox := ui.NewEditableCombobox()
newNode.uiText = ecbox
// newNode.Dump()
// log.Println("ecbox", ecbox)
for id, name := range s {
log.Println("Adding Combobox Entry:", id, name)
@ -201,19 +205,27 @@ func (n *Node) AddComboBox(title string, s ...string) *Node {
ecbox.OnChanged(func(*ui.EditableCombobox) {
test := ecbox.Text()
log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'")
log.Println("node.Name = '" + newNode.Name + "' text for '" + title + "' is now: '" + test + "'")
if (newNode.OnChanged == nil) {
log.Println("Not doing custom OnChanged since OnChanged == nil")
newNode.Dump()
} else {
newNode.OnChanged()
}
})
box.Append(ecbox, false)
newNode := n.AddNode(title)
newNode.uiText = ecbox
// newNode.Dump()
// panic("junk")
return newNode
}
/*
func (n *Node) OnChanged(f func()) {
f()
}
*/
func (n *Node) GetText() string {
if (n.uiText == nil) {

View File

@ -33,9 +33,9 @@ func addDemoTab(n *gui.Node, title string) {
groupNode1 := newNode.AddGroup("group 1")
cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo")
cbNode.OnChanged(func () {
cbNode.OnChanged = func () {
username = cbNode.GetText()
})
}
groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff")
groupNode1.Dump()

View File

@ -44,6 +44,7 @@ type Node struct {
Name string
Width int
Height int
OnChanged func ()
parent *Node
children []*Node
@ -73,6 +74,7 @@ func (n *Node) Dump() {
log.Println("gui.Node.Dump() Name = ", n.Name)
log.Println("gui.Node.Dump() Width = ", n.Width)
log.Println("gui.Node.Dump() Height = ", n.Height)
log.Println("gui.Node.Dump() OnChanged = ", n.OnChanged)
if (n.parent == nil) {
log.Println("gui.Node.Dump() parent = nil")
@ -89,6 +91,7 @@ func (n *Node) Dump() {
log.Println("gui.Node.Dump() uiBox = ", n.uiBox)
log.Println("gui.Node.Dump() uiControl = ", n.uiControl)
log.Println("gui.Node.Dump() uiButton = ", n.uiButton)
log.Println("gui.Node.Dump() uiText = ", n.uiText)
if (n.id == "") {
panic("gui.Node.Dump() id == nil")
}