summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go109
1 files changed, 94 insertions, 15 deletions
diff --git a/main.go b/main.go
index 21cbd02..ae22dc6 100644
--- a/main.go
+++ b/main.go
@@ -3,22 +3,29 @@ package gui
import (
"log"
"os"
+ "embed"
)
-import toolkit "git.wit.org/wit/gui/toolkit/andlabs"
+// Windows doesn't support plugins. How can I keep andlabs and only compile it on windows?
+// https://forum.heroiclabs.com/t/setting-up-goland-to-compile-plugins-on-windows/594/5
+// import toolkit "git.wit.org/wit/gui/toolkit/andlabs"
const Xaxis = 0 // stack things horizontally
const Yaxis = 1 // stack things vertically
+// may this plugin work when all other plugins fail
+//go:embed toolkit/gocui.so
+var res embed.FS
+
func init() {
log.Println("gui.init() has been run")
Config.counter = 0
Config.prefix = "wit"
- // Config.Options.Debug = true
- // Config.Options.DebugNode = true
- // Config.Options.DebugTabs = true
+ // Config.Debug.Debug = true
+ // Config.Debug.Node = true
+ // Config.Debug.Tabs = true
title := "guiBinaryTree"
w := 640
@@ -26,45 +33,117 @@ func init() {
// Populates the top of the binary tree
Config.master = addNode(title, w, h)
- if (Config.Options.Debug) {
+ if (Config.Debug.Debug) {
Config.master.Dump()
}
+}
+
+func Init() {
+ var initBAD bool = true
+
+ if (Config.Debug.Debug) {
+ log.Println("Starting gui.Init()")
+ }
+ for _, aplug := range allPlugins {
+ log.Println("gui.LoadToolkit() already loaded toolkit plugin =", aplug.name)
+ initBAD = false
+ }
+
+ // the program didn't specify a plugin. Try to load one
+ // TODO: detect the OS & user preferences to load the best one
+ if (initBAD) {
+ if (LoadToolkit("andlabs2")) {
+ initBAD = false
+ }
+ }
+
+ // andlabs2 gui failed. fall back to the terminal gui (should be compiled into the binary)
+ if (initBAD) {
+ if (LoadToolkit("gocui")) {
+ initBAD = false
+ }
+ }
- // load the gocui plugin
- PlugGocli = LoadPlugin("../../toolkit/gocui.so")
- PlugGocliOk = false
+ // locate the shared library file
+ // panic("WTF Init()")
+ for _, aplug := range allPlugins {
+ log.Println("gui.Node.Init() toolkit plugin =", aplug.name)
+ if (aplug.InitOk) {
+ log.Println("gui.Node.Init() Already Ran Init()", aplug.name)
+ continue
+ }
+ if (aplug.Init == nil) {
+ log.Println("gui.Node.Main() Init == nil", aplug.name)
+ continue
+ }
+ aplug.InitOk = true
+ aplug.Init()
+ }
+ // StandardExit(nil)
}
+// This should not pass a function
func Main(f func()) {
- if (Config.Options.Debug) {
+ if (Config.Debug.Debug) {
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
}
- toolkit.Main(f)
+ for _, aplug := range allPlugins {
+ log.Println("gui.Node.NewButton() toolkit plugin =", aplug.name)
+ if (aplug.MainOk) {
+ log.Println("gui.Node.Main() Already Ran Main()", aplug.name)
+ continue
+ }
+ if (aplug.Main == nil) {
+ log.Println("gui.Node.Main() Main == nil", aplug.name)
+ continue
+ }
+ aplug.MainOk = true
+ aplug.Main(f)
+ // f()
+ }
+ // toolkit.Main(f)
}
+// This should never be exposed(?)
+
// 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.)
// For example: gui.Queue(NewWindow())
-func Queue(f func()) {
+func queue(f func()) {
log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)")
- toolkit.Queue(f)
+ // toolkit.Queue(f)
+ for _, aplug := range allPlugins {
+ log.Println("gui.Node.NewButton() toolkit plugin =", aplug.name)
+ if (aplug.Queue == nil) {
+ continue
+ }
+ aplug.Queue(f)
+ }
}
// The window is destroyed but the application does not quit
func StandardClose(n *Node) {
- if (Config.Options.Debug) {
+ if (Config.Debug.Debug) {
log.Println("wit/gui Standard Window Close. name =", n.Name)
}
}
-
// The window is destroyed but the application does not quit
func StandardExit(n *Node) {
- if (Config.Options.Debug) {
+ if (Config.Debug.Debug) {
log.Println("wit/gui Standard Window Exit. running os.Exit()")
}
+
+ log.Println("gui.Node.StandardExit() attempt to exit each toolkit plugin")
+ for i, aplug := range allPlugins {
+ log.Println("gui.Node.NewButton()", i, aplug)
+ if (aplug.Quit != nil) {
+ aplug.Quit()
+ }
+ }
+
os.Exit(0)
}