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

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

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

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

	Custom func()
}

func (n *BasicEntry) SetText(s string) *BasicEntry {
	log.Log(GADGETS, "BasicEntry.Set() =", s)
	n.v.SetText(s)
	return n
}

func (n *BasicEntry) Enable() {
	log.Log(GADGETS, "BasicEntry.Enable()")
	n.v.Enable()
}

func (n *BasicEntry) Disable() {
	log.Log(GADGETS, "BasicEntry.Disable()")
	n.v.Disable()
}

func (n *BasicEntry) String() string {
	log.Log(GADGETS, "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,
	}

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

	return &d
}