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 {
|
2023-04-08 11:06:50 -05:00
|
|
|
newNode := n.newNode(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
|
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-05-09 08:25:10 -05:00
|
|
|
/*
|
2023-04-06 18:26:30 -05:00
|
|
|
// deprecate this once andlabs is refactored
|
2023-04-03 10:26:47 -05:00
|
|
|
func callback(i int) bool {
|
|
|
|
log(debugError, "callback() for widget id =", i)
|
2023-04-28 10:35:57 -05:00
|
|
|
n := me.rootNode.FindId(i)
|
2023-04-03 10:26:47 -05:00
|
|
|
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-05-09 08:25:10 -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
|
|
|
|
}
|
|
|
|
|