diff --git a/README-goreadme.md b/README-goreadme.md index abf7acd..5d7ec42 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#L219) +### func [StandardExit](/main.go#L149) `func StandardExit()` @@ -171,7 +171,7 @@ This struct can be used with the go-arg package 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#L190) +#### func [New](/main.go#L120) `func New() *Node` @@ -180,7 +180,7 @@ This is due to restrictions by being cross platform some toolkit's on some operating systems don't support more than one Keep things simple. Do the default expected thing whenever possible -### type [Symbol](/plugin.go#L16) +### type [Symbol](/plugin.go#L17) `type Symbol any` diff --git a/grid.go b/grid.go index 3fb1b71..9bcc105 100644 --- a/grid.go +++ b/grid.go @@ -37,7 +37,30 @@ func (n *Node) NewGrid(name string, w int, h int) *Node { newNode.Y = h newNode.NextX = 1 newNode.NextY = 1 + + /* + // fix values here if they are invalid. Index starts at 1 + if (where.NextX < 1) { + where.NextX = 1 + } + if (where.NextY < 1) { + where.NextY = 1 + } + // + a.X = where.NextX + a.Y = where.NextY + */ + newaction(&a, newNode, n) + /* + where.NextY += 1 + if (where.NextY > where.Y) { + where.NextX += 1 + where.NextY = 1 + } + log(logInfo, "Action() END size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY) + */ + return newNode } diff --git a/main.go b/main.go index c6ec163..4017314 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package gui import ( "os" - "embed" "git.wit.org/wit/gui/toolkit" ) @@ -114,75 +113,6 @@ func (n *Node) doUserEvent(a toolkit.Action) { } } -func (n *Node) InitEmbed(resFS embed.FS) *Node { - me.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) - if (plug == nil) { - return n - } - - log(logInfo, "LoadToolkit() sending InitToolkit action to the plugin channel") - var a toolkit.Action - a.ActionType = toolkit.InitToolkit - plug.pluginChan <- a - sleep(.5) // temp hack until chan communication is setup - - // TODO: find a new way to do this that is locking, safe and accurate - me.rootNode.redraw(plug) - log(logInfo, "LoadToolkit() END for name =", name) - return n -} - -func (n *Node) CloseToolkit(name string) bool { - log(logInfo, "CloseToolkit() for name =", name) - for _, plug := range allPlugins { - log(debugGui, "CloseToolkit() found", plug.name) - if (plug.name == name) { - log(debugNow, "CloseToolkit() sending close", name) - var a toolkit.Action - a.ActionType = toolkit.CloseToolkit - plug.pluginChan <- a - sleep(.5) - return true - } - } - return false -} - // There should only be one of these per application // This is due to restrictions by being cross platform // some toolkit's on some operating systems don't support more than one diff --git a/plugin.go b/plugin.go index 8280bb8..85a20aa 100644 --- a/plugin.go +++ b/plugin.go @@ -7,6 +7,7 @@ package gui import ( "os" + "embed" "plugin" "git.wit.org/wit/gui/toolkit" @@ -204,34 +205,14 @@ func initToolkit(name string, filename string) *aplug { // 2023/04/06 Queue() is also being used and channels are being used. memcopy() only func newaction(a *toolkit.Action, n *Node, where *Node) { + // remove this if (n != nil) { a.WidgetId = n.id a.WidgetType = n.WidgetType a.ActionType = a.ActionType } - - // TODO: redo this grid logic if (where != nil) { - log(logInfo, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY) a.ParentId = where.id - switch where.WidgetType { - case toolkit.Grid: - // where.Dump(true) - log(logInfo, "Action() START on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY) - // - // fix values here if they are invalid. Index starts at 1 - if (where.NextX < 1) { - where.NextX = 1 - } - if (where.NextY < 1) { - where.NextY = 1 - } - // - a.X = where.NextX - a.Y = where.NextY - log(logInfo, "Action() END on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY) - default: - } } for _, aplug := range allPlugins { @@ -245,18 +226,73 @@ func newaction(a *toolkit.Action, n *Node, where *Node) { aplug.pluginChan <- *a sleep(.02) } - // increment where to put the next widget in a grid or table - if (where != nil) { - switch where.WidgetType { - case toolkit.Grid: - log(logInfo, "Action() START size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY) - where.NextY += 1 - if (where.NextY > where.Y) { - where.NextX += 1 - where.NextY = 1 - } - log(logInfo, "Action() END size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY) - default: +} + +func (n *Node) InitEmbed(resFS embed.FS) *Node { + me.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) + if (plug == nil) { + return n + } + + log(logInfo, "LoadToolkit() sending InitToolkit action to the plugin channel") + var a toolkit.Action + a.ActionType = toolkit.InitToolkit + plug.pluginChan <- a + sleep(.5) // temp hack until chan communication is setup + + // TODO: find a new way to do this that is locking, safe and accurate + me.rootNode.redraw(plug) + log(logInfo, "LoadToolkit() END for name =", name) + return n +} + +func (n *Node) CloseToolkit(name string) bool { + log(logInfo, "CloseToolkit() for name =", name) + for _, plug := range allPlugins { + log(debugGui, "CloseToolkit() found", plug.name) + if (plug.name == name) { + log(debugNow, "CloseToolkit() sending close", name) + var a toolkit.Action + a.ActionType = toolkit.CloseToolkit + plug.pluginChan <- a + sleep(.5) + return true + } + } + return false }