diff --git a/README-goreadme.md b/README-goreadme.md index 5211057..e99ca1b 100644 --- a/README-goreadme.md +++ b/README-goreadme.md @@ -139,7 +139,7 @@ Creates a window helpful for debugging this package `func ShowDebugValues()` -### func [StandardExit](/main.go#L197) +### func [StandardExit](/main.go#L231) `func StandardExit()` @@ -157,13 +157,13 @@ This goroutine can be used like a watchdog timer ## Types -### type [GuiArgs](/structs.go#L26) +### type [GuiArgs](/structs.go#L27) `type GuiArgs struct { ... }` This struct can be used with the go-arg package -### type [GuiConfig](/structs.go#L32) +### type [GuiConfig](/structs.go#L33) `type GuiConfig struct { ... }` @@ -173,14 +173,14 @@ This struct can be used with the go-arg package var Config GuiConfig ``` -### type [Node](/structs.go#L59) +### type [Node](/structs.go#L63) `type Node struct { ... }` The Node is a binary tree. This is how all GUI elements are stored simply the name and the size of whatever GUI element exists -#### func [New](/main.go#L168) +#### func [New](/main.go#L202) `func New() *Node` diff --git a/debugWindow.go b/debugWindow.go index 01273c8..0c27a3f 100644 --- a/debugWindow.go +++ b/debugWindow.go @@ -64,6 +64,10 @@ func (n *Node) DebugTab(title string) *Node { //////////////////////// window debugging things ////////////////////////////////// g1 = newN.NewGroup("list things") + g1.NewButton("List toolkits", func () { + dropdownWindow(g1) + Config.rootNode.ListToolkits() + }) g1.NewButton("List Windows", func () { dropdownWindow(g1) }) diff --git a/image.go b/image.go index e159168..c764eff 100644 --- a/image.go +++ b/image.go @@ -10,9 +10,6 @@ func (n *Node) NewImage(name string) *Node { var a toolkit.Action a.ActionType = toolkit.Add - // a.Widget = &newNode.widget - // a.Where = &n.widget - // action(&a) newaction(&a, newNode, n) return newNode diff --git a/main.go b/main.go index 21904ab..5d05974 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ package gui import ( "os" - // "embed" // reminder to not attempt this within the 'wit/gui' package + "embed" "git.wit.org/wit/gui/toolkit" ) @@ -126,6 +126,40 @@ func (n *Node) doUserEvent(a toolkit.Action) { } } +func (n *Node) InitEmbed(resFS embed.FS) *Node { + Config.resFS = resFS + return n +} + +func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node { + for _, aplug := range allPlugins { + log(logInfo, "LoadToolkitEmbed() already loaded toolkit plugin =", aplug.name) + if (aplug.name == name) { + log(logError, "LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice") + return n + } + } + + f, err := os.CreateTemp("", "sample." + name + ".so") + if (err != nil) { + return n + } + defer os.Remove(f.Name()) + f.Write(b) + + p := initToolkit(name, f.Name()) + if (p == nil) { + log(logError, "LoadToolkitEmbed() embedded go file failed", name) + } + return n +} + +func (n *Node) ListToolkits() { + for _, aplug := range allPlugins { + log(logNow, "ListToolkits() already loaded toolkit plugin =", aplug.name) + } +} + func (n *Node) LoadToolkit(name string) *Node { log(logInfo, "LoadToolkit() START for name =", name) plug := initPlugin(name) diff --git a/plugin.go b/plugin.go index 556bc9e..6894b96 100644 --- a/plugin.go +++ b/plugin.go @@ -118,7 +118,7 @@ func searchPaths(name string) *aplug { // attempt to write out the file from the internal resource filename = "toolkit/" + name + ".so" - p := tryfile(name, filename) + p := initToolkit(name, filename) if (p != nil) { return p } @@ -128,20 +128,20 @@ func searchPaths(name string) *aplug { log(logError, "searchPaths() error. exiting here?") } else { filename = homeDir + "/go/src/git.wit.org/wit/gui/toolkit/" + name + ".so" - p = tryfile(name, filename) + p = initToolkit(name, filename) if (p != nil) { return p } } filename = "/usr/lib/go-gui/" + name + ".so" - p = tryfile(name, filename) + p = initToolkit(name, filename) if (p != nil) { return p } filename = "/usr/local/lib/" + name + ".so" - p = tryfile(name, filename) + p = initToolkit(name, filename) if (p != nil) { return p } @@ -150,13 +150,13 @@ func searchPaths(name string) *aplug { // load module // 1. open the shared object file to load the symbols -func tryfile(name string, filename string) *aplug { +func initToolkit(name string, filename string) *aplug { plug, err := plugin.Open(filename) if err != nil { log(debugGui, "plugin FAILED =", filename, err) return nil } - log(debugGui, "tryfile() loading plugin =", filename) + log(debugGui, "initToolkit() loading plugin =", filename) var newPlug *aplug newPlug = new(aplug) @@ -180,13 +180,13 @@ func tryfile(name string, filename string) *aplug { // set the communication to the plugins newPlug.pluginChan = newPlug.PluginChannel() if (newPlug.pluginChan == nil) { - log(debugError, "tryfile() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename) + log(debugError, "initToolkit() ERROR PluginChannel() returned nil for plugin:", newPlug.name, filename) return nil } newPlug.Callback(Config.guiChan) newPlug.InitOk = true - log(debugPlugin, "tryfile() END", newPlug.name, filename) + log(debugPlugin, "initToolkit() END", newPlug.name, filename) return newPlug } diff --git a/structs.go b/structs.go index 4697dde..491a99d 100644 --- a/structs.go +++ b/structs.go @@ -1,8 +1,9 @@ package gui import ( - "git.wit.org/wit/gui/toolkit" "sync" + "embed" + "git.wit.org/wit/gui/toolkit" ) // @@ -52,6 +53,9 @@ type GuiConfig struct { // sets the chan for the plugins to call back too guiChan chan toolkit.Action + + // option to pass in compiled plugins as embedded files + resFS embed.FS } // The Node is a binary tree. This is how all GUI elements are stored diff --git a/toolkit/nocui/event.go b/toolkit/nocui/event.go index ab2723f..73b7ff2 100644 --- a/toolkit/nocui/event.go +++ b/toolkit/nocui/event.go @@ -16,6 +16,7 @@ func (n *node) doWidgetClick() { // rootNode.dumpTree(true) case toolkit.Window: // setCurrentWindow(w) + n.doUserEvent() case toolkit.Tab: // setCurrentTab(w) case toolkit.Group: diff --git a/toolkit/nocui/stdin.go b/toolkit/nocui/stdin.go index ed71206..86ec664 100644 --- a/toolkit/nocui/stdin.go +++ b/toolkit/nocui/stdin.go @@ -22,12 +22,16 @@ func simpleStdin() { case "b": log(true, "show buttons") rootNode.showButtons() + case "d": + var a toolkit.Action + a.ActionType = toolkit.EnableDebug + callback <- a case "": fmt.Println("") fmt.Println("Enter:") fmt.Println("'l': list all widgets") fmt.Println("'b': for buttons") - fmt.Println("") + fmt.Println("'d': enable debugging") default: i, _ := strconv.Atoi(s) log(true, "got input:", i)