summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--action.go35
-rw-r--r--main.go25
-rw-r--r--structs.go6
-rw-r--r--tree.go24
-rw-r--r--treeInit.go72
6 files changed, 122 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index f095df2..1100359 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,11 @@ BUILDTIME = $(shell date +%Y.%m.%d)
all: goimports plugin
#ldd pixelgl.so
+deps:
+ sudo apt install libxxf86vm-dev libxxf86vm1
+
plugin:
- GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
+ LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/ GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
install:
rm -f pixelgo.so
diff --git a/action.go b/action.go
index a4e5ee6..0bf52c7 100644
--- a/action.go
+++ b/action.go
@@ -7,12 +7,13 @@ package main
*/
import (
+ "go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
-func Add(n *tree.Node) {
+func newAdd(n *tree.Node) {
log.Log(INFO, "Add() END =", n.WidgetType, n.String())
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
@@ -68,15 +69,15 @@ func newaction(n *tree.Node, atype widget.ActionType) {
log.Log(INFO, "newaction() END", atype, n.String())
}
-func SetTitle(n *tree.Node, s string) {
- SetText(n, s)
+func setTitle(n *tree.Node, s string) {
+ setText(n, s)
}
-func SetLabel(n *tree.Node, s string) {
- SetText(n, s)
+func setLabel(n *tree.Node, s string) {
+ setText(n, s)
}
-func SetText(n *tree.Node, s string) {
+func setText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
@@ -90,7 +91,7 @@ func SetText(n *tree.Node, s string) {
log.Info("SetText()", n.WidgetType, n.String())
}
-func AddText(n *tree.Node, s string) {
+func addText(n *tree.Node, s string) {
if n == nil {
log.Warn("Tree Error: Add() sent n == nil")
return
@@ -103,3 +104,23 @@ func AddText(n *tree.Node, s string) {
// w := n.TK.(*guiWidget)
// w.AddText(s)
}
+
+func enableWidget(n *tree.Node) {
+ log.Info("do enable() here")
+}
+
+func disableWidget(n *tree.Node) {
+ log.Info("do enable() here")
+}
+
+func setChecked(n *tree.Node, b bool) {
+ log.Info("do enable() here")
+}
+
+func showTable(n *guipb.Table) {
+ log.Info("do enable() here")
+}
+
+func toolkitClose() {
+ log.Info("do enable() here")
+}
diff --git a/main.go b/main.go
index 27e62cd..c13b9ad 100644
--- a/main.go
+++ b/main.go
@@ -14,7 +14,6 @@ import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/log"
- "go.wit.com/toolkits/tree"
"github.com/faiface/pixel/pixelgl"
// "github.com/gookit/config"
@@ -24,6 +23,8 @@ import (
var VERSION string
var BUILDTIME string
+var PLUGIN string = "pixelgl"
+
//go:embed resources/*
var resources embed.FS
@@ -32,21 +33,23 @@ var pp *arg.Parser
// the glsl file
var glslFile string
-func init() {
+func initPlugin() {
pp = arg.MustParse(&argv)
log.Log(INFO, "Init()")
- me.myTree = tree.New()
- me.myTree.PluginName = "nocui"
- // me.myTree.ActionFromChannel = doAction
+ me.myTree = initTree()
+ /*
+ me.myTree.PluginName = "nocui"
+ // me.myTree.ActionFromChannel = doAction
- me.myTree.NodeAction = newaction
- me.myTree.Add = Add
- me.myTree.SetTitle = SetTitle
- me.myTree.SetLabel = SetLabel
- me.myTree.SetText = SetText
- me.myTree.AddText = AddText
+ me.myTree.NodeAction = newaction
+ me.myTree.Add = Add
+ me.myTree.SetTitle = SetTitle
+ me.myTree.SetLabel = SetLabel
+ me.myTree.SetText = SetText
+ me.myTree.AddText = AddText
+ */
me.exit = false
diff --git a/structs.go b/structs.go
index 5416913..f51cfb8 100644
--- a/structs.go
+++ b/structs.go
@@ -1,6 +1,8 @@
package main
import (
+ "sync"
+
"go.wit.com/toolkits/tree"
)
@@ -13,8 +15,8 @@ type guiWidget struct {
val map[string]int
}
-// It's probably a terrible idea to call this 'me'
-var me toolkitConfig
+var initOnce sync.Once // run initPlugin() only once
+var me toolkitConfig // It's probably a terrible idea to call this 'me'
type toolkitConfig struct {
treeRoot *tree.Node // the base of the binary tree. it should have id == 0
diff --git a/tree.go b/tree.go
deleted file mode 100644
index 57f283a..0000000
--- a/tree.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package main
-
-/*
- This is reference code for toolkit developers
-*/
-
-import (
- "go.wit.com/widget"
-)
-
-// 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) {
- me.myTree.Callback(guiCallback)
-}
-
-func PluginChannel() chan widget.Action {
- return me.myTree.PluginChannel()
-}
diff --git a/treeInit.go b/treeInit.go
new file mode 100644
index 0000000..78ff4fb
--- /dev/null
+++ b/treeInit.go
@@ -0,0 +1,72 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+/*
+ DO NOT EDIT THIS FILE
+
+ this file is the same for every GUI toolkit plugin
+ when you are making a new GUI toolkit plugin for
+ a specific toolkit, you just need to define these
+ functions.
+
+ for example, in the "gocui" toolkit, the functions
+ below are what triggers the "gocui" GO package
+ to draw labels, buttons, windows, etc
+
+ If you are starting out trying to make a new GUI toolkit,
+ all you have to do is copy this file over. Then
+ work on making these functions. addWidget(), setText(), etc.
+
+ That's it!
+*/
+
+package main
+
+/*
+ This is reference code for toolkit developers
+
+ This is how information is passed in GO back to the application
+ via the GO 'plugin' concept
+
+ TODO: switch this to protocol buffers
+*/
+
+import (
+ "go.wit.com/toolkits/tree"
+ "go.wit.com/widget"
+)
+
+// 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) {
+ me.myTree.Callback(guiCallback)
+}
+
+func PluginChannel() chan widget.Action {
+ initOnce.Do(initPlugin)
+ return me.myTree.PluginChannel()
+}
+
+func initTree() *tree.TreeInfo {
+ t := tree.New()
+ t.PluginName = PLUGIN
+ t.Add = newAdd
+ t.SetTitle = setTitle
+ t.SetLabel = setLabel
+ t.SetText = setText
+ t.AddText = addText
+
+ t.Enable = enableWidget
+ t.Disable = disableWidget
+
+ t.SetChecked = setChecked
+ t.ToolkitClose = toolkitClose
+ t.ShowTable = showTable
+
+ return t
+}