commit 7f6059a8e0f83bb4b450c1264195f08fe1280f05 Author: Jeff Carr Date: Mon Jan 1 16:19:40 2024 -0600 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..66c2a4f --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# gadgets + +Package gadgets are special collections of widgets + +Things to avoid or keep in mind: Also Features these might enable: + +```go +* These should never bypass the binary tree +* Hide complexity internally here +* These might require corresponding toolkit implementations? +* These might allow unique/good corresponding toolkit implementations (date/time selection?) + +## Warning + +Doing this / adding these might be a really bad idea that I will regret later diff --git a/basicCombobox.go b/basicCombobox.go new file mode 100644 index 0000000..1b60000 --- /dev/null +++ b/basicCombobox.go @@ -0,0 +1,79 @@ +/* + A Labeled Combobox widget: + + ----------------------------- + | | | + | Food: | | + | | | + ----------------------------- + + The user can then edit the dropdown field and type anything into it +*/ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" +) + +type BasicCombobox struct { + ready bool + name string + + parent *gui.Node // parent widget + l *gui.Node // label widget + d *gui.Node // dropdown widget + + value string + label string + + Custom func() +} + +func (d *BasicCombobox) Get() string { + if ! d.Ready() {return ""} + return d.value +} + +// Returns true if the status is valid +func (d *BasicCombobox) Ready() bool { + if d == nil {return false} + return d.ready +} + +func (d *BasicCombobox) Add(value string) { + if ! d.Ready() {return} + log.Println("BasicCombobox.Add() =", value) + d.d.AddDropdownName(value) + return +} + +func (d *BasicCombobox) Set(value string) bool { + if ! d.Ready() {return false} + log.Println("BasicCombobox.Set() =", value) + d.d.SetText(value) + d.value = value + return true +} + +func NewBasicCombobox(p *gui.Node, name string) *BasicCombobox { + d := BasicCombobox { + parent: p, + name: name, + ready: false, + } + + // various timeout settings + d.l = p.NewLabel(name) + d.d = p.NewCombobox("") + d.d.Custom = func() { + d.value = d.Get() + log.Println("BasicCombobox.Custom() user changed value to =", d.value) + if d.Custom != nil { + d.Custom() + } + } + + d.ready = true + return &d +} diff --git a/basicDropdown.go b/basicDropdown.go new file mode 100644 index 0000000..2279ee3 --- /dev/null +++ b/basicDropdown.go @@ -0,0 +1,79 @@ +/* + A Labeled Dropdown widget: + + ----------------------------- + | | | + | Food: | | + | | | + ----------------------------- + + This being a 'Basic Dropdown', the dropdown names must be unique +*/ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" +) + +type BasicDropdown struct { + ready bool + name string + + parent *gui.Node // parent widget + l *gui.Node // label widget + d *gui.Node // dropdown widget + + value string + label string + + Custom func() +} + +func (d *BasicDropdown) Get() string { + if ! d.Ready() {return ""} + return d.d.GetText() +} + +// Returns true if the status is valid +func (d *BasicDropdown) Ready() bool { + if d == nil {return false} + return d.ready +} + +func (d *BasicDropdown) Add(value string) { + if ! d.Ready() {return} + log.Println("BasicDropdown.Set() =", value) + d.d.AddDropdownName(value) + return +} + +func (d *BasicDropdown) Set(value string) bool { + if ! d.Ready() {return false} + log.Println("BasicDropdown.Set() =", value) + d.l.SetText(value) + d.value = value + return true +} + +func NewBasicDropdown(p *gui.Node, name string) *BasicDropdown { + d := BasicDropdown { + parent: p, + name: name, + ready: false, + } + + // various timeout settings + d.l = p.NewLabel(name) + d.d = p.NewDropdown("") + d.d.Custom = func() { + d.value = d.Get() + log.Println("BasicDropdown.Custom() user changed value to =", d.value) + if d.Custom != nil { + d.Custom() + } + } + + d.ready = true + return &d +} diff --git a/basicEntry.go b/basicEntry.go new file mode 100644 index 0000000..e95d17d --- /dev/null +++ b/basicEntry.go @@ -0,0 +1,56 @@ +/* + A Labeled Single Line Entry widget: + + ----------------------------- + | | | + | Food: | | + | | | + ----------------------------- +*/ +package gadgets + +import ( + "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 + + 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/basicLabel.go b/basicLabel.go new file mode 100644 index 0000000..1cd6d3a --- /dev/null +++ b/basicLabel.go @@ -0,0 +1,60 @@ +/* + A Labeled label: + + ----------------------------- + | | | + | Food: | Apple | + | | | + ----------------------------- +*/ +package gadgets + +import ( + "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 + + value string + label string + + Custom func() +} + +func (n *BasicLabel) Get() string { + return n.value +} + +func (n *BasicLabel) Set(value string) *BasicLabel { + log.Println("BasicLabel.Set() =", value) + if (n.v != nil) { + n.v.Set(value) + } + n.value = value + return n +} + +func (ngui *Node) NewBasicLabel(name string) *BasicLabel { + var n *gui.Node + n = (*gui.Node)(ngui) + d := BasicLabel { + p: n, + value: "", + } + + // various timeout settings + d.l = n.NewLabel(name) + d.v = n.NewLabel("") + d.v.Custom = func() { + d.value = d.v.S + log.Println("BasicLabel.Custom() user changed value to =", d.value) + } + + return &d +} diff --git a/durationSlider.go b/durationSlider.go new file mode 100644 index 0000000..6ae1e00 --- /dev/null +++ b/durationSlider.go @@ -0,0 +1,79 @@ +/* + A slider that goes between a High and Low time +*/ + +package gadgets + +import ( + "log" + "fmt" + "time" + + "go.wit.com/gui/gui" +) + +type Duration struct { + 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 + + Custom func() +} + +func (n *Duration) Set(d time.Duration) { + var timeRange, step, offset time.Duration + + if (d > n.High) { + d = n.High + } + if (d < n.Low) { + d = n.Low + } + + // set the duration + n.Duration = d + + // figure out the integer offset for the Slider GUI Widget + timeRange = n.High - n.Low + step = timeRange / 1000 + if (step == 0) { + log.Println("duration.Set() division by step == 0", n.Low, n.High, timeRange, step) + n.s.Set(0) + return + } + offset = d - n.Low + i := int(offset / step) + log.Println("duration.Set() =", n.Low, n.High, d, "i =", i) + n.s.I = i + n.s.Set(i) + n.s.Custom() +} + +func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.Duration) *Duration { + d := Duration { + p: n, + Label: label, + 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.I) / 1000 + log.Println("d.Duration =", d.Duration) + s := fmt.Sprintf("%s (%v)", d.Label, d.Duration) + d.l.SetText(s) + if (d.Custom != nil) { + d.Custom() + } + } + + return &d +} diff --git a/logSettings.go b/logSettings.go new file mode 100644 index 0000000..a496ca5 --- /dev/null +++ b/logSettings.go @@ -0,0 +1,72 @@ +package gadgets + +import ( + "go.wit.com/log" + "go.wit.com/gui/gui" +) + +var myLogGui *LogSettings + +type LogSettings struct { + ready bool + hidden bool + err error + + parent *gui.Node // should be the root of the 'gui' package binary tree + window *gui.Node // our window for displaying the log package settings + group *gui.Node // + grid *gui.Node // + + // Primary Directives + status *OneLiner + summary *OneLiner +} + +// This is initializes the main DO object +// You can only have one of these +func NewLogSettings(p *gui.Node) *LogSettings { + if myLogGui != nil {return myLogGui} + myLogGui = new(LogSettings) + myLogGui.parent = p + + myLogGui.ready = false + + myLogGui.window = p.NewWindow("Log Settings") + + // make a group label and a grid + myLogGui.group = myLogGui.window.NewGroup("droplets:").Pad() + myLogGui.grid = myLogGui.group.NewGrid("grid", 2, 1).Pad() + + myLogGui.ready = true + myLogGui.Hide() + return myLogGui +} + +// Returns true if the status is valid +func (d *LogSettings) Ready() bool { + if d == nil {return false} + return d.ready +} + +func (d *LogSettings) Show() { + if ! d.Ready() {return} + log.Info("LogSettings.Show() window") + if d.hidden { + d.window.Show() + } + d.hidden = false +} + +func (d *LogSettings) Hide() { + if ! d.Ready() {return} + log.Info("LogSettings.Hide() window") + if ! d.hidden { + d.window.Hide() + } + d.hidden = true +} + +func (d *LogSettings) Update() bool { + if ! d.Ready() {return false} + return true +} diff --git a/oneLiner.go b/oneLiner.go new file mode 100644 index 0000000..faf0ece --- /dev/null +++ b/oneLiner.go @@ -0,0 +1,56 @@ +/* + A Labeled label: + + ----------------------------- + | | | + | Food: | Apple | + | | | + ----------------------------- +*/ +package gadgets + +import ( + "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 + + value string + label string + + Custom func() +} + +func (n *OneLiner) Get() string { + return n.value +} + +func (n *OneLiner) Set(value string) *OneLiner { + log.Println("OneLiner.Set() =", value) + if (n.v != nil) { + n.v.Set(value) + } + n.value = value + return n +} + +func NewOneLiner(n *gui.Node, name string) *OneLiner { + d := OneLiner { + p: n, + value: "", + } + + // various timeout settings + d.l = n.NewLabel(name) + d.v = n.NewLabel("") + d.v.Custom = func() { + d.value = d.v.S + log.Println("OneLiner.Custom() user changed value to =", d.value) + } + + return &d +}