continuing move toward var value any
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
190682f9c6
commit
828a6af020
41
common.go
41
common.go
|
@ -4,7 +4,6 @@ package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"errors"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/widget"
|
"go.wit.com/gui/widget"
|
||||||
)
|
)
|
||||||
|
@ -66,46 +65,12 @@ func (n *Node) AddText(str string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) SetText(text string) *Node {
|
|
||||||
log.Log(CHANGE, "SetText() value =", text)
|
|
||||||
|
|
||||||
n.Text = text
|
|
||||||
n.S = text
|
|
||||||
|
|
||||||
if ! n.hidden {
|
|
||||||
a := newAction(n, widget.SetText)
|
|
||||||
sendAction(a)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Node) SetNext(w int, h int) {
|
func (n *Node) SetNext(w int, h int) {
|
||||||
n.NextW = w
|
n.NextW = w
|
||||||
n.NextH = h
|
n.NextH = h
|
||||||
log.Info("SetNext() w,h =", n.NextW, n.NextH)
|
log.Info("SetNext() w,h =", n.NextW, n.NextH)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Set(val any) {
|
|
||||||
log.Log(CHANGE, "Set() value =", val)
|
|
||||||
|
|
||||||
switch v := val.(type) {
|
|
||||||
case bool:
|
|
||||||
n.B = val.(bool)
|
|
||||||
case string:
|
|
||||||
n.Text = val.(string)
|
|
||||||
n.S = val.(string)
|
|
||||||
case int:
|
|
||||||
n.I = val.(int)
|
|
||||||
default:
|
|
||||||
log.Error(errors.New("Set() unknown type"), "v =", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ! n.hidden {
|
|
||||||
a := newAction(n, widget.Set)
|
|
||||||
sendAction(a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Node) AppendText(str string) {
|
func (n *Node) AppendText(str string) {
|
||||||
tmp := n.S + str
|
tmp := n.S + str
|
||||||
n.Text = tmp
|
n.Text = tmp
|
||||||
|
@ -246,7 +211,11 @@ func (n *Node) Window(title string) *Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Ready() bool {
|
func (n *Node) Ready() bool {
|
||||||
if n == nil {return false}
|
if n == nil {
|
||||||
|
log.Warn("Ready() got node == nil")
|
||||||
|
// TODO: figure out if you can identify the code trace to help find the root cause
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package gui
|
||||||
|
|
||||||
|
// Common actions for widgets like 'Enable' or 'Hide'
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
"go.wit.com/gui/widget"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (n *Node) SetText(text string) *Node {
|
||||||
|
if ! n.Ready() { return n }
|
||||||
|
log.Log(CHANGE, "SetText() value =", text)
|
||||||
|
|
||||||
|
n.value = text
|
||||||
|
|
||||||
|
if ! n.hidden {
|
||||||
|
a := newAction(n, widget.SetText)
|
||||||
|
a.A = n.value
|
||||||
|
sendAction(a)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) Set(val any) {
|
||||||
|
log.Log(CHANGE, "Set() value =", val)
|
||||||
|
|
||||||
|
n.value = val
|
||||||
|
|
||||||
|
switch v := val.(type) {
|
||||||
|
case bool:
|
||||||
|
n.B = val.(bool)
|
||||||
|
case string:
|
||||||
|
n.Text = val.(string)
|
||||||
|
n.S = val.(string)
|
||||||
|
case int:
|
||||||
|
n.I = val.(int)
|
||||||
|
default:
|
||||||
|
log.Error(errors.New("Set() unknown type"), "v =", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! n.hidden {
|
||||||
|
a := newAction(n, widget.Set)
|
||||||
|
a.A = val
|
||||||
|
sendAction(a)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue