gadgets/basicCombobox.go

89 lines
1.6 KiB
Go
Raw Normal View History

2024-01-01 16:19:40 -06:00
/*
A Labeled Combobox widget:
-----------------------------
| | |
| Food: | <dropdown> |
| | |
-----------------------------
The user can then edit the dropdown field and type anything into it
*/
package gadgets
import (
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type BasicCombobox struct {
ready bool
progname string
2024-01-01 16:19:40 -06:00
parent *gui.Node // parent widget
l *gui.Node // label widget
d *gui.Node // dropdown widget
Custom func()
}
func (d *BasicCombobox) String() string {
2024-01-01 16:19:40 -06:00
if ! d.Ready() {return ""}
return d.d.String()
}
func (d *BasicCombobox) SetText(s string) {
if ! d.Ready() {return}
d.d.SetText(s)
2024-01-01 16:19:40 -06:00
}
// Returns true if the status is valid
func (d *BasicCombobox) Ready() bool {
if d == nil {return false}
return d.ready
}
func (d *BasicCombobox) Enable() {
if d == nil {return}
if d.d == nil {return}
d.d.Enable()
}
func (d *BasicCombobox) Disable() {
if d == nil {return}
if d.d == nil {return}
d.d.Disable()
}
func (d *BasicCombobox) SetTitle(name string) {
if d == nil {return}
if d.d == nil {return}
d.d.SetText(name)
}
func (d *BasicCombobox) AddText(s string) {
2024-01-01 16:19:40 -06:00
if ! d.Ready() {return}
log.Log(INFO, "BasicCombobox.Add() =", s)
d.d.AddText(s)
2024-01-01 16:19:40 -06:00
}
func NewBasicCombobox(p *gui.Node, label string) *BasicCombobox {
2024-01-01 16:19:40 -06:00
d := BasicCombobox {
parent: p,
progname: label,
2024-01-01 16:19:40 -06:00
ready: false,
}
// various timeout settings
d.l = p.NewLabel(label)
d.d = p.NewCombobox()
2024-01-01 16:19:40 -06:00
d.d.Custom = func() {
log.Warn("BasicCombobox.Custom() user changed value to =", d.d.String())
2024-01-01 16:19:40 -06:00
if d.Custom != nil {
d.Custom()
}
}
d.ready = true
return &d
}