gadgets/basicEntry.go

68 lines
1.2 KiB
Go

/*
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(INFO, "BasicEntry.Set() =", s)
n.v.SetText(s)
return n
}
func (n *BasicEntry) Enable() {
log.Log(INFO, "BasicEntry.Enable()")
n.v.Enable()
}
func (n *BasicEntry) Disable() {
log.Log(INFO, "BasicEntry.Disable()")
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,
}
// various timeout settings
d.l = p.NewLabel(name)
d.v = p.NewEntryLine("")
d.v.Custom = func() {
log.Log(INFO, "BasicEntry() user changed =", d.String())
if d.Custom != nil {
d.Custom()
}
}
return &d
}