summaryrefslogtreecommitdiff
path: root/basicEntry.go
blob: 29a0dd8d5e94e6bde5050a64d3db7e68399cea4c (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
/*
	A Labeled Single Line Entry widget:

	-----------------------------
	|            |              |
	|   Food:    |  <type here> |
	|            |              |
	-----------------------------
*/
package gadgets

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

type BasicEntry struct {
	parent	*gui.Node	// parent widget
	l	*gui.Node	// label widget
	v	*gui.Node	// value widget

	value	string
	label	string

	Custom func()
}

/*
func (n *BasicEntry) Get() string {
	return n.value
}

func (n *BasicEntry) Set(value string) *BasicEntry {
	log.Log(INFO, "BasicEntry.Set() =", value)
	if (n.v != nil) {
		n.v.Set(value)
	}
	n.value = value
	return n
}
*/

func (n *BasicEntry) Enable() {
	log.Log(INFO, "BasicEntry.Enable()")
	if (n.v != nil) {
		n.v.Enable()
	}
}

func (n *BasicEntry) Disable() {
	log.Log(INFO, "BasicEntry.Disable()")
	if (n.v != nil) {
		n.v.Disable()
	}
}

func (n *BasicEntry) String() string {
	log.Log(INFO, "BasicEntry.SetLabel() =", n.v.String())
	return n.v.String()
}

func (n *BasicEntry) SetLabel(s string) *BasicEntry {
	n.l.SetText(s)
	return n
}

func NewBasicEntry(p *gui.Node, name string) *BasicEntry {
	d := BasicEntry {
		parent: p,
		value: "",
	}

	// various timeout settings
	d.l = p.NewLabel(name)
	d.v = p.NewEntryLine("")
	d.v.Custom = func() {
		d.value = d.v.String()
		log.Log(INFO, "BasicEntry.Custom() user changed value to =", d.value)
		if d.Custom != nil {
			d.Custom()
		}
	}

	return &d
}