summaryrefslogtreecommitdiff
path: root/toolkit/nocui/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-27 21:11:00 -0500
committerJeff Carr <[email protected]>2023-04-27 21:11:00 -0500
commit87b62c98a6ebd9d0e48850d1710de7f39aba41c8 (patch)
treeb5961b9d4841b20ff41ae95acac4d82459ee9d3f /toolkit/nocui/main.go
parent9e285c7affa3257a46e85acde6dc64a9c781b728 (diff)
nocui: a template for porting new toolkits
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/nocui/main.go')
-rw-r--r--toolkit/nocui/main.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/toolkit/nocui/main.go b/toolkit/nocui/main.go
new file mode 100644
index 0000000..7309782
--- /dev/null
+++ b/toolkit/nocui/main.go
@@ -0,0 +1,58 @@
+package main
+
+import (
+ "sync"
+ "git.wit.org/wit/gui/toolkit"
+)
+
+// this is the channel we get requests to make widgets
+var pluginChan chan toolkit.Action
+
+// the starting point of the binary tree
+var rootNode *node
+
+var muAction sync.Mutex
+
+func catchActionChannel() {
+ log(logNow, "catchActionChannel() START")
+ for {
+ log(logNow, "catchActionChannel() for loop")
+ select {
+ case a := <-pluginChan:
+ log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
+ log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
+ muAction.Lock()
+ action(a)
+ muAction.Unlock()
+ log(logNow, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
+ }
+ }
+}
+
+// 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 toolkit.Action) {
+ callback = guiCallback
+}
+
+func PluginChannel() chan toolkit.Action {
+ return pluginChan
+}
+
+// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
+func init() {
+ log(logNow, "Init() START")
+ log(logInfo, "Init()")
+
+ // andlabs = make(map[int]*andlabsT)
+ pluginChan = make(chan toolkit.Action, 1)
+
+ log(logNow, "Init() start channel reciever")
+ go catchActionChannel()
+ log(logNow, "Init() END")
+}