new-gui/setText.go

58 lines
978 B
Go

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 }
if n.GetText() == text {
// nothing changed
return n
}
n.value = text
n.changed = true
log.Log(CHANGE, "SetText() value =", text)
// inform the toolkits
sendAction(n, widget.SetText)
return n
}
func (n *Node) Set(val any) {
if ! n.Ready() { return }
switch v := val.(type) {
case bool:
if widget.GetBool(n.value) == val.(bool) {
// nothing changed
return
}
case string:
if widget.GetString(n.value) == val.(string) {
// nothing changed
return
}
case int:
if widget.GetInt(n.value) == val.(int) {
// nothing changed
return
}
default:
log.Error(errors.New("Set() unknown type"), "v =", v)
}
n.value = val
n.changed = true
log.Log(CHANGE, "Set() value =", val)
// inform the toolkits
sendAction(n, widget.Set)
}