From e7bcb14d6ccb8dca8daedd7989e8479dabc124b3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 15:46:31 -0500 Subject: [PATCH] TEXT: fix OnChanged() handling --- box.go | 18 +++++++++++++++--- cmds/gui-example/demo-window.go | 4 ++-- new-structs.go | 3 +++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/box.go b/box.go index 7a61f55..cf215d7 100644 --- a/box.go +++ b/box.go @@ -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) { diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go index 993900d..f01c1a9 100644 --- a/cmds/gui-example/demo-window.go +++ b/cmds/gui-example/demo-window.go @@ -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() diff --git a/new-structs.go b/new-structs.go index 4f9989e..b75fe0b 100644 --- a/new-structs.go +++ b/new-structs.go @@ -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") }