summaryrefslogtreecommitdiff
path: root/gadgets
diff options
context:
space:
mode:
Diffstat (limited to 'gadgets')
-rw-r--r--gadgets/README.md15
-rw-r--r--gadgets/basicLabel.go60
-rw-r--r--gadgets/durationSlider.go79
-rw-r--r--gadgets/oneLiner.go56
4 files changed, 210 insertions, 0 deletions
diff --git a/gadgets/README.md b/gadgets/README.md
new file mode 100644
index 0000000..66c2a4f
--- /dev/null
+++ b/gadgets/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/gadgets/basicLabel.go b/gadgets/basicLabel.go
new file mode 100644
index 0000000..a952912
--- /dev/null
+++ b/gadgets/basicLabel.go
@@ -0,0 +1,60 @@
+/*
+ A Labeled label:
+
+ -----------------------------
+ | | |
+ | Food: | Apple |
+ | | |
+ -----------------------------
+*/
+package gadgets
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/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/gadgets/durationSlider.go b/gadgets/durationSlider.go
new file mode 100644
index 0000000..6f81214
--- /dev/null
+++ b/gadgets/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"
+)
+
+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/gadgets/oneLiner.go b/gadgets/oneLiner.go
new file mode 100644
index 0000000..529cec3
--- /dev/null
+++ b/gadgets/oneLiner.go
@@ -0,0 +1,56 @@
+/*
+ A Labeled label:
+
+ -----------------------------
+ | | |
+ | Food: | Apple |
+ | | |
+ -----------------------------
+*/
+package gadgets
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/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
+}