summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/plugin.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-03-01 11:35:36 -0600
committerJeff Carr <[email protected]>2023-03-01 11:35:36 -0600
commit8dbf5a09097b7868e9218bf98716c57eac998a10 (patch)
treeab3bdfeaf5a59a55de9d2a6661d2d824090491e5 /toolkit/andlabs/plugin.go
parentf3bb68396afa7452ecf1c8d4744c825a9d81057c (diff)
lots cleaner code between the pluginv0.6.1
Queue() around SetText is helping userspace crashing merge forceDump(bool) into Dump() debugging output configuration is pretty clean keep cutting down duplicate things --gui-verbose flag works make label "standard" code add debug.FreeOSMemory() move the GO language internals to display in the GUI update push to do tags and go to github.com/wit-go/ remove the other license file it might be confusing golang.org and github proper WidgetType added a Quit() button Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/andlabs/plugin.go')
-rw-r--r--toolkit/andlabs/plugin.go129
1 files changed, 92 insertions, 37 deletions
diff --git a/toolkit/andlabs/plugin.go b/toolkit/andlabs/plugin.go
index 5165178..5bc40a0 100644
--- a/toolkit/andlabs/plugin.go
+++ b/toolkit/andlabs/plugin.go
@@ -1,49 +1,104 @@
package main
-import (
- "git.wit.org/wit/gui/toolkit"
-)
+// if you include more than just this import
+// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
+import "git.wit.org/wit/gui/toolkit"
-// This is a map between the widgets in wit/gui and the internal structures of gocui
+// import "github.com/andlabs/ui"
+// import _ "github.com/andlabs/ui/winmanifest"
-var mapWidgets map[*andlabsT]*toolkit.Widget
-var mapToolkits map[*toolkit.Widget]*andlabsT
-
-// This lists out the know mappings
-func listMap() {
- log(debugToolkit, "listMap() HERE")
- log(debugToolkit, "listMap() HERE")
- log(debugToolkit, "listMap() HERE mapWidgets()")
- for t, w := range mapWidgets {
- log(debugToolkit, "andlabs =", t.Name, "widget =", w.Name)
+//
+// This should be called ?
+// Pass() ?
+// This handles all interaction between the wit/gui package (what golang knows about)
+// and this plugin that talks to the OS and does scary and crazy things to make
+// a GUI on whatever OS or whatever GUI toolkit you might have (GTK, QT, WASM, libcurses)
+//
+// Once you are here, you should be in a protected goroutine created by the golang wit/gui package
+//
+// TODO: make sure you can't escape this goroutine
+//
+func Send(p *toolkit.Widget, c *toolkit.Widget) {
+ if (p == nil) {
+ log(debugPlugin, "Send() parent = nil")
+ } else {
+ log(debugPlugin, "Send() parent =", p.Name, ",", p.Type)
}
- log(debugToolkit, "listMap() HERE mapToolkits()")
- for w, t := range mapToolkits {
- log(debugToolkit, "andlabs =", t, "widget =", w.Name)
- forceDump(t)
+ log(debugPlugin, "Send() child =", c.Name, ",", c.Action, ",", c.Type)
+
+ switch c.Type {
+ case toolkit.Window:
+ newWindow(c)
+ case toolkit.Tab:
+ newTab(p, c)
+ case toolkit.Group:
+ newGroup(p, c)
+ case toolkit.Button:
+ doButton(p, c)
+ case toolkit.Checkbox:
+ doCheckbox(p, c)
+ case toolkit.Label:
+ newLabel(p, c)
+ case toolkit.Textbox:
+ doTextbox(p, c)
+ case toolkit.Slider:
+ newSlider(p, c)
+ case toolkit.Spinner:
+ newSpinner(p, c)
+ default:
+ log(true, "unknown parent =", p.Name, p.Type)
+ log(true, "unknown child =", c.Name, c.Type)
+ log(true, "Don't know how to do", c.Type, "yet")
}
}
-func mapWidgetsToolkits(w *toolkit.Widget, t *andlabsT) {
- if (mapToolkits[w] == nil) {
- mapToolkits[w] = t
- } else {
- log(debugToolkit, "WTF: mapToolkits was sent nil. this should not happen w =", w)
- log(debugToolkit, "WTF: mapToolkits was sent nil. this should not happen t =", t.Width)
- log(debugToolkit, "WTF: mapToolkits map already set to ", mapToolkits[w])
- panic("WTF mapWidgetsToolkits() w == nil")
+// delete the child widget from the parent
+// p = parent, c = child
+func destroy(p *toolkit.Widget, c *toolkit.Widget) {
+ log(true, "delete()", c.Name, c.Type)
+
+ pt := mapToolkits[p]
+ ct := mapToolkits[c]
+ if (ct == nil) {
+ log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", c.Name, c.Type)
+ // this pukes out a whole universe of shit
+ // listMap()
+ return
}
- if (mapWidgets[t] == nil) {
- mapWidgets[t] = w
- } else {
- log(debugToolkit, "WTF: mapWidgets already installed. w =", w)
- log(debugToolkit, "WTF: mapWidgets already installed. t =", t.Width, t)
- log(SPEW, &t)
- log(SPEW, t)
- log(SPEW, *t)
- log(debugToolkit, "WTF: mapWidgets already mapped to", mapWidgets[t])
- log(SPEW, mapWidgets[t])
- panic("WTF. mapWidget andlabs toolkit already mapped to gui toolkit")
+ switch ct.Type {
+ case toolkit.Button:
+ log(true, "Should delete Button here:", c.Name)
+ log(true, "Parent:")
+ pt.Dump(true)
+ log(true, "Child:")
+ ct.Dump(true)
+ if (pt.uiBox == nil) {
+ log(true, "Don't know how to destroy this")
+ } else {
+ log(true, "Fuck it, destroy the whole box", pt.Name)
+ // pt.uiBox.Destroy() // You have a bug: You cannot destroy a uiControl while it still has a parent.
+ pt.uiBox.SetPadded(false)
+ pt.uiBox.Delete(4)
+ ct.uiButton.Disable()
+ // ct.uiButton.Hide()
+ ct.uiButton.Destroy()
+ }
+
+ case toolkit.Window:
+ log(true, "Should delete Window here:", c.Name)
+ default:
+ log(true, "Don't know how to delete c =", c.Type, c.Name)
+ log(true, "Don't know how to delete pt =", pt.Type, pt.Name, pt.uiButton)
+ log(true, "Don't know how to delete ct =", ct.Type, ct.Name, ct.uiButton)
+ log(true, "Parent:")
+ pt.Dump(true)
+ log(true, "Child:")
+ ct.Dump(true)
+ log(true, "Fuckit, let's destroy a button", c.Name, c.Type)
+ if (ct.uiButton != nil) {
+ pt.uiBox.Delete(4)
+ ct.uiButton.Destroy()
+ }
}
}