prepare for protobuf

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-05 15:02:09 -06:00
parent 8fcf5f668b
commit a57a8b5a63
11 changed files with 33 additions and 29 deletions

View File

@ -60,7 +60,10 @@ func getNewAction(n *Node, atype widget.ActionType) *widget.Action {
// set state // set state
a.State.ProgName = n.progname a.State.ProgName = n.progname
a.State.Label = n.label a.State.Label = n.label
a.State.Value = n.value // a.State.Value = n.value
a.State.DefaultS = n.defaultS
a.State.CurrentS = n.currentS
a.State.NewString = n.newString
a.State.Checked = n.checked a.State.Checked = n.checked
a.State.Visable = n.visable a.State.Visable = n.visable
@ -79,7 +82,7 @@ func getNewAction(n *Node, atype widget.ActionType) *widget.Action {
a.State.Range.High = n.Y a.State.Range.High = n.Y
a.ProgName = n.progname a.ProgName = n.progname
a.Value = n.value // a.Value = n.value
a.Direction = n.direction a.Direction = n.direction
// These should be improved/deprecated based on the gui/widget docs // These should be improved/deprecated based on the gui/widget docs

View File

@ -17,7 +17,7 @@ func (n *Node) addText(newS string) {
} }
} }
n.strings[newS] = highest + 1 // TODO: use the int's for the order n.strings[newS] = highest + 1 // TODO: use the int's for the order
n.value = newS n.newString = newS
/* /*
// time.Sleep(time.Duration(1000 * time.Nanosecond)) // doesn't work // time.Sleep(time.Duration(1000 * time.Nanosecond)) // doesn't work
// maybe this stupid chipset is defective. TODO: try on different hardware // maybe this stupid chipset is defective. TODO: try on different hardware

View File

@ -99,7 +99,7 @@ func (n *Node) Bool() bool {
default: default:
} }
return widget.GetBool(n.value) return false
} }
func (n *Node) Int() int { func (n *Node) Int() int {
@ -107,14 +107,13 @@ func (n *Node) Int() int {
return -1 return -1
} }
return widget.GetInt(n.value) return -1
} }
func (n *Node) SetBool(b bool) { func (n *Node) SetBool(b bool) {
switch n.WidgetType { switch n.WidgetType {
case widget.Checkbox: case widget.Checkbox:
n.checked = b n.checked = b
n.value = b
default: default:
log.Warn("WidgetType not bool", n.WidgetType, n.id) log.Warn("WidgetType not bool", n.WidgetType, n.id)
} }
@ -123,7 +122,7 @@ func (n *Node) SetBool(b bool) {
func (n *Node) SetInt(i int) { func (n *Node) SetInt(i int) {
switch n.WidgetType { switch n.WidgetType {
default: default:
n.value = i // n.value = i
// log.Warn("WidgetType not bool", n.WidgetType, n.id) // log.Warn("WidgetType not bool", n.WidgetType, n.id)
} }
} }
@ -144,7 +143,7 @@ func (n *Node) String() string {
default: default:
} }
return widget.GetString(n.value) return widget.GetString(n.currentS)
} }
func (n *Node) Strings() []string { func (n *Node) Strings() []string {
@ -181,8 +180,8 @@ func (n *Node) AppendText(str string) {
if !n.Ready() { if !n.Ready() {
return return
} }
tmp := widget.GetString(n.value) + str tmp := n.currentS + str
n.value = tmp n.newString = tmp
n.changed = true n.changed = true
// inform the toolkits // inform the toolkits

View File

@ -64,10 +64,10 @@ func (n *Node) dumpWidget(b bool) string {
if b { if b {
switch n.WidgetType { switch n.WidgetType {
case widget.Combobox: case widget.Combobox:
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.value) logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.currentS)
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.strings) logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.strings)
case widget.Dropdown: case widget.Dropdown:
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.value) logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.currentS)
logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.strings) logindent(b, listChildrenDepth, defaultPadding, " Dropdown", n.strings)
case widget.Grid: case widget.Grid:
logindent(b, listChildrenDepth, defaultPadding, " GridSize =", n.X, n.Y) logindent(b, listChildrenDepth, defaultPadding, " GridSize =", n.X, n.Y)

View File

@ -143,7 +143,7 @@ func (n *Node) gotUserEvent(a widget.Action) {
default: default:
} }
n.value = a.Value n.currentS = a.State.CurrentS
log.Log(CHANGE, "gotUserEvent() n.Bool() =", n.Bool(), "n.String() =", n.String()) log.Log(CHANGE, "gotUserEvent() n.Bool() =", n.Bool(), "n.String() =", n.String())
if n.Custom == nil { if n.Custom == nil {
log.Log(CHANGE, "a Custom() function was not set for this widget") log.Log(CHANGE, "a Custom() function was not set for this widget")

View File

@ -13,7 +13,7 @@ and it initializes basic default values
there isn't much to see here. there isn't much to see here.
*/ */
func (n *Node) newNode(title string, t widget.WidgetType) *Node { func (n *Node) newNode(s string, t widget.WidgetType) *Node {
if n == nil { if n == nil {
log.Warn("newNode got parent == nil") log.Warn("newNode got parent == nil")
panic("gui newNode") panic("gui newNode")
@ -21,8 +21,11 @@ func (n *Node) newNode(title string, t widget.WidgetType) *Node {
var newN *Node var newN *Node
newN = addNode() newN = addNode()
newN.progname = title newN.progname = s
newN.value = title newN.label = s
newN.defaultS = s
newN.newString = s
newN.currentS = s
newN.WidgetType = t newN.WidgetType = t
newN.strings = make(map[string]int) newN.strings = make(map[string]int)

View File

@ -16,10 +16,6 @@ func (n *Node) SetLabel(label string) *Node {
n.label = label n.label = label
case widget.Button: case widget.Button:
n.label = label n.label = label
case widget.Combobox:
n.label = label
case widget.Dropdown:
n.label = label
case widget.Label: case widget.Label:
n.label = label n.label = label
case widget.Group: case widget.Group:
@ -30,7 +26,7 @@ func (n *Node) SetLabel(label string) *Node {
} }
n.changed = true n.changed = true
log.Log(CHANGE, "SetLabel() value =", label) log.Log(CHANGE, "SetLabel() =", label)
// inform the toolkits // inform the toolkits
sendAction(n, widget.SetText) sendAction(n, widget.SetText)
@ -40,7 +36,7 @@ func (n *Node) SetLabel(label string) *Node {
// What "SetText" means depends on the type of widget // What "SetText" means depends on the type of widget
// should this be a different name? // should this be a different name?
func (n *Node) SetText(text string) *Node { func (n *Node) SetText(text string) *Node {
n.value = text n.newString = text
n.changed = true n.changed = true
log.Log(CHANGE, "SetText() text =", text) log.Log(CHANGE, "SetText() text =", text)
@ -54,15 +50,15 @@ func (n *Node) SetText(text string) *Node {
case widget.Group: case widget.Group:
n.label = text n.label = text
case widget.Combobox: case widget.Combobox:
n.label = text n.newString = text
case widget.Dropdown: case widget.Dropdown:
n.label = text n.newString = text
case widget.Window: case widget.Window:
n.label = text n.label = text
default: default:
} }
// inform the toolkits // inform the toolkits
sendAction(n, widget.Set) sendAction(n, widget.SetText)
return n return n
} }

View File

@ -96,7 +96,10 @@ type Node struct {
WidgetType widget.WidgetType WidgetType widget.WidgetType
// most widgets need one value, this is current alue // most widgets need one value, this is current alue
value any // value any
defaultS string
newString string
currentS string
// //
label string label string

View File

@ -8,7 +8,7 @@ import (
func (parent *Node) NewTextbox(name string) *Node { func (parent *Node) NewTextbox(name string) *Node {
newNode := parent.newNode(name, widget.Textbox) newNode := parent.newNode(name, widget.Textbox)
newNode.value = name newNode.defaultS = name
newNode.progname = name newNode.progname = name
newNode.Custom = func() { newNode.Custom = func() {
@ -22,7 +22,7 @@ func (parent *Node) NewTextbox(name string) *Node {
func (parent *Node) NewEntryLine(name string) *Node { func (parent *Node) NewEntryLine(name string) *Node {
newNode := parent.newNode(name, widget.Textbox) newNode := parent.newNode(name, widget.Textbox)
newNode.value = name newNode.defaultS = name
newNode.progname = name newNode.progname = name
newNode.X = 1 newNode.X = 1

View File

@ -19,6 +19,7 @@ func Watchdog() {
myTicker(10*time.Second, "WATCHDOG", func() { myTicker(10*time.Second, "WATCHDOG", func() {
i += 1 i += 1
log.Log(INFO, "myTicker() ticked", i) log.Log(INFO, "myTicker() ticked", i)
me.rootNode.ListToolkits()
}) })
} }

View File

@ -29,7 +29,6 @@ func (parent *Node) NewWindow(title string) *Node {
log.Log(INFO, "NewWindow()", title) log.Log(INFO, "NewWindow()", title)
newNode.progname = title newNode.progname = title
newNode.label = title newNode.label = title
newNode.value = title
newNode.margin = true newNode.margin = true
newNode.visable = true newNode.visable = true
newNode.hidden = false newNode.hidden = false