1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
package gui
import (
"log"
"os"
"embed"
)
// 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.Debug.Debug = true
// Config.Debug.Node = true
// Config.Debug.Tabs = true
title := "guiBinaryTree"
w := 640
h := 480
// Populates the top of the binary tree
Config.master = addNode(title, w, h)
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("andlabs")) {
initBAD = false
}
}
// andlabs gui plugin failed. fall back to the terminal gui (should be compiled into the binary)
if (initBAD) {
if (LoadToolkit("gocui")) {
initBAD = 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.Debug.Debug) {
log.Println("Starting gui.Main() (using gtk via andlabs/ui)")
}
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()) {
log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)")
// 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.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.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)
}
|