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