NODE: make node entries for the buttons

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-31 04:06:46 -05:00
parent 741361c000
commit d57f74ff45
2 changed files with 18 additions and 69 deletions

View File

@ -4,10 +4,10 @@ import "log"
import "git.wit.org/wit/gui"
/*
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
*/
func demoClick (n *gui.Node) {
log.Println("demoClick() Dumping node:")
n.Dump()
}
func addDemoTab(n *gui.Node, title string) {
newNode := n.AddTab(title, nil)
@ -21,70 +21,13 @@ func addDemoTab(n *gui.Node, title string) {
groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff")
groupNode1.Dump()
/*
b := groupNode1.FindBox()
b.Dump()
*/
// n1, b1 := addButton(groupNode1, "Data.ListChildren(false)")
/*
b1.OnClicked(func(*ui.Button) {
gui.Data.ListChildren(false)
})
*/
//n2, b2 := addButton(groupNode1, "dumpBox(window)")
newNode2 := groupNode1.AppendButton("foo 3 " + "AppendButton()", func(groupNode1 *gui.Node) {
log.Println("Dumping groupNode1")
groupNode1.Dump()
})
newNode2.Dump()
/*
b2.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("names[x] =", names[x])
x.Dump(names[x])
})
n2.Dump()
*/
butNode1 := groupNode1.AddButton("button1", demoClick)
butNode1.Dump()
butNode2 := groupNode1.AddButton("button2", demoClick)
butNode2.Dump()
groupNode2 := newNode.AddGroup("group 2")
groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3")
}
/*
func addButton(n *gui.Node, name string) (*gui.Node, *ui.Button) {
// val := &myButtonInfo{}
button := ui.NewButton(name)
// val.uiC = button
button.OnClicked(func(*ui.Button) {
log.Println("Should do something here")
})
// n.Append(button, false)
newNode := n.AppendButton(name + "AppendButton", func() {
log.Println("Should do something here also")
})
return newNode, button
}
*/
/*
type myButtonInfo struct {
Custom func (*gui.GuiButton)
ADD func (*gui.GuiButton)
Name string
Action string
Node *gui.Node
}
func newMakeButton(n *gui.Node, name string, action string, custom func(*gui.GuiButton)) *gui.Node {
val := &myButtonInfo{}
val.Custom = custom
val.Name = name
val.Node = n
// val.Action = action
return n.CreateButton(custom, name, val)
}
*/

View File

@ -50,6 +50,7 @@ type Node struct {
window *GuiWindow
box *GuiBox
custom func(*Node)
uiControl *ui.Control
uiButton *ui.Button
@ -123,7 +124,7 @@ func (n *Node) Append(child *Node) {
// time.Sleep(3 * time.Second)
}
func (n *Node) AppendButton(name string, custom func(*Node)) *Node {
func (n *Node) AddButton(name string, custom func(*Node)) *Node {
if (n.uiBox == nil) {
log.Println("gui.Node.AppendButton() filed node.UiBox == nil")
return n
@ -133,13 +134,18 @@ func (n *Node) AppendButton(name string, custom func(*Node)) *Node {
log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button))
n.uiBox.Append(button, false)
n.uiButton = button
newNode := n.makeNode(name, 888, 888 + Config.counter)
newNode.uiButton = button
newNode.custom = custom
button.OnClicked(func(*ui.Button) {
log.Println("gui.AppendButton() Button Clicked. Running custom()")
custom(n)
custom(newNode)
})
// panic("AppendButton")
// time.Sleep(3 * time.Second)
return n
return newNode
}
func (n *Node) List() {