summaryrefslogtreecommitdiff
path: root/setText.go
blob: eb09640eab07279b27f67b160c734e06932a260a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gui

// Common actions for widgets like 'Enable' or 'Hide'

import (
	"errors"

	"go.wit.com/log"
	"go.wit.com/widget"
)

func (n *Node) SetText(text string) *Node {
	if !n.Ready() {
		return n
	}

	if n.String() == 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)
}