lots of syntax changes

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-18 05:04:18 -06:00
parent 76d6da5505
commit a8d95fef8d
8 changed files with 222 additions and 161 deletions

View File

@ -12,8 +12,8 @@
package gadgets package gadgets
import ( import (
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type BasicCombobox struct { type BasicCombobox struct {
@ -28,41 +28,61 @@ type BasicCombobox struct {
} }
func (d *BasicCombobox) String() string { func (d *BasicCombobox) String() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
return d.d.String() return d.d.String()
} }
func (d *BasicCombobox) SetText(s string) { func (d *BasicCombobox) SetText(s string) {
if ! d.Ready() {return} if !d.Ready() {
return
}
d.d.SetText(s) d.d.SetText(s)
} }
// Returns true if the status is valid // Returns true if the status is valid
func (d *BasicCombobox) Ready() bool { func (d *BasicCombobox) Ready() bool {
if d == nil {return false} if d == nil {
return false
}
return d.ready return d.ready
} }
func (d *BasicCombobox) Enable() { func (d *BasicCombobox) Enable() {
if d == nil {return} if d == nil {
if d.d == nil {return} return
}
if d.d == nil {
return
}
d.d.Enable() d.d.Enable()
} }
func (d *BasicCombobox) Disable() { func (d *BasicCombobox) Disable() {
if d == nil {return} if d == nil {
if d.d == nil {return} return
}
if d.d == nil {
return
}
d.d.Disable() d.d.Disable()
} }
func (d *BasicCombobox) SetTitle(name string) { func (d *BasicCombobox) SetTitle(name string) {
if d == nil {return} if d == nil {
if d.d == nil {return} return
}
if d.d == nil {
return
}
d.d.SetText(name) d.d.SetText(name)
} }
func (d *BasicCombobox) AddText(s string) { func (d *BasicCombobox) AddText(s string) {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Log(INFO, "BasicCombobox.Add() =", s) log.Log(INFO, "BasicCombobox.Add() =", s)
d.d.AddText(s) d.d.AddText(s)
} }

View File

@ -12,8 +12,8 @@
package gadgets package gadgets
import ( import (
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type BasicDropdown struct { type BasicDropdown struct {
@ -39,36 +39,47 @@ func (d *BasicDropdown) Get() string {
// Returns true if the status is valid // Returns true if the status is valid
func (d *BasicDropdown) Ready() bool { func (d *BasicDropdown) Ready() bool {
if d == nil {return false} if d == nil {
return false
}
return d.ready return d.ready
} }
func (d *BasicDropdown) AddText(s string) { func (d *BasicDropdown) AddText(s string) {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Log(INFO, "BasicDropdown.AddText() =", s) log.Log(INFO, "BasicDropdown.AddText() =", s)
d.d.AddText(s) d.d.AddText(s)
return return
} }
func (d *BasicDropdown) SetText(s string) { func (d *BasicDropdown) SetText(s string) {
if ! d.Ready() {return} if !d.Ready() {
return
}
log.Log(INFO, "BasicDropdown.SetText() =", s) log.Log(INFO, "BasicDropdown.SetText() =", s)
d.d.SetText(s) d.d.SetText(s)
return return
} }
func (d *BasicDropdown) String() string { func (d *BasicDropdown) String() string {
if ! d.Ready() {return ""} if !d.Ready() {
return ""
}
log.Log(INFO, "BasicDropdown.String()", d.d.String()) log.Log(INFO, "BasicDropdown.String()", d.d.String())
return d.d.String() return d.d.String()
} }
func (d *BasicDropdown) SetLabel(value string) bool { func (d *BasicDropdown) SetLabel(value string) bool {
if ! d.Ready() {return false} if !d.Ready() {
return false
}
log.Log(INFO, "BasicDropdown.SetLabel() =", value) log.Log(INFO, "BasicDropdown.SetLabel() =", value)
d.l.SetText(value) d.l.SetText(value)
return true return true
} }
/* /*
func (d *BasicDropdown) Set(value string) bool { func (d *BasicDropdown) Set(value string) bool {
if ! d.Ready() {return false} if ! d.Ready() {return false}

View File

@ -10,8 +10,8 @@
package gadgets package gadgets
import ( import (
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type BasicEntry struct { type BasicEntry struct {
@ -42,14 +42,14 @@ func (n *BasicEntry) Set(value string) *BasicEntry {
func (n *BasicEntry) Enable() { func (n *BasicEntry) Enable() {
log.Log(INFO, "BasicEntry.Enable()") log.Log(INFO, "BasicEntry.Enable()")
if (n.v != nil) { if n.v != nil {
n.v.Enable() n.v.Enable()
} }
} }
func (n *BasicEntry) Disable() { func (n *BasicEntry) Disable() {
log.Log(INFO, "BasicEntry.Disable()") log.Log(INFO, "BasicEntry.Disable()")
if (n.v != nil) { if n.v != nil {
n.v.Disable() n.v.Disable()
} }
} }

View File

@ -10,8 +10,8 @@
package gadgets package gadgets
import ( import (
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type Node gui.Node type Node gui.Node

View File

@ -4,8 +4,8 @@
package gadgets package gadgets
import ( import (
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type BasicWindow struct { type BasicWindow struct {
@ -34,21 +34,27 @@ func NewBasicWindow(parent *gui.Node, title string) *BasicWindow {
} }
func (w *BasicWindow) Show() { func (w *BasicWindow) Show() {
if ! w.Ready() {return} if !w.Ready() {
return
}
w.win.Show() w.win.Show()
w.hidden = false w.hidden = false
return return
} }
func (w *BasicWindow) Hide() { func (w *BasicWindow) Hide() {
if ! w.Ready() {return} if !w.Ready() {
return
}
w.win.Hide() w.win.Hide()
w.hidden = true w.hidden = true
return return
} }
func (w *BasicWindow) Toggle() { func (w *BasicWindow) Toggle() {
if ! w.Ready() {return} if !w.Ready() {
return
}
if w.hidden { if w.hidden {
w.Show() w.Show()
w.hidden = false w.hidden = false
@ -60,14 +66,18 @@ func (w *BasicWindow) Toggle() {
} }
func (w *BasicWindow) Title(title string) { func (w *BasicWindow) Title(title string) {
if ! w.Ready() {return} if !w.Ready() {
return
}
w.win.SetText(title) w.win.SetText(title)
return return
} }
// sets this window to run os.Exit() // sets this window to run os.Exit()
func (w *BasicWindow) StandardExit() { func (w *BasicWindow) StandardExit() {
if ! w.Ready() {return} if !w.Ready() {
return
}
w.win.Custom = func() { w.win.Custom = func() {
log.Warn("BasicWindow.Custom() closed. TODO: handle this", w.title) log.Warn("BasicWindow.Custom() closed. TODO: handle this", w.title)
log.Warn("BasicWindow.Custom() closed. handled properly?", w.title) log.Warn("BasicWindow.Custom() closed. handled properly?", w.title)
@ -81,21 +91,31 @@ func (w *BasicWindow) StandardExit() {
// Returns true if initialized // Returns true if initialized
func (w *BasicWindow) Initialized() bool { func (w *BasicWindow) Initialized() bool {
if w == nil {return false} if w == nil {
if w.parent == nil {return false} return false
}
if w.parent == nil {
return false
}
return true return true
} }
// Returns true if the status is valid // Returns true if the status is valid
func (w *BasicWindow) Ready() bool { func (w *BasicWindow) Ready() bool {
if ! w.Initialized() {return false} if !w.Initialized() {
if ! w.parent.Ready() {return false} return false
}
if !w.parent.Ready() {
return false
}
return w.ready return w.ready
} }
func (w *BasicWindow) Box() *gui.Node { func (w *BasicWindow) Box() *gui.Node {
if ! w.Initialized() {return nil} if !w.Initialized() {
if (w.win == nil) { return nil
}
if w.win == nil {
w.Draw() w.Draw()
} }
return w.box return w.box
@ -103,20 +123,26 @@ func (w *BasicWindow) Box() *gui.Node {
func (w *BasicWindow) Vertical() { func (w *BasicWindow) Vertical() {
log.Warn("BasicWindow() Vertical() START w.vertical =", w.vertical, w.title) log.Warn("BasicWindow() Vertical() START w.vertical =", w.vertical, w.title)
if w == nil {return} if w == nil {
return
}
w.vertical = true w.vertical = true
log.Warn("BasicWindow() Vertical() END w.vertical =", w.vertical, w.title) log.Warn("BasicWindow() Vertical() END w.vertical =", w.vertical, w.title)
} }
func (w *BasicWindow) Horizontal() { func (w *BasicWindow) Horizontal() {
log.Warn("BasicWindow() Horizontal() START w.vertical =", w.vertical, w.title) log.Warn("BasicWindow() Horizontal() START w.vertical =", w.vertical, w.title)
if w == nil {return} if w == nil {
return
}
w.vertical = false w.vertical = false
log.Warn("BasicWindow() Horizontal() END w.vertical =", w.vertical, w.title) log.Warn("BasicWindow() Horizontal() END w.vertical =", w.vertical, w.title)
} }
func (w *BasicWindow) Make() { func (w *BasicWindow) Make() {
if ! w.Initialized() {return} if !w.Initialized() {
return
}
if w.win != nil { if w.win != nil {
log.Warn("BasicWindow.Make() window was already created") log.Warn("BasicWindow.Make() window was already created")
return return
@ -148,7 +174,9 @@ func (w *BasicWindow) Make() {
} }
func (w *BasicWindow) TestDraw() { func (w *BasicWindow) TestDraw() {
if ! w.Initialized() {return} if !w.Initialized() {
return
}
if w.win == nil { if w.win == nil {
log.Warn("BasicWindow.TestDraw() can't draw on window == nil") log.Warn("BasicWindow.TestDraw() can't draw on window == nil")
w.Make() w.Make()
@ -158,7 +186,9 @@ func (w *BasicWindow) TestDraw() {
} }
func (w *BasicWindow) Draw() { func (w *BasicWindow) Draw() {
if ! w.Initialized() {return} if !w.Initialized() {
return
}
if w.win != nil { if w.win != nil {
log.Warn("BasicWindow.Draw() window was already created") log.Warn("BasicWindow.Draw() window was already created")
w.Make() w.Make()

View File

@ -8,8 +8,8 @@ import (
"fmt" "fmt"
"time" "time"
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type Duration struct { type Duration struct {
@ -28,10 +28,10 @@ type Duration struct {
func (n *Duration) Set(d time.Duration) { func (n *Duration) Set(d time.Duration) {
var timeRange, step, offset time.Duration var timeRange, step, offset time.Duration
if (d > n.High) { if d > n.High {
d = n.High d = n.High
} }
if (d < n.Low) { if d < n.Low {
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 // figure out the integer offset for the Slider GUI Widget
timeRange = n.High - n.Low timeRange = n.High - n.Low
step = timeRange / 1000 step = timeRange / 1000
if (step == 0) { if step == 0 {
log.Log(INFO, "duration.Set() division by step == 0", n.Low, n.High, timeRange, step) log.Log(INFO, "duration.Set() division by step == 0", n.Low, n.High, timeRange, step)
n.s.Set(0) n.s.Set(0)
return return
@ -70,7 +70,7 @@ func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.D
log.Println("d.Duration =", d.Duration) log.Println("d.Duration =", d.Duration)
s := fmt.Sprintf("%s (%v)", d.Label, d.Duration) s := fmt.Sprintf("%s (%v)", d.Label, d.Duration)
d.l.SetText(s) d.l.SetText(s)
if (d.Custom != nil) { if d.Custom != nil {
d.Custom() d.Custom()
} }
} }

View File

@ -10,8 +10,8 @@
package gadgets package gadgets
import ( import (
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type LogFlag struct { type LogFlag struct {

View File

@ -10,8 +10,8 @@
package gadgets package gadgets
import ( import (
"go.wit.com/gui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui/gui"
) )
type OneLiner struct { type OneLiner struct {
@ -34,7 +34,7 @@ func (n *OneLiner) SetText(s string) *OneLiner {
func (n *OneLiner) SetLabel(value string) *OneLiner { func (n *OneLiner) SetLabel(value string) *OneLiner {
log.Log(INFO, "OneLiner.SetLabel() =", value) log.Log(INFO, "OneLiner.SetLabel() =", value)
if (n.l != nil) { if n.l != nil {
n.l.Set(value) n.l.Set(value)
} }
return n return n
@ -42,14 +42,14 @@ func (n *OneLiner) SetLabel(value string) *OneLiner {
func (n *OneLiner) Enable() { func (n *OneLiner) Enable() {
log.Log(INFO, "OneLiner.Enable()") log.Log(INFO, "OneLiner.Enable()")
if (n.v != nil) { if n.v != nil {
n.v.Show() n.v.Show()
} }
} }
func (n *OneLiner) Disable() { func (n *OneLiner) Disable() {
log.Log(INFO, "OneLiner.Disable()") log.Log(INFO, "OneLiner.Disable()")
if (n.v != nil) { if n.v != nil {
n.v.Hide() n.v.Hide()
} }
} }