add 'gadgets'
attempt func (n *gui.Node) blah() definition better docs for pkg.go.dev how logging should work fix syntax links for pkg.go.dev Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d9c33a3475
commit
01ab0180f4
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
17
structs.go
17
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
|
||||
|
|
Loading…
Reference in New Issue