2024-01-18 00:05:54 -06:00
|
|
|
package tree
|
|
|
|
|
|
|
|
/*
|
|
|
|
These code should be common to all gui plugins
|
|
|
|
|
|
|
|
There are some helper functions that are probably going to be
|
|
|
|
the same everywhere. Mostly due to handling the binary tree structure
|
|
|
|
and the channel communication
|
|
|
|
|
|
|
|
For now, it's just a symlink to the 'master' version in
|
|
|
|
./toolkit/nocui/common.go
|
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
2024-01-18 04:08:11 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:05:54 -06:00
|
|
|
)
|
|
|
|
|
2024-02-09 10:26:42 -06:00
|
|
|
// searches the binary tree for a WidgetId
|
|
|
|
func FindWidgetId(id int) *Node {
|
|
|
|
return treeRoot.FindWidgetId(id)
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:05:54 -06:00
|
|
|
// searches the binary tree for a WidgetId
|
|
|
|
func (n *Node) FindWidgetId(id int) *Node {
|
2024-01-18 04:08:11 -06:00
|
|
|
if n == nil {
|
2024-01-18 00:05:54 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if n.WidgetId == id {
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range n.children {
|
|
|
|
newN := child.FindWidgetId(id)
|
2024-01-18 04:08:11 -06:00
|
|
|
if newN != nil {
|
2024-01-18 00:05:54 -06:00
|
|
|
return newN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other goroutines must use this to access the GUI
|
|
|
|
//
|
|
|
|
// You can not acess / process the GUI thread directly from
|
|
|
|
// other goroutines. This is due to the nature of how
|
|
|
|
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
|
|
|
|
//
|
|
|
|
// this sets the channel to send user events back from the plugin
|
|
|
|
func (me *TreeInfo) Callback(guiCallback chan widget.Action) {
|
|
|
|
me.callback = guiCallback
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me *TreeInfo) PluginChannel() chan widget.Action {
|
|
|
|
return me.pluginChan
|
|
|
|
}
|