gadgets/oneLiner.go

93 lines
1.7 KiB
Go
Raw Normal View History

2024-01-01 16:19:40 -06:00
/*
A Labeled label:
2024-01-01 16:19:40 -06:00
-----------------------------
| | |
| Food: | Apple |
| | |
-----------------------------
2024-01-01 16:19:40 -06:00
*/
package gadgets
import (
"go.wit.com/gui"
2024-01-01 16:19:40 -06:00
"go.wit.com/log"
)
type OneLiner struct {
p *gui.Node // parent widget
l *gui.Node // label widget
v *gui.Node // value widget
2024-01-01 16:19:40 -06:00
Custom func()
}
func (n *OneLiner) String() string {
return n.v.String()
2024-01-01 16:19:40 -06:00
}
2024-02-19 14:42:06 -06:00
// returns a widget of the last tag that acts as a mirror
func (n *OneLiner) MirrorLabel() *gui.Node {
return gui.RawMirror(n.l)
}
// returns a widget of the last tag that acts as a mirror
func (n *OneLiner) MirrorValue() *gui.Node {
return gui.RawMirror(n.v)
}
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)
2024-01-01 16:19:40 -06:00
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()
}
2024-02-13 16:17:08 -06:00
func (n *OneLiner) Show() {
log.Log(GADGETS, "OneLiner.Disable()")
n.l.Show()
n.v.Show()
}
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{
2024-01-01 16:19:40 -06:00
p: n,
}
// various timeout settings
d.l = n.NewLabel(label)
2024-01-01 16:19:40 -06:00
d.v = n.NewLabel("")
d.v.Custom = func() {
log.Log(GADGETS, "OneLiner.Custom() user changed value to =", d.v.String())
2024-01-01 16:19:40 -06:00
}
return &d
}