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

@ -1,19 +1,19 @@
/*
A Labeled Combobox widget:
A Labeled Combobox widget:
-----------------------------
| | |
| Food: | <dropdown> |
| | |
-----------------------------
-----------------------------
| | |
| Food: | <dropdown> |
| | |
-----------------------------
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 (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type BasicCombobox struct {
@ -28,47 +28,67 @@ type BasicCombobox struct {
}
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 {
d := BasicCombobox{
parent: p,
progname: label,
ready: false,

View File

@ -1,19 +1,19 @@
/*
A Labeled Dropdown widget:
A Labeled Dropdown widget:
-----------------------------
| | |
| Food: | <dropdown> |
| | |
-----------------------------
-----------------------------
| | |
| Food: | <dropdown> |
| | |
-----------------------------
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 (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type BasicDropdown struct {
@ -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,7 +91,7 @@ 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,

View File

@ -1,17 +1,17 @@
/*
A Labeled Single Line Entry widget:
A Labeled Single Line Entry widget:
-----------------------------
| | |
| Food: | <type here> |
| | |
-----------------------------
-----------------------------
| | |
| Food: | <type here> |
| | |
-----------------------------
*/
package gadgets
import (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type BasicEntry struct {
@ -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,7 +65,7 @@ func (n *BasicEntry) SetLabel(s string) *BasicEntry {
}
func NewBasicEntry(p *gui.Node, name string) *BasicEntry {
d := BasicEntry {
d := BasicEntry{
parent: p,
value: "",
}

View File

@ -1,17 +1,17 @@
/*
A Labeled label:
A Labeled label:
-----------------------------
| | |
| Food: | Apple |
| | |
-----------------------------
-----------------------------
| | |
| Food: | Apple |
| | |
-----------------------------
*/
package gadgets
import (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type Node gui.Node
@ -45,7 +45,7 @@ func (n *BasicLabel) Set(value string) *BasicLabel {
func (ngui *Node) NewBasicLabel(name string) *BasicLabel {
var n *gui.Node
n = (*gui.Node)(ngui)
d := BasicLabel {
d := BasicLabel{
p: n,
value: "",
}

View File

@ -1,11 +1,11 @@
/*
A Standard Window
A Standard Window
*/
package gadgets
import (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type BasicWindow struct {
@ -23,7 +23,7 @@ type BasicWindow struct {
func NewBasicWindow(parent *gui.Node, title string) *BasicWindow {
var w *BasicWindow
w = &BasicWindow {
w = &BasicWindow{
parent: parent,
title: title,
vertical: false,
@ -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()

View File

@ -8,8 +8,8 @@ import (
"fmt"
"time"
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type Duration struct {
@ -28,10 +28,10 @@ type Duration struct {
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,7 +55,7 @@ func (n *Duration) Set(d time.Duration) {
}
func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.Duration) *Duration {
d := Duration {
d := Duration{
p: n,
Label: label,
High: high,
@ -65,12 +65,12 @@ func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.D
// 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()
}
}

View File

@ -1,17 +1,17 @@
/*
A log.Flag
A log.Flag
-----------------------------------------------
| | |
| [ X ] | INFO (controls log.Info() |
| | |
-----------------------------------------------
-----------------------------------------------
| | |
| [ X ] | INFO (controls log.Info() |
| | |
-----------------------------------------------
*/
package gadgets
import (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type LogFlag struct {
@ -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()

View File

@ -1,17 +1,17 @@
/*
A Labeled label:
A Labeled label:
-----------------------------
| | |
| Food: | Apple |
| | |
-----------------------------
-----------------------------
| | |
| Food: | Apple |
| | |
-----------------------------
*/
package gadgets
import (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/gui/gui"
)
type OneLiner struct {
@ -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,
}