diff options
| author | Jeff Carr <[email protected]> | 2022-10-19 13:23:22 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2022-10-19 13:23:22 -0500 |
| commit | f3af1f5b7ff78b3f73d7510622fc9633dec36d35 (patch) | |
| tree | e4868584d5e19942938aaa122b2e1cab377db000 /button.go | |
| parent | f7b1036e544238d65b0e3ad46d08075aa4177032 (diff) | |
Refactor to 'gui/toolkit/'
* add a example cmds/consolemouse
uses a console button to launch the andlabs/ui
* fix wrong return value in toolkit/NewLabel()
* redirect STDIN output to a file
* wonderful fix of Window() exit
* finally remove the ancient stupid variables x & y
* phase out struct 'box' and use 'node' instead
* better names for things: use NewFoo() and NewBar()
Diffstat (limited to 'button.go')
| -rw-r--r-- | button.go | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -1,7 +1,7 @@ package gui import "log" -import "reflect" +// import "reflect" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" @@ -53,24 +53,33 @@ func guiButtonClick(button *GuiButton) { } func (n *Node) AddButton(name string, custom func(*Node)) *Node { - if (n.uiBox == nil) { - log.Println("gui.Node.AppendButton() filed node.UiBox == nil") + if (n.Toolkit == nil) { + log.Println("gui.Node.AppendButton() filed node.Toolkit == nil") + panic("gui.Node.AppendButton() filed node.Toolkit == nil") return n } + /* button := ui.NewButton(name) log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) 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 := n.New(name) + newNode.Toolkit = n.Toolkit.NewButton(name) + newNode.Toolkit.Custom = func() { + log.Println("gui.AppendButton() Button Clicked. Running custom()") + custom(newNode) + } newNode.custom = custom + /* button.OnClicked(func(*ui.Button) { log.Println("gui.AppendButton() Button Clicked. Running custom()") custom(newNode) }) + */ // panic("AppendButton") // time.Sleep(3 * time.Second) return newNode @@ -106,6 +115,10 @@ func (n *Node) CreateButton(custom func(*GuiButton), name string, values interfa return newNode } +func (n *Node) NewButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { + return CreateButton(box, custom, name, values) +} + func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { newUiB := ui.NewButton(name) newUiB.OnClicked(defaultButtonClick) |
