From a8d95fef8d0879a3e3ecdac76ab4df4fee658fcf Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 18 Jan 2024 05:04:18 -0600 Subject: [PATCH] lots of syntax changes Signed-off-by: Jeff Carr --- basicCombobox.go | 72 +++++++++++++++++++++++++-------------- basicDropdown.go | 59 +++++++++++++++++++------------- basicEntry.go | 34 +++++++++---------- basicLabel.go | 30 ++++++++--------- basicWindow.go | 86 ++++++++++++++++++++++++++++++++--------------- durationSlider.go | 40 +++++++++++----------- logFlag.go | 32 +++++++++--------- oneLiner.go | 30 ++++++++--------- 8 files changed, 222 insertions(+), 161 deletions(-) diff --git a/basicCombobox.go b/basicCombobox.go index aacf612..3fc250e 100644 --- a/basicCombobox.go +++ b/basicCombobox.go @@ -1,77 +1,97 @@ /* - A Labeled Combobox widget: +A Labeled Combobox widget: - ----------------------------- - | | | - | Food: | | - | | | - ----------------------------- +----------------------------- +| | | +| Food: | | +| | | +----------------------------- - The user can then edit the dropdown field and type anything into it +The user can then edit the dropdown field and type anything into it */ package gadgets -import ( +import ( + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type BasicCombobox struct { - ready bool + ready bool progname string - parent *gui.Node // parent widget - l *gui.Node // label widget - d *gui.Node // dropdown widget + parent *gui.Node // parent widget + l *gui.Node // label widget + d *gui.Node // dropdown widget Custom func() } func (d *BasicCombobox) String() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return d.d.String() } func (d *BasicCombobox) SetText(s string) { - if ! d.Ready() {return} + if !d.Ready() { + return + } d.d.SetText(s) } // Returns true if the status is valid func (d *BasicCombobox) Ready() bool { - if d == nil {return false} + if d == nil { + return false + } return d.ready } func (d *BasicCombobox) Enable() { - if d == nil {return} - if d.d == nil {return} + 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} + 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} + if d == nil { + return + } + if d.d == nil { + return + } d.d.SetText(name) } func (d *BasicCombobox) AddText(s string) { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Log(INFO, "BasicCombobox.Add() =", s) d.d.AddText(s) } func NewBasicCombobox(p *gui.Node, label string) *BasicCombobox { - d := BasicCombobox { - parent: p, + d := BasicCombobox{ + parent: p, progname: label, - ready: false, + ready: false, } // various timeout settings diff --git a/basicDropdown.go b/basicDropdown.go index fbc5137..075cd29 100644 --- a/basicDropdown.go +++ b/basicDropdown.go @@ -1,31 +1,31 @@ /* - A Labeled Dropdown widget: +A Labeled Dropdown widget: - ----------------------------- - | | | - | Food: | | - | | | - ----------------------------- +----------------------------- +| | | +| Food: | | +| | | +----------------------------- - This being a 'Basic Dropdown', the dropdown names must be unique +This being a 'Basic Dropdown', the dropdown names must be unique */ package gadgets -import ( +import ( + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type BasicDropdown struct { - ready bool - name string + ready bool + name string - parent *gui.Node // parent widget - l *gui.Node // label widget - d *gui.Node // dropdown widget + parent *gui.Node // parent widget + l *gui.Node // label widget + d *gui.Node // dropdown widget - value string - label string + value string + label string Custom func() } @@ -39,36 +39,47 @@ func (d *BasicDropdown) Get() string { // Returns true if the status is valid func (d *BasicDropdown) Ready() bool { - if d == nil {return false} + if d == nil { + return false + } return d.ready } func (d *BasicDropdown) AddText(s string) { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Log(INFO, "BasicDropdown.AddText() =", s) d.d.AddText(s) return } func (d *BasicDropdown) SetText(s string) { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Log(INFO, "BasicDropdown.SetText() =", s) d.d.SetText(s) return } func (d *BasicDropdown) String() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } log.Log(INFO, "BasicDropdown.String()", d.d.String()) return d.d.String() } func (d *BasicDropdown) SetLabel(value string) bool { - if ! d.Ready() {return false} + if !d.Ready() { + return false + } log.Log(INFO, "BasicDropdown.SetLabel() =", value) d.l.SetText(value) return true } + /* func (d *BasicDropdown) Set(value string) bool { if ! d.Ready() {return false} @@ -80,10 +91,10 @@ func (d *BasicDropdown) Set(value string) bool { */ func NewBasicDropdown(p *gui.Node, name string) *BasicDropdown { - d := BasicDropdown { + d := BasicDropdown{ parent: p, - name: name, - ready: false, + name: name, + ready: false, } // various timeout settings diff --git a/basicEntry.go b/basicEntry.go index 29a0dd8..d20fe18 100644 --- a/basicEntry.go +++ b/basicEntry.go @@ -1,26 +1,26 @@ /* - A Labeled Single Line Entry widget: +A Labeled Single Line Entry widget: - ----------------------------- - | | | - | Food: | | - | | | - ----------------------------- +----------------------------- +| | | +| Food: | | +| | | +----------------------------- */ package gadgets -import ( +import ( + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type BasicEntry struct { - parent *gui.Node // parent widget - l *gui.Node // label widget - v *gui.Node // value widget + parent *gui.Node // parent widget + l *gui.Node // label widget + v *gui.Node // value widget - value string - label string + value string + label string Custom func() } @@ -42,14 +42,14 @@ func (n *BasicEntry) Set(value string) *BasicEntry { func (n *BasicEntry) Enable() { log.Log(INFO, "BasicEntry.Enable()") - if (n.v != nil) { + if n.v != nil { n.v.Enable() } } func (n *BasicEntry) Disable() { log.Log(INFO, "BasicEntry.Disable()") - if (n.v != nil) { + if n.v != nil { n.v.Disable() } } @@ -65,9 +65,9 @@ func (n *BasicEntry) SetLabel(s string) *BasicEntry { } func NewBasicEntry(p *gui.Node, name string) *BasicEntry { - d := BasicEntry { + d := BasicEntry{ parent: p, - value: "", + value: "", } // various timeout settings diff --git a/basicLabel.go b/basicLabel.go index 468c44e..36915e2 100644 --- a/basicLabel.go +++ b/basicLabel.go @@ -1,28 +1,28 @@ /* - A Labeled label: +A Labeled label: - ----------------------------- - | | | - | Food: | Apple | - | | | - ----------------------------- +----------------------------- +| | | +| Food: | Apple | +| | | +----------------------------- */ package gadgets -import ( +import ( + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type Node gui.Node type BasicLabel struct { - p *gui.Node // parent widget - l *gui.Node // label widget - v *gui.Node // value widget + p *gui.Node // parent widget + l *gui.Node // label widget + v *gui.Node // value widget - value string - label string + value string + label string Custom func() } @@ -45,8 +45,8 @@ func (n *BasicLabel) Set(value string) *BasicLabel { func (ngui *Node) NewBasicLabel(name string) *BasicLabel { var n *gui.Node n = (*gui.Node)(ngui) - d := BasicLabel { - p: n, + d := BasicLabel{ + p: n, value: "", } diff --git a/basicWindow.go b/basicWindow.go index 8e511cf..cc382b8 100644 --- a/basicWindow.go +++ b/basicWindow.go @@ -1,31 +1,31 @@ /* - A Standard Window +A Standard Window */ package gadgets -import ( +import ( + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type BasicWindow struct { - ready bool - hidden bool + ready bool + hidden bool vertical bool - title string + title string - parent *gui.Node - win *gui.Node // window widget - box *gui.Node // box + parent *gui.Node + win *gui.Node // window widget + box *gui.Node // box Custom func() } func NewBasicWindow(parent *gui.Node, title string) *BasicWindow { var w *BasicWindow - w = &BasicWindow { - parent: parent, - title: title, + w = &BasicWindow{ + parent: parent, + title: title, vertical: false, } log.Warn("NewBasicWindow() END") @@ -34,21 +34,27 @@ func NewBasicWindow(parent *gui.Node, title string) *BasicWindow { } func (w *BasicWindow) Show() { - if ! w.Ready() {return} + if !w.Ready() { + return + } w.win.Show() w.hidden = false return } func (w *BasicWindow) Hide() { - if ! w.Ready() {return} + if !w.Ready() { + return + } w.win.Hide() w.hidden = true return } func (w *BasicWindow) Toggle() { - if ! w.Ready() {return} + if !w.Ready() { + return + } if w.hidden { w.Show() w.hidden = false @@ -60,14 +66,18 @@ func (w *BasicWindow) Toggle() { } func (w *BasicWindow) Title(title string) { - if ! w.Ready() {return} + if !w.Ready() { + return + } w.win.SetText(title) return } // sets this window to run os.Exit() func (w *BasicWindow) StandardExit() { - if ! w.Ready() {return} + if !w.Ready() { + return + } w.win.Custom = func() { log.Warn("BasicWindow.Custom() closed. TODO: handle this", w.title) log.Warn("BasicWindow.Custom() closed. handled properly?", w.title) @@ -81,21 +91,31 @@ func (w *BasicWindow) StandardExit() { // Returns true if initialized func (w *BasicWindow) Initialized() bool { - if w == nil {return false} - if w.parent == nil {return false} + if w == nil { + return false + } + if w.parent == nil { + return false + } return true } // Returns true if the status is valid func (w *BasicWindow) Ready() bool { - if ! w.Initialized() {return false} - if ! w.parent.Ready() {return false} + if !w.Initialized() { + return false + } + if !w.parent.Ready() { + return false + } return w.ready } func (w *BasicWindow) Box() *gui.Node { - if ! w.Initialized() {return nil} - if (w.win == nil) { + if !w.Initialized() { + return nil + } + if w.win == nil { w.Draw() } return w.box @@ -103,20 +123,26 @@ func (w *BasicWindow) Box() *gui.Node { func (w *BasicWindow) Vertical() { log.Warn("BasicWindow() Vertical() START w.vertical =", w.vertical, w.title) - if w == nil {return} + if w == nil { + return + } w.vertical = true log.Warn("BasicWindow() Vertical() END w.vertical =", w.vertical, w.title) } func (w *BasicWindow) Horizontal() { log.Warn("BasicWindow() Horizontal() START w.vertical =", w.vertical, w.title) - if w == nil {return} + if w == nil { + return + } w.vertical = false log.Warn("BasicWindow() Horizontal() END w.vertical =", w.vertical, w.title) } func (w *BasicWindow) Make() { - if ! w.Initialized() {return} + if !w.Initialized() { + return + } if w.win != nil { log.Warn("BasicWindow.Make() window was already created") return @@ -148,7 +174,9 @@ func (w *BasicWindow) Make() { } func (w *BasicWindow) TestDraw() { - if ! w.Initialized() {return} + if !w.Initialized() { + return + } if w.win == nil { log.Warn("BasicWindow.TestDraw() can't draw on window == nil") w.Make() @@ -158,7 +186,9 @@ func (w *BasicWindow) TestDraw() { } func (w *BasicWindow) Draw() { - if ! w.Initialized() {return} + if !w.Initialized() { + return + } if w.win != nil { log.Warn("BasicWindow.Draw() window was already created") w.Make() diff --git a/durationSlider.go b/durationSlider.go index cceb65b..0824b63 100644 --- a/durationSlider.go +++ b/durationSlider.go @@ -4,34 +4,34 @@ package gadgets -import ( +import ( "fmt" "time" + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type Duration struct { - p *gui.Node // parent widget - l *gui.Node // label widget - s *gui.Node // slider widget + p *gui.Node // parent widget + l *gui.Node // label widget + s *gui.Node // slider widget - Label string - Low time.Duration - High time.Duration - Duration time.Duration + Label string + Low time.Duration + High time.Duration + Duration time.Duration - Custom func() + Custom func() } func (n *Duration) Set(d time.Duration) { var timeRange, step, offset time.Duration - if (d > n.High) { + if d > n.High { d = n.High } - if (d < n.Low) { + if d < n.Low { d = n.Low } @@ -41,7 +41,7 @@ func (n *Duration) Set(d time.Duration) { // figure out the integer offset for the Slider GUI Widget timeRange = n.High - n.Low step = timeRange / 1000 - if (step == 0) { + if step == 0 { log.Log(INFO, "duration.Set() division by step == 0", n.Low, n.High, timeRange, step) n.s.Set(0) return @@ -55,22 +55,22 @@ func (n *Duration) Set(d time.Duration) { } func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.Duration) *Duration { - d := Duration { - p: n, + d := Duration{ + p: n, Label: label, - High: high, - Low: low, + High: high, + Low: low, } // various timeout settings d.l = n.NewLabel(label) d.s = n.NewSlider(label, 0, 1000) - d.s.Custom = func () { - d.Duration = low + (high - low) * time.Duration(d.s.Int()) / 1000 + d.s.Custom = func() { + d.Duration = low + (high-low)*time.Duration(d.s.Int())/1000 log.Println("d.Duration =", d.Duration) s := fmt.Sprintf("%s (%v)", d.Label, d.Duration) d.l.SetText(s) - if (d.Custom != nil) { + if d.Custom != nil { d.Custom() } } diff --git a/logFlag.go b/logFlag.go index 9aa9d54..38cf77a 100644 --- a/logFlag.go +++ b/logFlag.go @@ -1,29 +1,29 @@ /* - A log.Flag +A log.Flag - ----------------------------------------------- - | | | - | [ X ] | INFO (controls log.Info() | - | | | - ----------------------------------------------- +----------------------------------------------- +| | | +| [ X ] | INFO (controls log.Info() | +| | | +----------------------------------------------- */ package gadgets -import ( +import ( + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type LogFlag struct { - p *gui.Node // parent widget - c *gui.Node // checkbox widget - lf *log.LogFlag + p *gui.Node // parent widget + c *gui.Node // checkbox widget + lf *log.LogFlag - Name string + Name string Subsystem string - Desc string - Default bool - b bool + Desc string + Default bool + b bool Custom func() } @@ -45,7 +45,7 @@ func (f *LogFlag) SetDefault() { } func NewLogFlag(n *gui.Node, lf *log.LogFlag) *LogFlag { - f := LogFlag { + f := LogFlag{ p: n, } f.Name = lf.GetName() diff --git a/oneLiner.go b/oneLiner.go index 81e2a8b..9b95d60 100644 --- a/oneLiner.go +++ b/oneLiner.go @@ -1,23 +1,23 @@ /* - A Labeled label: +A Labeled label: - ----------------------------- - | | | - | Food: | Apple | - | | | - ----------------------------- +----------------------------- +| | | +| Food: | Apple | +| | | +----------------------------- */ package gadgets -import ( +import ( + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) type OneLiner struct { - p *gui.Node // parent widget - l *gui.Node // label widget - v *gui.Node // value widget + p *gui.Node // parent widget + l *gui.Node // label widget + v *gui.Node // value widget Custom func() } @@ -34,7 +34,7 @@ func (n *OneLiner) SetText(s string) *OneLiner { func (n *OneLiner) SetLabel(value string) *OneLiner { log.Log(INFO, "OneLiner.SetLabel() =", value) - if (n.l != nil) { + if n.l != nil { n.l.Set(value) } return n @@ -42,20 +42,20 @@ func (n *OneLiner) SetLabel(value string) *OneLiner { func (n *OneLiner) Enable() { log.Log(INFO, "OneLiner.Enable()") - if (n.v != nil) { + if n.v != nil { n.v.Show() } } func (n *OneLiner) Disable() { log.Log(INFO, "OneLiner.Disable()") - if (n.v != nil) { + if n.v != nil { n.v.Hide() } } func NewOneLiner(n *gui.Node, label string) *OneLiner { - d := OneLiner { + d := OneLiner{ p: n, }