diff --git a/args.go b/args.go new file mode 100644 index 0000000..886880e --- /dev/null +++ b/args.go @@ -0,0 +1,22 @@ +package gui + +import ( + arg "github.com/alexflint/go-arg" +) + +var guiArg GuiArgs + +// This struct can be used with the go-arg package +type GuiArgs struct { + Gui string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"` + GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"` + GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"` +} + +func init() { + arg.Register(&guiArg) +} + +func GetArg(a string) bool { + return guiArg.GuiDebug +} diff --git a/gadgets/basicEntry.go b/gadgets/basicEntry.go new file mode 100644 index 0000000..105347b --- /dev/null +++ b/gadgets/basicEntry.go @@ -0,0 +1,56 @@ +/* + A Labeled Single Line Entry widget: + + ----------------------------- + | | | + | Food: | | + | | | + ----------------------------- +*/ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui" +) + +type BasicEntry struct { + parent *gui.Node // parent widget + l *gui.Node // label widget + v *gui.Node // value widget + + value string + label string + + Custom func() +} + +func (n *BasicEntry) Get() string { + return n.value +} + +func (n *BasicEntry) Set(value string) *BasicEntry { + log.Println("BasicEntry.Set() =", value) + if (n.v != nil) { + n.v.Set(value) + } + n.value = value + return n +} + +func NewBasicEntry(p *gui.Node, name string) *BasicEntry { + d := BasicEntry { + parent: p, + value: "", + } + + // various timeout settings + d.l = p.NewLabel(name) + d.v = p.NewEntryLine("") + d.v.Custom = func() { + d.value = d.v.S + log.Println("BasicEntry.Custom() user changed value to =", d.value) + } + + return &d +} diff --git a/main.go b/main.go index 84a7d52..09b2bc1 100644 --- a/main.go +++ b/main.go @@ -123,9 +123,9 @@ func New() *Node { // try to load andlabs, if that doesn't work, fall back to the console func (n *Node) Default() *Node { - if (GuiArg.Gui != "") { - log(logError, "New.Default() try toolkit =", GuiArg.Gui) - return n.LoadToolkit(GuiArg.Gui) + if (guiArg.Gui != "") { + log(logError, "New.Default() try toolkit =", guiArg.Gui) + return n.LoadToolkit(guiArg.Gui) } // if DISPLAY isn't set, return since gtk can't load // TODO: figure out how to check what to do in macos and mswindows diff --git a/structs.go b/structs.go index b9d4d89..406b11a 100644 --- a/structs.go +++ b/structs.go @@ -23,15 +23,6 @@ import ( var me guiConfig -var GuiArg GuiArgs - -// This struct can be used with the go-arg package -type GuiArgs struct { - Gui string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"` - GuiDebug bool `arg:"--gui-debug" help:"open the GUI debugger"` - GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"` -} - type guiConfig struct { initOnce sync.Once