diff options
| author | Jeff Carr <[email protected]> | 2024-01-16 12:55:20 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-16 12:55:20 -0600 |
| commit | ba95c13799740b5f55541fc5e8ab9f1d34f7e421 (patch) | |
| tree | 1e04c62ea4ac6a133978e14c4d33babe46f8fe1e /common | |
| parent | 29c39d7a1cbc1f071fa819e589fa6ed93fcb7d80 (diff) | |
use widget.GetString()
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'common')
| -rw-r--r-- | common/addNode.go | 68 | ||||
| -rw-r--r-- | common/plugin.go | 69 | ||||
| -rw-r--r-- | common/structs.go | 43 |
3 files changed, 180 insertions, 0 deletions
diff --git a/common/addNode.go b/common/addNode.go new file mode 100644 index 0000000..be769fc --- /dev/null +++ b/common/addNode.go @@ -0,0 +1,68 @@ +package main + +/* + 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 ( + "reflect" + "strconv" + + "go.wit.com/log" + "go.wit.com/gui/widget" +) + +// this is in common.go, do not move it +func addNode(a *widget.Action) *node { + n := new(node) + n.WidgetType = a.WidgetType + n.WidgetId = a.WidgetId + n.ParentId = a.ParentId + + n.state = a.State + + // copy the data from the action message + n.progname = a.ProgName + n.value = a.Value + n.direction = a.Direction + n.strings = a.Strings + + // TODO: these need to be rethought + n.X = a.X + n.Y = a.Y + n.W = a.W + n.H = a.H + n.AtW = a.AtW + n.AtH = a.AtH + + // store the internal toolkit information + n.tk = initWidget(n) + // n.tk = new(guiWidget) + + if (a.WidgetType == widget.Root) { + log.Log(INFO, "addNode() Root") + return n + } + + if (me.rootNode.findWidgetId(a.WidgetId) != nil) { + log.Log(ERROR, "addNode() WidgetId already exists", a.WidgetId) + return me.rootNode.findWidgetId(a.WidgetId) + } + + // add this new widget on the binary tree + n.parent = me.rootNode.findWidgetId(a.ParentId) + if n.parent != nil { + n.parent.children = append(n.parent.children, n) + //w := n.tk + //w.parent = n.parent.tk + //w.parent.children = append(w.parent.children, w) + } + return n +} diff --git a/common/plugin.go b/common/plugin.go new file mode 100644 index 0000000..bfc9a68 --- /dev/null +++ b/common/plugin.go @@ -0,0 +1,69 @@ +package main + +/* + 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 ( + "reflect" + "strconv" + + "go.wit.com/log" + "go.wit.com/gui/widget" +) + +// searches the binary tree for a WidgetId +func (n *node) findWidgetId(id int) *node { + if (n == nil) { + return nil + } + + if n.WidgetId == id { + return n + } + + for _, child := range n.children { + newN := child.findWidgetId(id) + if (newN != nil) { + return newN + } + } + return nil +} + +func (n *node) doUserEvent() { + if (callback == nil) { + log.Log(ERROR, "doUserEvent() callback == nil", n.WidgetId) + return + } + var a widget.Action + a.WidgetId = n.WidgetId + a.Value = n.value + a.ActionType = widget.User + log.Log(INFO, "doUserEvent() START: send a user event to the callback channel") + callback <- a + log.Log(INFO, "doUserEvent() END: sent a user event to the callback channel") + return +} + +// 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 Callback(guiCallback chan widget.Action) { + callback = guiCallback +} + +func PluginChannel() chan widget.Action { + return pluginChan +} diff --git a/common/structs.go b/common/structs.go new file mode 100644 index 0000000..32eed8a --- /dev/null +++ b/common/structs.go @@ -0,0 +1,43 @@ +package main + +/* + 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 ( + "reflect" + "strconv" + + "go.wit.com/log" + "go.wit.com/gui/widget" +) + +// this is the channel we send user events like +// mouse clicks or keyboard events back to the program +var callback chan widget.Action + +// this is the channel we get requests to make widgets +var pluginChan chan widget.Action + +type Node struct { + parent *node + children []*node + + WidgetId int // widget ID + WidgetType widget.WidgetType + ParentId int // parent ID + + State widget.State + + // the internal plugin toolkit structure + // in the gtk plugin, it has gtk things like margin & border settings + // in the text console one, it has text console things like colors for menus & buttons + TK any +} |
