summaryrefslogtreecommitdiff
path: root/andlabs/setText.go
blob: 9aabd99373f9198db993a6b7f4b9c061ae41254b (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
package main

import (
	"reflect"
	"strconv"

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

func (n *node) setText(a *widget.Action) {
	var name string
	var A any
	var k reflect.Kind
	A = a.A
	if a.A == nil {
		log.Warn("setText a.A == nil")
		A = ""
	}

	k = reflect.TypeOf(A).Kind()

	switch k {
	case reflect.Int:
		var i int
		i = A.(int)
		name = strconv.Itoa(i)
	case reflect.String:
		name = A.(string)
	case reflect.Bool:
		if A.(bool) == true {
			name = "true"
		} else {
			name = "false"
		}
	default:
		log.Warn("setText uknown kind", k, "value =", A)
		name = ""
	}

	log.Log(CHANGE, "setText() START with text =", name)
	t := n.tk
	if (t == nil) {
		log.Log(ERROR, "setText error. tk == nil", n.Name, n.WidgetId)
		actionDump(debugError, a)
		return
	}
	log.Log(CHANGE, "setText() Attempt on", n.WidgetType, "with", name)

	switch n.WidgetType {
	case widget.Window:
		log.Warn("setText() Attempt to set the title to", name)
		t.uiWindow.SetTitle(name)
	case widget.Tab:
	case widget.Group:
		t.uiGroup.SetTitle(name)
	case widget.Checkbox:
		t.uiCheckbox.SetText(name)
	case widget.Textbox:
		if (t.uiEntry != nil) {
			t.uiEntry.SetText(name)
		}
		if (t.uiMultilineEntry != nil) {
			t.uiMultilineEntry.SetText(name)
		}
	case widget.Label:
		t.uiLabel.SetText(name)
	case widget.Button:
		t.uiButton.SetText(name)
	case widget.Slider:
		log.Log(ERROR, "setText() on slider unknown", a.ActionType, "on checkbox", n.Name)
	case widget.Spinner:
		log.Log(ERROR, "setText() on spinner unknown", a.ActionType, "on checkbox", n.Name)
	case widget.Dropdown:
		var orig int
		var i int = -1
		var s string
		orig = t.uiCombobox.Selected()
		log.Log(CHANGE, "try to set the Dropdown to", name, "from", orig)
		// try to find the string
		for i, s = range t.val {
			log.Log(CHANGE, "i, s", i, s)
			if (name == s) {
				t.uiCombobox.SetSelected(i)
				log.Log(CHANGE, "setText() Dropdown worked.", name)
				return
			}
		}
		log.Log(ERROR, "setText() Dropdown did not find:", name)
		// if i == -1, then there are not any things in the menu to select
		if (i == -1) {
			return
		}
		// if the string was never set, then set the dropdown to the last thing added to the menu
		if (orig == -1) {
			t.uiCombobox.SetSelected(i)
		}
	case widget.Combobox:
		t.uiEditableCombobox.SetText(name)
	default:
		log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet", a.ActionType)
	}
	log.Log(CHANGE, "setText() END with name =", )
}