summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--debugWindow.go4
-rwxr-xr-xexamples/buttons/buttonpluginbin6062120 -> 0 bytes
-rw-r--r--examples/buttons/log.go20
-rw-r--r--gadgets/README.md15
-rw-r--r--gadgets/basicLabel.go60
-rw-r--r--gadgets/durationSlider.go79
-rw-r--r--gadgets/oneLiner.go56
-rw-r--r--structs.go17
9 files changed, 250 insertions, 9 deletions
diff --git a/README.md b/README.md
index 775be32..0825db3 100644
--- a/README.md
+++ b/README.md
@@ -93,10 +93,10 @@ hopefully also things like libSDL, faiface/pixel, slint
Useful links and other
external things which might be useful
-[Wikipedia Graphical widget]: [https://en.wikipedia.org/wiki/Graphical_widget](https://en.wikipedia.org/wiki/Graphical_widget)
-[Github mirror]: [https://github.com/witorg/gui](https://github.com/witorg/gui)
-[Federated git pull]: [https://github.com/forgefed/forgefed](https://github.com/forgefed/forgefed)
-[GO Style Guide]: [https://google.github.io/styleguide/go/index](https://google.github.io/styleguide/go/index)
+* Wikipedia Graphical widget - [https://en.wikipedia.org/wiki/Graphical_widget](https://en.wikipedia.org/wiki/Graphical_widget)
+* Github mirror - [https://github.com/witorg/gui](https://github.com/witorg/gui)
+* Federated git pull - [https://github.com/forgefed/forgefed](https://github.com/forgefed/forgefed)
+* GO Style Guide - [https://google.github.io/styleguide/go/index](https://google.github.io/styleguide/go/index)
```go
* [Wikipedia Graphical widget]
diff --git a/debugWindow.go b/debugWindow.go
index cc0c8a8..ed1804e 100644
--- a/debugWindow.go
+++ b/debugWindow.go
@@ -98,6 +98,10 @@ func (n *Node) DebugTab(title string) *Node {
me.rootNode.LoadToolkit("gocui")
})
+ g2.NewButton("load toolkit 'andlabs'", func () {
+ me.rootNode.LoadToolkit("andlabs")
+ })
+
return newN
}
diff --git a/examples/buttons/buttonplugin b/examples/buttons/buttonplugin
deleted file mode 100755
index 3f4dee3..0000000
--- a/examples/buttons/buttonplugin
+++ /dev/null
Binary files differ
diff --git a/examples/buttons/log.go b/examples/buttons/log.go
index bf3d1a5..f8279af 100644
--- a/examples/buttons/log.go
+++ b/examples/buttons/log.go
@@ -24,6 +24,25 @@ var f2 *os.File
var err error
*/
+/* from gocron:
+
+// DefaultLogger is used by Cron if none is specified.
+var DefaultLogger Logger = PrintfLogger(log.New(os.Stdout, "cron: ", log.LstdFlags))
+
+// DiscardLogger can be used by callers to discard all log messages.
+var DiscardLogger Logger = PrintfLogger(log.New(ioutil.Discard, "", 0))
+
+// Logger is the interface used in this package for logging, so that any backend
+// can be plugged in. It is a subset of the github.com/go-logr/logr interface.
+type Logger interface {
+ // Info logs routine messages about cron's operation.
+ Info(msg string, keysAndValues ...interface{})
+ // Error logs an error condition.
+ Error(err error, msg string, keysAndValues ...interface{})
+}
+
+*/
+
func init() {
arg.MustParse(&args)
fmt.Println(args.Foo, args.Bar, args.User)
@@ -34,6 +53,7 @@ func init() {
log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
/*
+ // from: https://github.com/robfig/cron/blob/master/logger.go
log.Println()
log.Println("STDOUT is now at /tmp/guilogfile")
log.Println("STDOUT is now at /tmp/guilogfile")
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
+}
diff --git a/structs.go b/structs.go
index 5dc2d5f..b9d4d89 100644
--- a/structs.go
+++ b/structs.go
@@ -61,8 +61,13 @@ type Node struct {
WidgetType toolkit.WidgetType
+ // for NewLabel("hello"), Text = 'hello'
Text string // what is visable to the user
- Name string // a name useful for programming
+
+ // for NewLabel("hello"), if Name = 'HELLO'
+ // this can programatically identify the widget
+ // The name must be unique
+ Name string // a name useful for debugging
// used for Windows in toolkits measured in pixels
width int
@@ -72,19 +77,21 @@ type Node struct {
X int
Y int
- // the grid max width and height
- // ignore max height when there is no space left?
+ // the grid widget max width and height
+ // the max height can be implemented in the toolkit plugin
+ // to restrict the number of rows to display
W int
H int
+
// where the next widget should be put in this grid
NextW int
NextH int
- // if this widget is in a grid, this is the position
+ // if this widget is in a grid, this is the position of a widget
AtW int
AtH int
- // used for values
+ // the current widget value.
I int
S string
B bool