gadgets/basicEntry.go

70 lines
1.2 KiB
Go
Raw Normal View History

2024-01-01 16:19:40 -06:00
/*
A Labeled Single Line Entry widget:
2024-01-01 16:19:40 -06:00
-----------------------------
| | |
| Food: | <type here> |
| | |
-----------------------------
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 BasicEntry struct {
parent *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 *BasicEntry) SetText(s string) *BasicEntry {
log.Log(GADGETS, "BasicEntry.Set() =", s)
n.v.SetValue(s)
n.v.SetText(s)
n.v.SetLabel(s)
2024-01-01 16:19:40 -06:00
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.String() =", n.v.String())
return n.v.String()
}
func (n *BasicEntry) SetLabel(s string) *BasicEntry {
n.l.SetText(s)
return n
}
2024-01-01 16:19:40 -06:00
func NewBasicEntry(p *gui.Node, name string) *BasicEntry {
d := BasicEntry{
2024-01-01 16:19:40 -06:00
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()
}
2024-01-01 16:19:40 -06:00
}
return &d
}