gadgets/basicEntry.go

86 lines
1.4 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
value string
label string
2024-01-01 16:19:40 -06:00
Custom func()
}
/*
2024-01-01 16:19:40 -06:00
func (n *BasicEntry) Get() string {
return n.value
}
func (n *BasicEntry) Set(value string) *BasicEntry {
log.Log(INFO, "BasicEntry.Set() =", value)
2024-01-01 16:19:40 -06:00
if (n.v != nil) {
n.v.Set(value)
}
n.value = value
return n
}
*/
2024-01-01 16:19:40 -06:00
func (n *BasicEntry) Enable() {
log.Log(INFO, "BasicEntry.Enable()")
if n.v != nil {
n.v.Enable()
}
}
func (n *BasicEntry) Disable() {
log.Log(INFO, "BasicEntry.Disable()")
if n.v != nil {
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
}
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,
value: "",
2024-01-01 16:19:40 -06:00
}
// various timeout settings
d.l = p.NewLabel(name)
d.v = p.NewEntryLine("")
d.v.Custom = func() {
d.value = d.v.String()
log.Log(INFO, "BasicEntry.Custom() user changed value to =", d.value)
if d.Custom != nil {
d.Custom()
}
2024-01-01 16:19:40 -06:00
}
return &d
}