2019-06-02 15:40:44 -05:00
|
|
|
package gui
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
import "git.wit.org/wit/gui/toolkit"
|
2021-10-31 14:21:36 -05:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func (n *Node) NewButton(name string, custom func()) *Node {
|
|
|
|
newNode := n.New(name, toolkit.Button, custom)
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.Name = name
|
|
|
|
a.Text = name
|
|
|
|
a.ActionType = toolkit.Add
|
|
|
|
a.Callback = callback
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, newNode, n)
|
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
return newNode
|
|
|
|
}
|
2023-03-29 23:03:04 -05:00
|
|
|
|
2023-04-03 10:26:47 -05:00
|
|
|
func callback(i int) bool {
|
|
|
|
log(debugError, "callback() for widget id =", i)
|
|
|
|
n := Config.rootNode.FindId(i)
|
|
|
|
log(debugError, "callback() found node =", n)
|
|
|
|
// running custom here means the button get's clicked twice
|
|
|
|
if (n.Custom == nil) {
|
|
|
|
log(debugError, "callback() = nil. SKIPPING")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
n.Custom()
|
|
|
|
return true
|
2023-03-29 23:03:04 -05:00
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
|
|
|
|
// find widget by number
|
|
|
|
func (n *Node) FindId(i int) (*Node) {
|
|
|
|
if (n == nil) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n.id == i) {
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range n.children {
|
|
|
|
newN := child.FindId(i)
|
|
|
|
if (newN != nil) {
|
|
|
|
return newN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|