use widget.GetString()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-16 12:55:20 -06:00
parent 29c39d7a1c
commit ba95c13799
12 changed files with 203 additions and 13 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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))
}
}

View File

@ -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)

68
common/addNode.go Normal file
View File

@ -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
}

69
common/plugin.go Normal file
View File

@ -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
}

43
common/structs.go Normal file
View File

@ -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
}

View File

@ -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