summaryrefslogtreecommitdiff
path: root/nocui/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'nocui/common.go')
-rw-r--r--nocui/common.go67
1 files changed, 46 insertions, 21 deletions
diff --git a/nocui/common.go b/nocui/common.go
index bfb76c8..cd5b7f1 100644
--- a/nocui/common.go
+++ b/nocui/common.go
@@ -12,6 +12,9 @@ package main
*/
import (
+ "reflect"
+ "strconv"
+
"go.wit.com/log"
"go.wit.com/gui/widget"
)
@@ -31,16 +34,19 @@ type node struct {
WidgetType widget.WidgetType
ParentId int // parent ID
- Name string
- Text string
+ // Name string
+ // Text string
+
+ progname string
+ label string
+
+ // horizontal means layout widgets like books on a bookshelf
+ // vertical means layout widgets like books in a stack
+ direction widget.Orientation
// This is how the values are passed back and forth
// values from things like checkboxes & dropdown's
- B bool
- I int
- S string
-
- A any // switch to this or deprecate this? pros/cons?
+ value any
// This is used for things like a slider(0,100)
X int
@@ -54,9 +60,7 @@ type node struct {
vals []string // dropdown menu items
- // horizontal=true means layout widgets like books on a bookshelf
- // horizontal=false means layout widgets like books in a stack
- horizontal bool `default:false`
+ // horizontal bool `default:false`
hasTabs bool // does the window have tabs?
currentTab bool // the visible tab
@@ -93,12 +97,7 @@ func (n *node) doUserEvent() {
}
var a widget.Action
a.WidgetId = n.WidgetId
- a.Name = n.Name
- a.Text = n.Text
- a.S = n.S
- a.I = n.I
- a.B = n.B
- a.A = n.A
+ a.Value = n.value
a.ActionType = widget.User
log.Log(INFO, "doUserEvent() START: send a user event to the callback channel")
callback <- a
@@ -113,11 +112,9 @@ func addNode(a *widget.Action) *node {
n.ParentId = a.ParentId
// copy the data from the action message
- n.Name = a.Name
- n.Text = a.Text
- n.I = a.I
- n.S = a.S
- n.B = a.B
+ n.progname = a.ProgName
+ n.value = a.Value
+ n.direction = a.Direction
n.X = a.X
n.Y = a.Y
@@ -166,3 +163,31 @@ func Callback(guiCallback chan widget.Action) {
func PluginChannel() chan widget.Action {
return pluginChan
}
+
+func getString(A any) string {
+ if A == nil {
+ log.Warn("getString() got nil")
+ return ""
+ }
+ var k reflect.Kind
+ k = reflect.TypeOf(A).Kind()
+
+ switch k {
+ case reflect.Int:
+ var i int
+ i = A.(int)
+ return strconv.Itoa(i)
+ case reflect.String:
+ return A.(string)
+ case reflect.Bool:
+ if A.(bool) == true {
+ return "true"
+ } else {
+ return "false"
+ }
+ default:
+ log.Warn("getString uknown kind", k, "value =", A)
+ return ""
+ }
+ return ""
+}