diff options
| author | Jeff Carr <[email protected]> | 2024-01-11 00:51:37 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-11 00:51:37 -0600 |
| commit | 5f6afb8cf8293f819711ccdf791296edfd7ce7d6 (patch) | |
| tree | cd1fdf500294e30df6628045b307e7d146c4c55a /setText.go | |
| parent | b3fce8457ff73a31fe889eb7b1315fae2e016cc4 (diff) | |
continuing move toward var value anyv0.12.1
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'setText.go')
| -rw-r--r-- | setText.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/setText.go b/setText.go new file mode 100644 index 0000000..5e04d70 --- /dev/null +++ b/setText.go @@ -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) + } +} |
