2021-10-06 08:36:28 -05:00
|
|
|
package gui
|
|
|
|
|
2021-10-06 10:43:58 -05:00
|
|
|
import (
|
|
|
|
"log"
|
2022-11-06 12:59:24 -06:00
|
|
|
"os"
|
2022-11-13 08:53:03 -06:00
|
|
|
"embed"
|
2021-10-06 10:43:58 -05:00
|
|
|
)
|
2021-10-06 08:36:28 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// 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"
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
const Xaxis = 0 // stack things horizontally
|
|
|
|
const Yaxis = 1 // stack things vertically
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// may this plugin work when all other plugins fail
|
|
|
|
//go:embed toolkit/gocui.so
|
|
|
|
var res embed.FS
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
func init() {
|
|
|
|
log.Println("gui.init() has been run")
|
|
|
|
|
|
|
|
Config.counter = 0
|
|
|
|
Config.prefix = "wit"
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// Config.Debug.Debug = true
|
|
|
|
// Config.Debug.Node = true
|
|
|
|
// Config.Debug.Tabs = true
|
2022-11-06 12:59:24 -06:00
|
|
|
|
|
|
|
title := "guiBinaryTree"
|
2022-10-20 06:55:42 -05:00
|
|
|
w := 640
|
|
|
|
h := 480
|
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
// Populates the top of the binary tree
|
2022-10-20 06:55:42 -05:00
|
|
|
Config.master = addNode(title, w, h)
|
2022-11-13 08:53:03 -06:00
|
|
|
if (Config.Debug.Debug) {
|
2022-11-06 12:59:24 -06:00
|
|
|
Config.master.Dump()
|
|
|
|
}
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-11-14 14:30:28 -06:00
|
|
|
if (LoadToolkit("andlabs")) {
|
2022-11-13 08:53:03 -06:00
|
|
|
initBAD = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
// andlabs gui plugin failed. fall back to the terminal gui (should be compiled into the binary)
|
2022-11-13 08:53:03 -06:00
|
|
|
if (initBAD) {
|
|
|
|
if (LoadToolkit("gocui")) {
|
|
|
|
initBAD = false
|
|
|
|
}
|
|
|
|
}
|
2022-11-06 19:57:20 -06:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// 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)
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// This should not pass a function
|
2021-10-06 08:36:28 -05:00
|
|
|
func Main(f func()) {
|
2022-11-13 08:53:03 -06:00
|
|
|
if (Config.Debug.Debug) {
|
2022-11-06 19:57:20 -06:00
|
|
|
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
|
|
|
|
}
|
2022-11-13 08:53:03 -06:00
|
|
|
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)
|
2021-10-06 08:36:28 -05:00
|
|
|
}
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// This should never be exposed(?)
|
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
// Other goroutines must use this to access the GUI
|
2021-10-06 08:36:28 -05:00
|
|
|
//
|
|
|
|
// You can not acess / process the GUI thread directly from
|
2021-10-06 10:43:58 -05:00
|
|
|
// other goroutines. This is due to the nature of how
|
2021-10-06 08:36:28 -05:00
|
|
|
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
|
2022-10-20 06:55:42 -05:00
|
|
|
// For example: gui.Queue(NewWindow())
|
2022-11-14 14:30:28 -06:00
|
|
|
func Queue(f func()) {
|
2021-10-06 08:36:28 -05:00
|
|
|
log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)")
|
2022-11-13 08:53:03 -06:00
|
|
|
// toolkit.Queue(f)
|
|
|
|
for _, aplug := range allPlugins {
|
|
|
|
log.Println("gui.Node.NewButton() toolkit plugin =", aplug.name)
|
|
|
|
if (aplug.Queue == nil) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
aplug.Queue(f)
|
|
|
|
}
|
2021-10-06 08:36:28 -05:00
|
|
|
}
|
2022-11-06 12:59:24 -06:00
|
|
|
|
|
|
|
// The window is destroyed but the application does not quit
|
|
|
|
func StandardClose(n *Node) {
|
2022-11-13 08:53:03 -06:00
|
|
|
if (Config.Debug.Debug) {
|
2022-11-06 12:59:24 -06:00
|
|
|
log.Println("wit/gui Standard Window Close. name =", n.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The window is destroyed but the application does not quit
|
|
|
|
func StandardExit(n *Node) {
|
2022-11-13 08:53:03 -06:00
|
|
|
if (Config.Debug.Debug) {
|
2022-11-06 12:59:24 -06:00
|
|
|
log.Println("wit/gui Standard Window Exit. running os.Exit()")
|
|
|
|
}
|
2022-11-13 08:53:03 -06:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
os.Exit(0)
|
|
|
|
}
|