77 lines
1.3 KiB
Go
77 lines
1.3 KiB
Go
/*
|
|
A Labeled label:
|
|
|
|
-----------------------------
|
|
| | |
|
|
| Food: | Apple |
|
|
| | |
|
|
-----------------------------
|
|
*/
|
|
package gadgets
|
|
|
|
import (
|
|
"go.wit.com/gui"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
type OneLiner struct {
|
|
p *gui.Node // parent widget
|
|
l *gui.Node // label widget
|
|
v *gui.Node // value widget
|
|
|
|
Custom func()
|
|
}
|
|
|
|
func (n *OneLiner) String() string {
|
|
return n.v.String()
|
|
}
|
|
|
|
func (n *OneLiner) SetText(s string) *OneLiner {
|
|
log.Log(GADGETS, "OneLiner.Set() =", s)
|
|
n.v.SetLabel(s)
|
|
return n
|
|
}
|
|
|
|
func (n *OneLiner) SetValue(s string) *OneLiner {
|
|
log.Log(GADGETS, "OneLiner.Set() =", s)
|
|
n.v.SetLabel(s)
|
|
return n
|
|
}
|
|
|
|
func (n *OneLiner) SetLabel(value string) *OneLiner {
|
|
log.Log(GADGETS, "OneLiner.SetLabel() =", value)
|
|
n.l.SetLabel(value)
|
|
return n
|
|
}
|
|
|
|
func (n *OneLiner) Enable() {
|
|
log.Log(GADGETS, "OneLiner.Enable()")
|
|
n.v.Show()
|
|
}
|
|
|
|
func (n *OneLiner) Disable() {
|
|
log.Log(GADGETS, "OneLiner.Disable()")
|
|
n.v.Hide()
|
|
}
|
|
|
|
func (n *OneLiner) Hide() {
|
|
log.Log(GADGETS, "OneLiner.Disable()")
|
|
n.l.Hide()
|
|
n.v.Hide()
|
|
}
|
|
|
|
func NewOneLiner(n *gui.Node, label string) *OneLiner {
|
|
d := OneLiner{
|
|
p: n,
|
|
}
|
|
|
|
// various timeout settings
|
|
d.l = n.NewLabel(label)
|
|
d.v = n.NewLabel("")
|
|
d.v.Custom = func() {
|
|
log.Log(GADGETS, "OneLiner.Custom() user changed value to =", d.v.String())
|
|
}
|
|
|
|
return &d
|
|
}
|