diff options
| author | Jeff Carr <[email protected]> | 2024-01-16 12:55:20 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-16 12:55:20 -0600 |
| commit | ba95c13799740b5f55541fc5e8ab9f1d34f7e421 (patch) | |
| tree | 1e04c62ea4ac6a133978e14c4d33babe46f8fe1e | |
| parent | 29c39d7a1cbc1f071fa819e589fa6ed93fcb7d80 (diff) | |
use widget.GetString()
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | andlabs/addText.go | 4 | ||||
| -rw-r--r-- | andlabs/button.go | 4 | ||||
| -rw-r--r-- | andlabs/group.go | 4 | ||||
| -rw-r--r-- | andlabs/label.go | 4 | ||||
| -rw-r--r-- | andlabs/place.go | 2 | ||||
| -rw-r--r-- | andlabs/setText.go | 2 | ||||
| -rw-r--r-- | andlabs/tab.go | 4 | ||||
| -rw-r--r-- | andlabs/window.go | 3 | ||||
| -rw-r--r-- | common/addNode.go | 68 | ||||
| -rw-r--r-- | common/plugin.go | 69 | ||||
| -rw-r--r-- | common/structs.go | 43 | ||||
| -rw-r--r-- | nocui/common.go | 9 |
12 files changed, 203 insertions, 13 deletions
diff --git a/andlabs/addText.go b/andlabs/addText.go index 75c8c7d..cbc9269 100644 --- a/andlabs/addText.go +++ b/andlabs/addText.go @@ -16,9 +16,9 @@ func (n *node) addText(a *widget.Action) { switch n.WidgetType { case widget.Dropdown: - n.addDropdownName(getString(a.Value)) + n.addDropdownName(widget.GetString(a.Value)) case widget.Combobox: - n.addComboboxName(getString(a.Value)) + n.addComboboxName(widget.GetString(a.Value)) default: log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType) } diff --git a/andlabs/button.go b/andlabs/button.go index 81a30c0..0cc4f52 100644 --- a/andlabs/button.go +++ b/andlabs/button.go @@ -1,6 +1,8 @@ package main import ( + "go.wit.com/gui/widget" + "go.wit.com/dev/andlabs/ui" _ "go.wit.com/dev/andlabs/ui/winmanifest" ) @@ -9,7 +11,7 @@ func (p *node) newButton(n *node) { t := p.tk newt := new(guiWidget) - b := ui.NewButton(getString(n.value)) + b := ui.NewButton(widget.GetString(n.value)) newt.uiButton = b newt.uiControl = b newt.parent = t diff --git a/andlabs/group.go b/andlabs/group.go index e67f358..8faa6a4 100644 --- a/andlabs/group.go +++ b/andlabs/group.go @@ -1,6 +1,8 @@ package main import ( + "go.wit.com/gui/widget" + "go.wit.com/dev/andlabs/ui" _ "go.wit.com/dev/andlabs/ui/winmanifest" ) @@ -8,7 +10,7 @@ import ( func (p *node) newGroup(n *node) { newt := new(guiWidget) - g := ui.NewGroup(getString(n.value)) + g := ui.NewGroup(widget.GetString(n.value)) g.SetMargined(true) newt.uiGroup = g newt.uiControl = g diff --git a/andlabs/label.go b/andlabs/label.go index 4c208c6..bcdaf7a 100644 --- a/andlabs/label.go +++ b/andlabs/label.go @@ -1,13 +1,15 @@ package main import ( + "go.wit.com/gui/widget" + "go.wit.com/dev/andlabs/ui" _ "go.wit.com/dev/andlabs/ui/winmanifest" ) func (p *node) newLabel(n *node) { newt := new(guiWidget) - c := ui.NewLabel(getString(n.value)) + c := ui.NewLabel(widget.GetString(n.value)) newt.uiLabel = c newt.uiControl = c diff --git a/andlabs/place.go b/andlabs/place.go index 1d2144c..94a16b2 100644 --- a/andlabs/place.go +++ b/andlabs/place.go @@ -75,7 +75,7 @@ func (p *node) place(n *node) bool { // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.progname, n.Text, n.WidgetType) // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.progname, p.Text, p.WidgetType) // panic("n.tk.uiControl == nil") - p.tk.uiTab.Append(getString(n.value), n.tk.uiControl) + p.tk.uiTab.Append(widget.GetString(n.value), n.tk.uiControl) p.tk.boxC += 1 return true case widget.Box: diff --git a/andlabs/setText.go b/andlabs/setText.go index 88b4df0..77beb5c 100644 --- a/andlabs/setText.go +++ b/andlabs/setText.go @@ -6,7 +6,7 @@ import ( ) func (n *node) setText(a *widget.Action) { - name := getString(a.Value) + name := widget.GetString(a.Value) log.Log(CHANGE, "setText() START with text =", name) t := n.tk diff --git a/andlabs/tab.go b/andlabs/tab.go index 07c5ce9..2bccf5b 100644 --- a/andlabs/tab.go +++ b/andlabs/tab.go @@ -37,7 +37,7 @@ func (p *node) newTab(n *node) { if (t.uiTab == nil) { // this means you have to make a new tab log.Log(TOOLKIT, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId) - newt = rawTab(t.uiWindow, getString(n.value)) + newt = rawTab(t.uiWindow, widget.GetString(n.value)) t.uiTab = newt.uiTab } else { // this means you have to append a tab @@ -49,7 +49,7 @@ func (p *node) newTab(n *node) { newt.uiWindow = t.uiWindow newt.uiTab = t.uiTab } else { - newt = t.appendTab(getString(n.value)) + newt = t.appendTab(widget.GetString(n.value)) } } diff --git a/andlabs/window.go b/andlabs/window.go index 09bf6b8..d52648e 100644 --- a/andlabs/window.go +++ b/andlabs/window.go @@ -5,6 +5,7 @@ import ( _ "go.wit.com/dev/andlabs/ui/winmanifest" "go.wit.com/log" + "go.wit.com/gui/widget" ) func (t *guiWidget) MessageWindow(msg1 string, msg2 string) { @@ -37,7 +38,7 @@ func newWindow(n *node) { } func (n *node) SetWindowTitle(title string) { - log.Log(CHANGE, "toolkit NewWindow", getString(n.value), "title", title) + log.Log(CHANGE, "toolkit NewWindow", widget.GetString(n.value), "title", title) win := n.tk.uiWindow if (win == nil) { log.Log(ERROR, "Error: no window", n.WidgetId) diff --git a/common/addNode.go b/common/addNode.go new file mode 100644 index 0000000..be769fc --- /dev/null +++ b/common/addNode.go @@ -0,0 +1,68 @@ +package main + +/* + These code should be common to all gui plugins + + There are some helper functions that are probably going to be + the same everywhere. Mostly due to handling the binary tree structure + and the channel communication + + For now, it's just a symlink to the 'master' version in + ./toolkit/nocui/common.go +*/ + +import ( + "reflect" + "strconv" + + "go.wit.com/log" + "go.wit.com/gui/widget" +) + +// this is in common.go, do not move it +func addNode(a *widget.Action) *node { + n := new(node) + n.WidgetType = a.WidgetType + n.WidgetId = a.WidgetId + n.ParentId = a.ParentId + + n.state = a.State + + // copy the data from the action message + n.progname = a.ProgName + n.value = a.Value + n.direction = a.Direction + n.strings = a.Strings + + // TODO: these need to be rethought + n.X = a.X + n.Y = a.Y + n.W = a.W + n.H = a.H + n.AtW = a.AtW + n.AtH = a.AtH + + // store the internal toolkit information + n.tk = initWidget(n) + // n.tk = new(guiWidget) + + if (a.WidgetType == widget.Root) { + log.Log(INFO, "addNode() Root") + return n + } + + if (me.rootNode.findWidgetId(a.WidgetId) != nil) { + log.Log(ERROR, "addNode() WidgetId already exists", a.WidgetId) + return me.rootNode.findWidgetId(a.WidgetId) + } + + // add this new widget on the binary tree + n.parent = me.rootNode.findWidgetId(a.ParentId) + if n.parent != nil { + n.parent.children = append(n.parent.children, n) + //w := n.tk + //w.parent = n.parent.tk + //w.parent.children = append(w.parent.children, w) + } + return n +} diff --git a/common/plugin.go b/common/plugin.go new file mode 100644 index 0000000..bfc9a68 --- /dev/null +++ b/common/plugin.go @@ -0,0 +1,69 @@ +package main + +/* + These code should be common to all gui plugins + + There are some helper functions that are probably going to be + the same everywhere. Mostly due to handling the binary tree structure + and the channel communication + + For now, it's just a symlink to the 'master' version in + ./toolkit/nocui/common.go +*/ + +import ( + "reflect" + "strconv" + + "go.wit.com/log" + "go.wit.com/gui/widget" +) + +// searches the binary tree for a WidgetId +func (n *node) findWidgetId(id int) *node { + if (n == nil) { + return nil + } + + if n.WidgetId == id { + return n + } + + for _, child := range n.children { + newN := child.findWidgetId(id) + if (newN != nil) { + return newN + } + } + return nil +} + +func (n *node) doUserEvent() { + if (callback == nil) { + log.Log(ERROR, "doUserEvent() callback == nil", n.WidgetId) + return + } + var a widget.Action + a.WidgetId = n.WidgetId + a.Value = n.value + a.ActionType = widget.User + log.Log(INFO, "doUserEvent() START: send a user event to the callback channel") + callback <- a + log.Log(INFO, "doUserEvent() END: sent a user event to the callback channel") + return +} + +// 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.) +// +// this sets the channel to send user events back from the plugin +func Callback(guiCallback chan widget.Action) { + callback = guiCallback +} + +func PluginChannel() chan widget.Action { + return pluginChan +} diff --git a/common/structs.go b/common/structs.go new file mode 100644 index 0000000..32eed8a --- /dev/null +++ b/common/structs.go @@ -0,0 +1,43 @@ +package main + +/* + These code should be common to all gui plugins + + There are some helper functions that are probably going to be + the same everywhere. Mostly due to handling the binary tree structure + and the channel communication + + For now, it's just a symlink to the 'master' version in + ./toolkit/nocui/common.go +*/ + +import ( + "reflect" + "strconv" + + "go.wit.com/log" + "go.wit.com/gui/widget" +) + +// this is the channel we send user events like +// mouse clicks or keyboard events back to the program +var callback chan widget.Action + +// this is the channel we get requests to make widgets +var pluginChan chan widget.Action + +type Node struct { + parent *node + children []*node + + WidgetId int // widget ID + WidgetType widget.WidgetType + ParentId int // parent ID + + State widget.State + + // the internal plugin toolkit structure + // in the gtk plugin, it has gtk things like margin & border settings + // in the text console one, it has text console things like colors for menus & buttons + TK any +} diff --git a/nocui/common.go b/nocui/common.go index 35d8f22..7b79ca0 100644 --- a/nocui/common.go +++ b/nocui/common.go @@ -12,9 +12,6 @@ package main */ import ( - "reflect" - "strconv" - "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -34,6 +31,8 @@ type node struct { WidgetType widget.WidgetType ParentId int // parent ID + state widget.State + // a reference name for programming and debuggign. Must be unique progname string @@ -139,6 +138,7 @@ func convertString(val any) string { } */ +/* // this is in common.go, do not move it func getString(A any) string { if A == nil { @@ -167,6 +167,7 @@ func getString(A any) string { } return "" } +*/ // this is in common.go, do not move it func addNode(a *widget.Action) *node { @@ -175,6 +176,8 @@ func addNode(a *widget.Action) *node { n.WidgetId = a.WidgetId n.ParentId = a.ParentId + n.state = a.State + // copy the data from the action message n.progname = a.ProgName n.value = a.Value |
