summaryrefslogtreecommitdiff
path: root/setText.go
blob: 74d70a9b6510d24b0757adc152510f2601fb217d (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package gui

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

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

// This will set the visable name for widgets that
// have text displayed that is not editable by the user
// For example, a button, window, group, checkbox
func (n *Node) SetLabel(label string) *Node {
	switch n.WidgetType {
	case widget.Checkbox:
		n.label = label
	case widget.Button:
		n.label = label
	case widget.Label:
		n.label = label
	case widget.Group:
		n.label = label
	case widget.Window:
		n.label = label
	default:
	}

	n.changed = true
	log.Log(CHANGE, "SetLabel() value =", label)

	// inform the toolkits
	sendAction(n, widget.SetText)
	return n
}

// What "SetText" means depends on the type of widget
// should this be a different name?
func (n *Node) SetText(text string) *Node {
	n.SetValue(text)
	/*
		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) SetValue(val any) *Node {
	if !n.Ready() {
		return n
	}

	n.value = val
	n.changed = true
	log.Log(CHANGE, "Set() value =", val)

	// inform the toolkits
	sendAction(n, widget.Set)
	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)
}
*/