ready for version v0.7.4

start deprecating toolkit.Widget
    switch to variable name 'ParentId'
    use 'ActionType' and 'WidgetType'
    preliminary redraw()
    final definition of variables 'Name' and 'Text'
    more cleaning of the code
    remove lots of dumb code
    bind 'd' key press to dump out debugging info
    early color handling in gocui!

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-03-29 22:44:08 -05:00
parent ed128fa566
commit 9b79992b7b
57 changed files with 1116 additions and 577 deletions

View File

@ -123,11 +123,11 @@ Creates a window helpful for debugging this package
`func ExampleCatcher(f func())` `func ExampleCatcher(f func())`
### func [Indent](/debug.go#L130) ### func [Indent](/debug.go#L125)
`func Indent(b bool, a ...interface{})` `func Indent(b bool, a ...interface{})`
### func [InitPlugins](/main.go#L56) ### func [InitPlugins](/main.go#L58)
`func InitPlugins(names []string)` `func InitPlugins(names []string)`
@ -137,12 +137,16 @@ Creates a window helpful for debugging this package
loads and initializes a toolkit (andlabs/ui, gocui, etc) loads and initializes a toolkit (andlabs/ui, gocui, etc)
### func [Main](/main.go#L118) ### func [Main](/main.go#L121)
`func Main(f func())` `func Main(f func())`
This should not pass a function This should not pass a function
### func [Redraw](/redraw.go#L9)
`func Redraw(s string)`
### func [SetDebug](/debug.go#L28) ### func [SetDebug](/debug.go#L28)
`func SetDebug(s bool)` `func SetDebug(s bool)`
@ -151,11 +155,11 @@ This should not pass a function
`func SetFlag(s string, b bool)` `func SetFlag(s string, b bool)`
### func [ShowDebugValues](/debug.go#L86) ### func [ShowDebugValues](/debug.go#L79)
`func ShowDebugValues()` `func ShowDebugValues()`
### func [StandardExit](/main.go#L170) ### func [StandardExit](/main.go#L173)
`func StandardExit()` `func StandardExit()`
@ -244,11 +248,11 @@ func main() {
You get a window You get a window
``` ```
#### func [Start](/main.go#L96) #### func [Start](/main.go#L98)
`func Start() *Node` `func Start() *Node`
#### func [StartS](/main.go#L105) #### func [StartS](/main.go#L107)
`func StartS(name string) *Node` `func StartS(name string) *Node`

View File

@ -6,8 +6,9 @@ func (n *Node) NewButton(name string, custom func()) *Node {
newNode := n.New(name, toolkit.Button, custom) newNode := n.New(name, toolkit.Button, custom)
var a toolkit.Action var a toolkit.Action
a.Title = name a.Name = name
a.Type = toolkit.Add a.Text = name
a.ActionType = toolkit.Add
a.Callback = callback a.Callback = callback
newaction(&a, newNode, n) newaction(&a, newNode, n)

View File

@ -10,10 +10,9 @@ func (n *Node) NewCheckbox(name string) *Node {
newNode := n.New(name, toolkit.Checkbox, nil) newNode := n.New(name, toolkit.Checkbox, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
// a.Widget = &newNode.widget a.Name = name
// a.Where = &n.widget a.Text = name
// action(&a, newNode, n)
newaction(&a, newNode, n) newaction(&a, newNode, n)
return newNode return newNode

View File

@ -8,7 +8,7 @@
run: build run: build
# ./buttonplugin >/tmp/buttonplugin.log 2>&1 # ./buttonplugin >/tmp/buttonplugin.log 2>&1
./buttonplugin ./buttonplugin >/tmp/witgui.log.stderr 2>&1
build-release: build-release:
go get -v -u -x . go get -v -u -x .
@ -21,3 +21,7 @@ build:
update: update:
GO111MODULE="off" go get -v -u -x . GO111MODULE="off" go get -v -u -x .
log:
reset
tail -f /tmp/witgui.* /tmp/guilogfile

View File

@ -12,11 +12,7 @@ import (
var title string = "Demo Plugin Window" var title string = "Demo Plugin Window"
var outfile string = "/tmp/guilogfile" var outfile string = "/tmp/guilogfile"
// this is broken. delete this
func main() { func main() {
// this set the xterm and mate-terminal window title. maybe works generally?
fmt.Println("\033]0;" + title + "\007")
// time.Sleep(5 * time.Second) // time.Sleep(5 * time.Second)
// var w *gui.Node // var w *gui.Node
@ -54,27 +50,49 @@ var counter int = 5
// This creates a window // This creates a window
func buttonWindow() { func buttonWindow() {
var w, g *gui.Node var w, t, g, more, more2 *gui.Node
gui.Config.Title = title gui.Config.Title = title
gui.Config.Width = 640 gui.Config.Width = 640
gui.Config.Height = 480 gui.Config.Height = 480
w = gui.NewWindow() w = gui.NewWindow()
g = w.NewGroup("buttonGroup") t = w.NewTab("buttonTab")
g = t.NewGroup("buttonGroup")
g.NewButton("this app is old", func () { g.NewButton("this app is useful for plugin debuggin", func () {
}) })
g.NewLabel("STDOUT is set to: " + outfile) g.NewLabel("STDOUT is set to: " + outfile)
g.NewButton("hello", func () { g.NewButton("hello", func () {
log.Println("world") log.Println("world")
}) })
more = g.NewGroup("more")
g.NewButton("NewButton()", func () { g.NewButton("Load 'democui'", func () {
// this set the xterm and mate-terminal window title. maybe works generally?
fmt.Println("\033]0;" + title + "blah \007")
gui.StartS("democui")
})
g.NewButton("Redraw 'democui'", func () {
fmt.Println("\033]0;" + title + "blah2 \007")
gui.Redraw("democui")
})
g.NewButton("NewButton(more)", func () {
log.Println("new foobar 2. Adding button 'foobar 3'") log.Println("new foobar 2. Adding button 'foobar 3'")
name := "foobar " + strconv.Itoa(counter) name := "foobar " + strconv.Itoa(counter)
counter += 1 counter += 1
g.NewButton(name, func () { more.NewButton(name, func () {
log.Println("Got all the way to main() name =", name)
})
})
g.NewButton("NewButton(more2)", func () {
log.Println("new foobar 2. Adding button 'foobar 3'")
name := "foobar " + strconv.Itoa(counter)
counter += 1
more2.NewButton(name, func () {
log.Println("Got all the way to main() name =", name) log.Println("Got all the way to main() name =", name)
}) })
}) })
@ -83,30 +101,12 @@ func buttonWindow() {
log.Println("new foobar 2. Adding button 'foobar 3'") log.Println("new foobar 2. Adding button 'foobar 3'")
name := "neat " + strconv.Itoa(counter) name := "neat " + strconv.Itoa(counter)
counter += 1 counter += 1
g.NewGroup(name) more.NewGroup(name)
}) })
g.NewButton("gui.DebugWindow()", func () { g.NewButton("gui.DebugWindow()", func () {
gui.DebugWindow() gui.DebugWindow()
}) })
g.NewButton("LoadToolkit(andlabs)", func () { more2 = g.NewGroup("more2")
gui.LoadToolkit("andlabs")
})
g.NewButton("LoadToolkit(gocui)", func () {
gui.LoadToolkit("gocui")
})
g.NewButton("Init()", func () {
log.Println("gui.Init() is deprecated(?)")
//gui.Init()
})
g.NewButton("Main()", func () {
go gui.Main(func () {
w := gui.NewWindow()
w.NewGroup("buttonGroup")
})
})
} }

View File

@ -1,5 +1,6 @@
run: build run: build
GOTRACEBACK=all ./textbox --gui-debug # GOTRACEBACK=all ./textbox --gui-debug
GOTRACEBACK=all ./textbox --gui-debug >/tmp/witgui.log.stderr 2>&1
build-release: build-release:
go get -v -u -x . go get -v -u -x .

View File

@ -24,7 +24,7 @@ func main() {
arg.MustParse(&args) arg.MustParse(&args)
log.Println("Toolkit = ", args.Toolkit) log.Println("Toolkit = ", args.Toolkit)
gui.SetDebug(true) // gui.SetDebug(true)
// gui.InitPlugins([]string{"gocui"}) // gui.InitPlugins([]string{"gocui"})
// gui.InitPlugins([]string{"democui"}) // gui.InitPlugins([]string{"democui"})
gui.Main(initGUI) gui.Main(initGUI)

View File

@ -11,25 +11,25 @@ import (
func (n *Node) Show() { func (n *Node) Show() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Show a.ActionType = toolkit.Show
newaction(&a, n, nil) newaction(&a, n, nil)
} }
func (n *Node) Hide() { func (n *Node) Hide() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Hide a.ActionType = toolkit.Hide
newaction(&a, n, nil) newaction(&a, n, nil)
} }
func (n *Node) Enable() { func (n *Node) Enable() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Enable a.ActionType = toolkit.Enable
newaction(&a, n, nil) newaction(&a, n, nil)
} }
func (n *Node) Disable() { func (n *Node) Disable() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Disable a.ActionType = toolkit.Disable
newaction(&a, n, nil) newaction(&a, n, nil)
} }
@ -37,7 +37,7 @@ func (n *Node) Add(str string) {
log(debugGui, "gui.Add() value =", str) log(debugGui, "gui.Add() value =", str)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
a.S = str a.S = str
// a.Widget = &n.widget // a.Widget = &n.widget
// action(&a) // action(&a)
@ -48,7 +48,7 @@ func (n *Node) AddText(str string) {
log(debugChange, "AddText() value =", str) log(debugChange, "AddText() value =", str)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.AddText a.ActionType = toolkit.AddText
a.S = str a.S = str
// a.Widget = &n.widget // a.Widget = &n.widget
// action(&a) // action(&a)
@ -59,7 +59,7 @@ func (n *Node) SetText(str string) {
log(debugChange, "SetText() value =", str) log(debugChange, "SetText() value =", str)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.SetText a.ActionType = toolkit.SetText
a.S = str a.S = str
// a.Widget = &n.widget // a.Widget = &n.widget
// action(&a) // action(&a)
@ -80,7 +80,7 @@ func (n *Node) SetNext(x int, y int) {
func (n *Node) Set(val any) { func (n *Node) Set(val any) {
log(debugChange, "Set() value =", val) log(debugChange, "Set() value =", val)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Set a.ActionType = toolkit.Set
switch v := val.(type) { switch v := val.(type) {
case bool: case bool:
@ -100,7 +100,7 @@ func (n *Node) Set(val any) {
func (n *Node) AppendText(str string) { func (n *Node) AppendText(str string) {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.SetText a.ActionType = toolkit.SetText
tmp := n.widget.S + str tmp := n.widget.S + str
log(debugChange, "AppendText() value =", tmp) log(debugChange, "AppendText() value =", tmp)
a.S = tmp a.S = tmp
@ -160,25 +160,25 @@ func commonCallback(n *Node) {
func (n *Node) Margin() { func (n *Node) Margin() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Margin a.ActionType = toolkit.Margin
newaction(&a, n, nil) newaction(&a, n, nil)
} }
func (n *Node) Unmargin() { func (n *Node) Unmargin() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Unmargin a.ActionType = toolkit.Unmargin
newaction(&a, n, nil) newaction(&a, n, nil)
} }
func (n *Node) Pad() { func (n *Node) Pad() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Pad a.ActionType = toolkit.Pad
newaction(&a, n, nil) newaction(&a, n, nil)
} }
func (n *Node) Unpad() { func (n *Node) Unpad() {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Unpad a.ActionType = toolkit.Unpad
newaction(&a, n, nil) newaction(&a, n, nil)
} }

View File

@ -65,16 +65,9 @@ func SetFlag (s string, b bool) {
log(debugGui, "Can't set unknown flag", s) log(debugGui, "Can't set unknown flag", s)
} }
// send the flag to the toolkit
// n := Config.flag
// log(debugChange, "Set() toolkit flag", s, "to", b)
// n.widget.Action = "Set"
// n.widget.S = s
// n.widget.B = b
// send(nil, n) // set flag in the plugin
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.SetFlag a.ActionType = toolkit.Set
a.WidgetType = toolkit.Flag
a.S = s a.S = s
a.B = b a.B = b
// a.Widget = &newNode.widget // a.Widget = &newNode.widget
@ -109,9 +102,11 @@ func (n *Node) Dump(b bool) {
Indent(b, "Height = ", n.Height) Indent(b, "Height = ", n.Height)
Indent(b, "(X,Y) = ", n.X, n.Y) Indent(b, "(X,Y) = ", n.X, n.Y)
Indent(b, "Next (X,Y) = ", n.NextX, n.NextY) Indent(b, "Next (X,Y) = ", n.NextX, n.NextY)
/*
Indent(b, "Widget Name = ", n.widget.Name) Indent(b, "Widget Name = ", n.widget.Name)
Indent(b, "Widget Type = ", n.widget.Type) Indent(b, "Widget Type = ", n.widget.Type)
Indent(b, "Widget Id = ", n.widget.GetId()) Indent(b, "Widget Id = ", n.widget.Id)
*/
if (n.parent == nil) { if (n.parent == nil) {
Indent(b, "parent = nil") Indent(b, "parent = nil")

View File

@ -111,7 +111,7 @@ func DebugWidgetWindow(w *Node) {
activeWidget.Dump(true) activeWidget.Dump(true)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Dump a.ActionType = toolkit.Dump
newaction(&a, activeWidget, nil) newaction(&a, activeWidget, nil)
}) })
@ -123,64 +123,53 @@ func DebugWidgetWindow(w *Node) {
g = bugWidget.NewGroup("change things") g = bugWidget.NewGroup("change things")
g.NewButton("AddText()", func () { g.NewButton("AddText()", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.AddText a.ActionType = toolkit.AddText
a.S = activeLabelNewName.widget.S a.S = activeLabelNewName.widget.S
newaction(&a, activeWidget, nil) newaction(&a, activeWidget, nil)
}) })
g.NewButton("SetText()", func () { g.NewButton("SetText()", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.SetText a.ActionType = toolkit.SetText
a.S = activeLabelNewName.widget.S a.S = activeLabelNewName.widget.S
newaction(&a, activeWidget, nil) newaction(&a, activeWidget, nil)
}) })
g.NewButton("Margin()", func () { g.NewButton("Margin()", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Margin a.ActionType = toolkit.Margin
newaction(&a, activeWidget, nil) newaction(&a, activeWidget, nil)
}) })
g.NewButton("Unmargin()", func () { g.NewButton("Unmargin()", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Unmargin a.ActionType = toolkit.Unmargin
newaction(&a, activeWidget, nil) newaction(&a, activeWidget, nil)
}) })
g.NewButton("Pad()", func () { g.NewButton("Pad()", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Pad a.ActionType = toolkit.Pad
newaction(&a, activeWidget, nil) newaction(&a, activeWidget, nil)
}) })
g.NewButton("Unpad()", func () { g.NewButton("Unpad()", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Unpad a.ActionType = toolkit.Unpad
newaction(&a, activeWidget, nil) newaction(&a, activeWidget, nil)
}) })
g.NewButton("Move(junk)", func () { g.NewButton("Move(junk)", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Move a.ActionType = toolkit.Move
newaction(&a, activeWidget, activeJunk) newaction(&a, activeWidget, activeJunk)
}) })
g.NewButton("Delete()", func () { g.NewButton("Delete()", func () {
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Delete a.ActionType = toolkit.Delete
newaction(&a, activeWidget, activeJunk) newaction(&a, activeWidget, activeJunk)
}) })
g = bugWidget.NewGroup("not working?") g = bugWidget.NewGroup("not working?")
g.NewButton("Dump Widget Values()", func () {
log("activeWidget.B =", activeWidget.widget.B)
log("activeWidget.I =", activeWidget.widget.I)
log("activeWidget.S =", activeWidget.widget.S)
log("activeWidget.X =", activeWidget.widget.X)
log("activeWidget.Y =", activeWidget.widget.Y)
log("activeWidget.Width =", activeWidget.widget.Width)
log("activeWidget.Height =", activeWidget.widget.Height)
log("activeWidget.Margin =", activeWidget.widget.Margin)
log("activeWidget.Expand =", activeWidget.widget.Expand)
})
activeJunk = bugWidget.NewGroup("junk:") activeJunk = bugWidget.NewGroup("junk:")
activeJunk.NewLabel("test junk") activeJunk.NewLabel("test junk")
if (activeWidget == nil) { if (activeWidget == nil) {
setActiveWidget(Config.master) setActiveWidget(Config.rootNode)
} }
} }
@ -317,7 +306,7 @@ func (n *Node) debugAddWidgetButton() {
newNode := activeWidget.New(name, toolkit.Label, nil) newNode := activeWidget.New(name, toolkit.Label, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
newaction(&a, newNode, activeWidget) newaction(&a, newNode, activeWidget)
// return newNode // return newNode
// activeWidget.NewLabel(name) // activeWidget.NewLabel(name)

View File

@ -78,7 +78,7 @@ func (n *Node) DebugTab(title string) *Node {
g2.NewButton("Node.ListChildren(true)", func () { g2.NewButton("Node.ListChildren(true)", func () {
if (activeWidget == nil) { if (activeWidget == nil) {
activeWidget = Config.master activeWidget = Config.rootNode
} }
activeWidget.ListChildren(true) activeWidget.ListChildren(true)
}) })
@ -101,6 +101,10 @@ func (n *Node) DebugTab(title string) *Node {
StartS("democui") StartS("democui")
}) })
g2.NewButton("Redraw(democui)", func () {
Redraw("democui")
})
return newN return newN
} }
@ -123,7 +127,7 @@ func dropdownWindow(p *Node) {
} }
// var last = "" // var last = ""
for _, child := range Config.master.children { for _, child := range Config.rootNode.children {
log(debugGui, "\t\t", child.id, child.Width, child.Height, child.Name) log(debugGui, "\t\t", child.id, child.Width, child.Height, child.Name)
dd.AddDropdownName(child.Name) dd.AddDropdownName(child.Name)
// last = child.Name // last = child.Name
@ -163,5 +167,5 @@ func dropdownWindowWidgets(p *Node) {
} }
// list everything in the binary tree // list everything in the binary tree
addDropdowns(Config.master) addDropdowns(Config.rootNode)
} }

View File

@ -23,7 +23,7 @@ func (n *Node) NewDropdown(name string) *Node {
newNode := n.New(name, toolkit.Dropdown, nil) newNode := n.New(name, toolkit.Dropdown, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
// a.Widget = &newNode.widget // a.Widget = &newNode.widget
// a.Where = &n.widget // a.Where = &n.widget
// action(&a) // action(&a)
@ -36,7 +36,7 @@ func (n *Node) NewCombobox(name string) *Node {
newNode := n.New(name, toolkit.Combobox, nil) newNode := n.New(name, toolkit.Combobox, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
// a.Widget = &newNode.widget // a.Widget = &newNode.widget
// a.Where = &n.widget // a.Where = &n.widget
// action(&a) // action(&a)

View File

@ -22,7 +22,7 @@ func (n *Node) NewGrid(name string, x int, y int) *Node {
}) })
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
a.X = x a.X = x
a.Y = y a.Y = y
newNode.X = x newNode.X = x
@ -38,8 +38,9 @@ func (n *Node) NewBox(name string, b bool) *Node {
newNode := n.New(name, toolkit.Box, nil) newNode := n.New(name, toolkit.Box, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
a.Title = name a.Name = name
a.Text = name
a.B = b a.B = b
newaction(&a, newNode, n) newaction(&a, newNode, n)

View File

@ -12,7 +12,7 @@ func (n *Node) NewGroup(name string) *Node {
newNode = n.New(name, toolkit.Group, nil) newNode = n.New(name, toolkit.Group, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
newaction(&a, newNode, n) newaction(&a, newNode, n)
newBox := newNode.NewBox("group vBox", false) newBox := newNode.NewBox("group vBox", false)

View File

@ -9,7 +9,7 @@ func (n *Node) NewImage(name string) *Node {
newNode = n.New(name, toolkit.Image, nil) newNode = n.New(name, toolkit.Image, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
// a.Widget = &newNode.widget // a.Widget = &newNode.widget
// a.Where = &n.widget // a.Where = &n.widget
// action(&a) // action(&a)

View File

@ -8,7 +8,9 @@ func (n *Node) NewLabel(text string) *Node {
newNode := n.New(text, toolkit.Label, nil) newNode := n.New(text, toolkit.Label, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
a.Name = text
a.Text = text
newaction(&a, newNode, n) newaction(&a, newNode, n)
return newNode return newNode

17
main.go
View File

@ -2,7 +2,7 @@ package gui
import ( import (
// "embed" // "embed"
// "git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
// Windows doesn't support plugins. How can I keep andlabs and only compile it on windows? // Windows doesn't support plugins. How can I keep andlabs and only compile it on windows?
@ -31,10 +31,12 @@ func init() {
Config.Height = 480 Config.Height = 480
// Populates the top of the binary tree // Populates the top of the binary tree
Config.master = addNode("guiBinaryTree") Config.rootNode = addNode("guiBinaryTree")
Config.rootNode.WidgetType = toolkit.Root
// used to pass debugging flags to the toolkit plugins // used to pass debugging flags to the toolkit plugins
Config.flag = Config.master.New("flag", 0, nil) Config.flag = Config.rootNode.New("flag", 0, nil)
Config.flag.WidgetType = toolkit.Flag
} }
func doGuiChan() { func doGuiChan() {
@ -99,19 +101,20 @@ func Start() *Node {
} }
go Main(f) go Main(f)
sleep(1) sleep(1)
return Config.master return Config.rootNode
} }
func StartS(name string) *Node { func StartS(name string) *Node {
log(logInfo, "Start() Main(f) for name =", name) log(logInfo, "Start() Main(f) for name =", name)
if (LoadToolkit(name) == false) { if (LoadToolkit(name) == false) {
return Config.master return Config.rootNode
} }
// will this really work on mswindows & macos?
f := func() { f := func() {
} }
go Main(f) go Main(f)
sleep(1) sleep(1) // temp hack until chan communication is setup
return Config.master return Config.rootNode
} }
// This should not pass a function // This should not pass a function

View File

@ -9,6 +9,7 @@ func (n *Node) New(title string, t toolkit.WidgetType, custom func()) *Node {
var newN *Node var newN *Node
newN = addNode(title) newN = addNode(title)
newN.WidgetType = t
newN.widget.Type = t newN.widget.Type = t
// newN.widget.Action = "New" // newN.widget.Action = "New"
newN.Custom = custom newN.Custom = custom
@ -44,7 +45,7 @@ func addNode(title string) *Node {
n.Name = title n.Name = title
n.widget.Name = title n.widget.Name = title
n.id = Config.counter n.id = Config.counter
n.widget.SetId(n.id) n.widget.Id = n.id
log(debugNode, "addNode = widget setid =", n.id) log(debugNode, "addNode = widget setid =", n.id)
Config.counter += 1 Config.counter += 1

View File

@ -185,7 +185,8 @@ func loadPlugin(p *aplug, name string) {
homeDir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
exit(err) log(logError, "loadPlugin() error. exiting here?")
return
} }
// attempt to write out the file from the internal resource // attempt to write out the file from the internal resource
@ -234,15 +235,15 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
if (n != nil) { if (n != nil) {
a.Widget = &n.widget a.Widget = &n.widget
a.WidgetId = n.id a.WidgetId = n.id
a.WidgetT = n.widget.Type a.WidgetType = n.widget.Type
a.ActionType = a.ActionType
} }
// action(&a, newNode, n) // action(&a, newNode, n)
// newaction(&a, newNode, n) // newaction(&a, newNode, n)
if (where != nil) { if (where != nil) {
log(debugGui, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY) log(debugGui, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY)
// a.Where = &where.widget a.ParentId = where.id
a.WhereId = where.id
switch where.widget.Type { switch where.widget.Type {
case toolkit.Grid: case toolkit.Grid:
// where.Dump(true) // where.Dump(true)
@ -264,7 +265,7 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
} }
for _, aplug := range allPlugins { for _, aplug := range allPlugins {
log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.Type) log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.ActionType)
if (aplug.Action == nil) { if (aplug.Action == nil) {
log(debugPlugin, "Failed Action() == nil for", aplug.name) log(debugPlugin, "Failed Action() == nil for", aplug.name)
continue continue

59
redraw.go Normal file
View File

@ -0,0 +1,59 @@
package gui
import (
"git.wit.org/wit/gui/toolkit"
)
// This recreates the whole GUI for a plugin
func Redraw(s string) {
var p *aplug
log(logNow, "attempt to feed the binary tree to", s)
for _, aplug := range allPlugins {
log("Loaded plugin:", aplug.name, aplug.filename)
if (aplug.name == s) {
log("Found plugin:", aplug.name, aplug.filename)
p = aplug
}
}
if (p == nil) {
log("Plugin", s, "is not loaded")
return
}
Config.rootNode.Redraw(p)
}
// func (n *Node) ListChildren(dump bool, dropdown *Node, mapNodes map[string]*Node) {
func (n *Node) Redraw(p *aplug) {
if (n == nil) {
return
}
n.redo(p)
for _, child := range n.children {
child.Redraw(p)
}
return
}
func (n *Node) redo(p *aplug) {
log(logNow, "redo() on n.Widget")
var a *toolkit.Action
a = new(toolkit.Action)
a.Name = n.Name
a.Text = n.Text
a.ActionType = toolkit.Add
a.WidgetType = n.WidgetType
a.WidgetId = n.id
a.Width = n.Width
a.Height = n.Height
if (n.parent == nil) {
a.ParentId = 0
} else {
a.ParentId = n.parent.id
}
p.Action(a)
}

View File

@ -10,7 +10,7 @@ func (n *Node) NewSlider(name string, x int, y int) *Node {
}) })
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
a.X = x a.X = x
a.Y = y a.Y = y
// a.Widget = &newNode.widget // a.Widget = &newNode.widget

View File

@ -10,7 +10,7 @@ func (n *Node) NewSpinner(name string, x int, y int) *Node {
}) })
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
a.X = x a.X = x
a.Y = y a.Y = y
// a.Widget = &newNode.widget // a.Widget = &newNode.widget

View File

@ -33,9 +33,9 @@ type GuiArgs struct {
type GuiConfig struct { type GuiConfig struct {
// This is the master node. The Binary Tree starts here // This is the master node. The Binary Tree starts here
master *Node rootNode *Node
// A node off of master for passing debugging flags // A node off of rootNode for passing debugging flags
flag *Node flag *Node
// These are shortcuts to pass default values to make a new window // These are shortcuts to pass default values to make a new window
@ -60,8 +60,13 @@ type Node struct {
initOnce sync.Once initOnce sync.Once
widget toolkit.Widget widget toolkit.Widget
WidgetType toolkit.WidgetType
Name string // Title string // what is visable to the user
// Desc string // a name useful for programming
Text string // what is visable to the user
Name string // a name useful for programming
// used for Windows // used for Windows
Width int Width int
@ -85,9 +90,4 @@ type Node struct {
parent *Node parent *Node
children []*Node children []*Node
// is keeping
// deprecate these things if they don't really need to exist
// checked bool
// text string
} }

5
tab.go
View File

@ -11,8 +11,9 @@ func (n *Node) NewTab(text string) *Node {
newNode := n.New(text, toolkit.Tab, nil) newNode := n.New(text, toolkit.Tab, nil)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
a.Title = text a.Name = text
a.Text = text
newaction(&a, newNode, n) newaction(&a, newNode, n)
newBox := newNode.NewBox(text, true) newBox := newNode.NewBox(text, true)

View File

@ -10,7 +10,7 @@ func (n *Node) NewTextbox(name string) *Node {
}) })
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
// a.Widget = &newNode.widget // a.Widget = &newNode.widget
// a.Where = &n.widget // a.Where = &n.widget
// action(&a) // action(&a)

View File

@ -59,7 +59,7 @@ func pad(a *toolkit.Action) {
switch t.Type { switch t.Type {
case toolkit.Group: case toolkit.Group:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
t.uiGroup.SetMargined(true) t.uiGroup.SetMargined(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -70,7 +70,7 @@ func pad(a *toolkit.Action) {
t.uiGroup.SetMargined(false) t.uiGroup.SetMargined(false)
} }
case toolkit.Tab: case toolkit.Tab:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
tabSetMargined(t.uiTab, true) tabSetMargined(t.uiTab, true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -81,7 +81,7 @@ func pad(a *toolkit.Action) {
tabSetMargined(t.uiTab, false) tabSetMargined(t.uiTab, false)
} }
case toolkit.Window: case toolkit.Window:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
t.uiWindow.SetMargined(true) t.uiWindow.SetMargined(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -92,7 +92,7 @@ func pad(a *toolkit.Action) {
t.uiWindow.SetBorderless(true) t.uiWindow.SetBorderless(true)
} }
case toolkit.Grid: case toolkit.Grid:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
t.uiGrid.SetPadded(true) t.uiGrid.SetPadded(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -103,7 +103,7 @@ func pad(a *toolkit.Action) {
t.uiGrid.SetPadded(false) t.uiGrid.SetPadded(false)
} }
case toolkit.Box: case toolkit.Box:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
t.uiBox.SetPadded(true) t.uiBox.SetPadded(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -114,17 +114,17 @@ func pad(a *toolkit.Action) {
t.uiBox.SetPadded(false) t.uiBox.SetPadded(false)
} }
case toolkit.Textbox: case toolkit.Textbox:
log(debugError, "TODO: implement expand for", a.Type) log(debugError, "TODO: implement expand for", a.ActionType)
log(debugError, "TODO: implement expand for", a.Type) log(debugError, "TODO: implement expand for", a.ActionType)
log(debugError, "TODO: implement expand for", a.Type) log(debugError, "TODO: implement expand for", a.ActionType)
log(debugError, "TODO: implement expand for", a.Type) log(debugError, "TODO: implement expand for", a.ActionType)
default: default:
log(debugError, "TODO: implement pad() for", a.Type) log(debugError, "TODO: implement pad() for", a.ActionType)
} }
} }
func move(a *toolkit.Action) { func move(a *toolkit.Action) {
log(debugNow, "move()", a.WidgetId, "to", a.WhereId) log(debugNow, "move()", a.WidgetId, "to", a.ParentId)
tWidget := andlabs[a.WidgetId] tWidget := andlabs[a.WidgetId]
if (tWidget == nil) { if (tWidget == nil) {
@ -132,55 +132,55 @@ func move(a *toolkit.Action) {
return return
} }
tWhere := andlabs[a.WhereId] tParent := andlabs[a.ParentId]
if (tWhere == nil) { if (tParent == nil) {
log(debugError, "move() ERROR: toolkit struct == nil. for", a.WhereId) log(debugError, "move() ERROR: toolkit struct == nil. for", a.ParentId)
return return
} }
switch tWhere.Type { switch tParent.Type {
case toolkit.Group: case toolkit.Group:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
tWhere.uiGroup.SetMargined(true) tParent.uiGroup.SetMargined(true)
} }
case toolkit.Tab: case toolkit.Tab:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
// tabSetMargined(tWhere.uiTab, true) // tabSetMargined(tParent.uiTab, true)
} }
case toolkit.Window: case toolkit.Window:
switch a.Type { switch a.ActionType {
case toolkit.Pad: case toolkit.Pad:
// t.uiWindow.SetBorderless(false) // t.uiWindow.SetBorderless(false)
} }
case toolkit.Grid: case toolkit.Grid:
switch a.Type { switch a.ActionType {
case toolkit.Pad: case toolkit.Pad:
// t.uiGrid.SetPadded(true) // t.uiGrid.SetPadded(true)
} }
case toolkit.Box: case toolkit.Box:
log(debugNow, "TODO: move() for a =", a.Type) log(debugNow, "TODO: move() for a =", a.ActionType)
log(debugNow, "TODO: move() where =", a.WhereId) log(debugNow, "TODO: move() where =", a.ParentId)
log(debugNow, "TODO: move() for widget =", a.WidgetId) log(debugNow, "TODO: move() for widget =", a.WidgetId)
stretchy = true stretchy = true
tWhere.uiBox.Append(tWidget.uiControl, stretchy) tParent.uiBox.Append(tWidget.uiControl, stretchy)
// log(debugNow, "is there a tWhere parent? =", tWhere.parent) // log(debugNow, "is there a tParent parent? =", tParent.parent)
// tWhere.uiBox.Delete(0) // tParent.uiBox.Delete(0)
// this didn't work: // this didn't work:
// tWidget.uiControl.Disable() // tWidget.uiControl.Disable()
// sleep(.8) // sleep(.8)
default: default:
log(debugError, "TODO: need to implement move() for a =", a.Type) log(debugError, "TODO: need to implement move() for a =", a.ActionType)
log(debugError, "TODO: need to implement move() for where =", a.WhereId) log(debugError, "TODO: need to implement move() for where =", a.ParentId)
log(debugError, "TODO: need to implement move() for widget =", a.WidgetId) log(debugError, "TODO: need to implement move() for widget =", a.WidgetId)
} }
} }
func uiDelete(a *toolkit.Action) { func uiDelete(a *toolkit.Action) {
if (andlabs[a.WhereId] == nil) { if (andlabs[a.ParentId] == nil) {
log(debugError, "uiDelete() ERROR: can not uiDelete to nil") log(debugError, "uiDelete() ERROR: can not uiDelete to nil")
return return
} }
@ -188,7 +188,7 @@ func uiDelete(a *toolkit.Action) {
log(debugError, "uiDelete() ERROR: can not uiDelete nil") log(debugError, "uiDelete() ERROR: can not uiDelete nil")
return return
} }
log(debugNow, "uiDelete()", a.WidgetId, "to", a.WhereId) log(debugNow, "uiDelete()", a.WidgetId, "to", a.ParentId)
tWidget := andlabs[a.WidgetId] tWidget := andlabs[a.WidgetId]
if (tWidget == nil) { if (tWidget == nil) {
@ -196,38 +196,38 @@ func uiDelete(a *toolkit.Action) {
return return
} }
tWhere := andlabs[a.WhereId] tParent := andlabs[a.ParentId]
if (tWhere == nil) { if (tParent == nil) {
log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.WhereId) log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.ParentId)
return return
} }
switch tWhere.Type { switch tParent.Type {
case toolkit.Group: case toolkit.Group:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
tWhere.uiGroup.SetMargined(true) tParent.uiGroup.SetMargined(true)
} }
case toolkit.Tab: case toolkit.Tab:
switch a.Type { switch a.ActionType {
case toolkit.Margin: case toolkit.Margin:
// tabSetMargined(tWhere.uiTab, true) // tabSetMargined(tParent.uiTab, true)
} }
case toolkit.Window: case toolkit.Window:
switch a.Type { switch a.ActionType {
case toolkit.Pad: case toolkit.Pad:
// t.uiWindow.SetBorderless(false) // t.uiWindow.SetBorderless(false)
} }
case toolkit.Grid: case toolkit.Grid:
switch a.Type { switch a.ActionType {
case toolkit.Pad: case toolkit.Pad:
// t.uiGrid.SetPadded(true) // t.uiGrid.SetPadded(true)
} }
case toolkit.Box: case toolkit.Box:
log(debugNow, "tWidget.boxC =", tWhere.Name) log(debugNow, "tWidget.boxC =", tParent.Name)
log(debugNow, "is there a tWhere parent? =", tWhere.parent) log(debugNow, "is there a tParent parent? =", tParent.parent)
if (tWidget.boxC < 1) { if (tWidget.boxC < 1) {
log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", tWhere.boxC) log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", tParent.boxC)
return return
} }
tWidget.uiBox.Delete(0) tWidget.uiBox.Delete(0)
@ -236,10 +236,10 @@ func uiDelete(a *toolkit.Action) {
// this didn't work: // this didn't work:
// tWidget.uiControl.Disable() // tWidget.uiControl.Disable()
// sleep(.8) // sleep(.8)
// tWhere.uiBox.Append(tWidget.uiControl, stretchy) // tParent.uiBox.Append(tWidget.uiControl, stretchy)
default: default:
log(debugError, "TODO: need to implement uiDelete() for a =", a.Type) log(debugError, "TODO: need to implement uiDelete() for a =", a.ActionType)
log(debugError, "TODO: need to implement uiDelete() for where =", a.WhereId) log(debugError, "TODO: need to implement uiDelete() for where =", a.ParentId)
log(debugError, "TODO: need to implement uiDelete() for widget =", a.WidgetId) log(debugError, "TODO: need to implement uiDelete() for widget =", a.WidgetId)
} }
} }

View File

@ -8,11 +8,11 @@ import (
) )
func actionDump(b bool, a *toolkit.Action) { func actionDump(b bool, a *toolkit.Action) {
log(b, "actionDump() Widget.Type =", a.Type) log(b, "actionDump() Widget.Type =", a.ActionType)
log(b, "actionDump() Widget.S =", a.S) log(b, "actionDump() Widget.S =", a.S)
log(b, "actionDump() Widget.I =", a.I) log(b, "actionDump() Widget.I =", a.I)
log(b, "actionDump() WidgetId =", a.WidgetId) log(b, "actionDump() WidgetId =", a.WidgetId)
log(b, "actionDump() WhereId =", a.WhereId) log(b, "actionDump() ParentId =", a.ParentId)
} }
func add(a *toolkit.Action) { func add(a *toolkit.Action) {
@ -28,21 +28,21 @@ func add(a *toolkit.Action) {
} }
// for now, window gets handled without checking where == nil) // for now, window gets handled without checking where == nil)
if (a.WidgetT == toolkit.Window) { if (a.WidgetType == toolkit.Window) {
doWindow(a) doWindow(a)
return return
} }
if (andlabs[a.WhereId] == nil) { if (andlabs[a.ParentId] == nil) {
// listMap(debugError) // memory corruption? // listMap(debugError) // memory corruption?
log(debugError, "add() Widget.Name =", a.Title) log(debugError, "add() Widget.Name =", a.Name)
log(debugError, "add() Widget.Type =", a.WidgetT) log(debugError, "add() Widget.Type =", a.WidgetType)
log(debugError, "ERROR add() ERROR a.Where map to t == nil. WidgetId =", a.WidgetId, "WhereId =", a.WhereId) log(debugError, "ERROR add() ERROR a.Parent map to t == nil. WidgetId =", a.WidgetId, "ParentId =", a.ParentId)
exit("can not add()") exit("can not add()")
return return
} }
switch a.WidgetT { switch a.WidgetType {
case toolkit.Window: case toolkit.Window:
doWindow(a) doWindow(a)
return return
@ -86,7 +86,7 @@ func add(a *toolkit.Action) {
newImage(a) newImage(a)
return return
default: default:
log(debugError, "add() error TODO: ", a.WidgetT, a.Title) log(debugError, "add() error TODO: ", a.WidgetType, a.Name)
} }
} }
@ -115,32 +115,32 @@ func add(a *toolkit.Action) {
// -- (0,1) -- (1,1) -- (1,1) -- // -- (0,1) -- (1,1) -- (1,1) --
// ----------------------------- // -----------------------------
func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool { func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
log(debugAction, "place() START", a.WidgetT, a.Title) log(debugAction, "place() START", a.WidgetType, a.Name)
// add the structure to the array // add the structure to the array
if (andlabs[a.WidgetId] == nil) { if (andlabs[a.WidgetId] == nil) {
log(logInfo, "newTab() MAPPED", a.WidgetId, a.WhereId) log(logInfo, "newTab() MAPPED", a.WidgetId, a.ParentId)
andlabs[a.WidgetId] = newt andlabs[a.WidgetId] = newt
newt.Type = a.WidgetT newt.Type = a.WidgetType
} else { } else {
log(debugError, "newTab() DO WHAT?", a.WidgetId, a.WhereId) log(debugError, "newTab() DO WHAT?", a.WidgetId, a.ParentId)
log(debugError, "THIS IS BAD") log(debugError, "THIS IS BAD")
} }
if (newt.uiControl == nil) { if (newt.uiControl == nil) {
log(debugError, "place() ERROR uiControl == nil", a.WhereId) log(debugError, "place() ERROR uiControl == nil", a.ParentId)
return false return false
} }
where := andlabs[a.WhereId] where := andlabs[a.ParentId]
if (where == nil) { if (where == nil) {
log(debugError, "place() ERROR where == nil", a.WhereId) log(debugError, "place() ERROR where == nil", a.ParentId)
return false return false
} }
switch where.Type { switch where.Type {
case toolkit.Grid: case toolkit.Grid:
log(debugGrid, "add() Grid try at Where X,Y =", a.X, a.Y) log(debugGrid, "add() Grid try at Parent X,Y =", a.X, a.Y)
newt.gridX = a.X newt.gridX = a.X
newt.gridY = a.Y newt.gridY = a.Y
log(debugGrid, "add() Grid try at gridX,gridY", newt.gridX, newt.gridY) log(debugGrid, "add() Grid try at gridX,gridY", newt.gridX, newt.gridY)
@ -152,14 +152,14 @@ func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
case toolkit.Group: case toolkit.Group:
if (t.uiBox == nil) { if (t.uiBox == nil) {
t.uiGroup.SetChild(newt.uiControl) t.uiGroup.SetChild(newt.uiControl)
log(debugGrid, "add() hack Group to use this as the box?", a.Title, a.WidgetT) log(debugGrid, "add() hack Group to use this as the box?", a.Name, a.WidgetType)
t.uiBox = newt.uiBox t.uiBox = newt.uiBox
} else { } else {
t.uiBox.Append(newt.uiControl, stretchy) t.uiBox.Append(newt.uiControl, stretchy)
} }
return true return true
case toolkit.Tab: case toolkit.Tab:
t.uiTab.Append(a.Title, newt.uiControl) t.uiTab.Append(a.Text, newt.uiControl)
t.boxC += 1 t.boxC += 1
return true return true
case toolkit.Box: case toolkit.Box:
@ -170,7 +170,7 @@ func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
t.uiWindow.SetChild(newt.uiControl) t.uiWindow.SetChild(newt.uiControl)
return true return true
default: default:
log(debugError, "add() how?", a.WhereId) log(debugError, "add() how?", a.ParentId)
} }
return false return false
} }

View File

@ -9,14 +9,14 @@ import (
// make new Box here // make new Box here
func newBox(a *toolkit.Action) { func newBox(a *toolkit.Action) {
log(debugToolkit, "newBox()", a.Title) log(debugToolkit, "newBox()", a.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "newBox() toolkit struct == nil. name=", a.Title) log(debugToolkit, "newBox() toolkit struct == nil. name=", a.Name)
listMap(debugToolkit) listMap(debugToolkit)
} }
newt := t.rawBox(a.Title, a.B) newt := t.rawBox(a.Text, a.B)
newt.boxC = 0 newt.boxC = 0
place(a, t, newt) place(a, t, newt)
andlabs[a.WidgetId] = newt andlabs[a.WidgetId] = newt

View File

@ -10,21 +10,21 @@ import (
func newButton(a *toolkit.Action) { func newButton(a *toolkit.Action) {
var t, newt *andlabsT var t, newt *andlabsT
var b *ui.Button var b *ui.Button
log(debugToolkit, "newButton()", a.Title) log(debugToolkit, "newButton()", a.Name)
t = andlabs[a.WhereId] t = andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "newButton() toolkit struct == nil. name=", a.Title) log(debugToolkit, "newButton() toolkit struct == nil. name=", a.Name)
return return
} }
newt = new(andlabsT) newt = new(andlabsT)
b = ui.NewButton(a.Title) b = ui.NewButton(a.Text)
newt.uiButton = b newt.uiButton = b
newt.uiControl = b newt.uiControl = b
newt.tw = a.Widget newt.tw = a.Widget
newt.Type = a.WidgetT newt.Type = a.WidgetType
newt.parent = t newt.parent = t
b.OnClicked(func(*ui.Button) { b.OnClicked(func(*ui.Button) {

View File

@ -31,9 +31,9 @@ func (t *andlabsT) checked() bool {
} }
func newCheckbox(a *toolkit.Action) { func newCheckbox(a *toolkit.Action) {
log(debugToolkit, "newCheckbox()", a.Title) log(debugToolkit, "newCheckbox()", a.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
listMap(debugError) listMap(debugError)
return return

View File

@ -45,11 +45,11 @@ func (t *andlabsT) AddComboboxName(title string) {
} }
func newCombobox(a *toolkit.Action) { func newCombobox(a *toolkit.Action) {
log(debugToolkit, "newCombobox()", a.Title) log(debugToolkit, "newCombobox()", a.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "newCombobox() toolkit struct == nil. name=", a.Title) log(debugToolkit, "newCombobox() toolkit struct == nil. name=", a.Name)
listMap(debugToolkit) listMap(debugToolkit)
return return
} }

View File

@ -90,6 +90,7 @@ func widgetDump(b bool, w *toolkit.Widget) {
return return
} }
/*
log(b, "widget.Name =", w.Name) log(b, "widget.Name =", w.Name)
log(b, "widget.Type =", w.Type) log(b, "widget.Type =", w.Type)
log(b, "widget.Custom =", w.Custom) log(b, "widget.Custom =", w.Custom)
@ -99,6 +100,7 @@ func widgetDump(b bool, w *toolkit.Widget) {
log(b, "widget.Height =", w.Height) log(b, "widget.Height =", w.Height)
log(b, "widget.X =", w.X) log(b, "widget.X =", w.X)
log(b, "widget.Y =", w.Y) log(b, "widget.Y =", w.Y)
*/
} }
/* /*

View File

@ -9,7 +9,7 @@ import (
func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT { func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
var newt andlabsT var newt andlabsT
w := a.Widget w := a.Widget
log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Title) log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Name)
newt.tw = w newt.tw = w
newt.Type = w.Type newt.Type = w.Type
@ -82,9 +82,9 @@ func SetDropdownName(a *toolkit.Action, s string) {
} }
func newDropdown(a *toolkit.Action) { func newDropdown(a *toolkit.Action) {
log(debugToolkit, "gui.andlabs.newDropdown()", a.Title) log(debugToolkit, "gui.andlabs.newDropdown()", a.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", a.WidgetId) log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", a.WidgetId)
listMap(debugToolkit) listMap(debugToolkit)

View File

@ -14,7 +14,7 @@ import (
// ----------------------------- // -----------------------------
func newGrid(a *toolkit.Action) { func newGrid(a *toolkit.Action) {
var newt *andlabsT var newt *andlabsT
log(debugToolkit, "newGrid()", a.WidgetId, "to", a.WhereId) log(debugToolkit, "newGrid()", a.WidgetId, "to", a.ParentId)
newt = new(andlabsT) newt = new(andlabsT)
@ -26,6 +26,6 @@ func newGrid(a *toolkit.Action) {
newt.gridX = 0 newt.gridX = 0
newt.gridY = 0 newt.gridY = 0
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
place(a, t, newt) place(a, t, newt)
} }

View File

@ -11,7 +11,7 @@ func newGroup(a *toolkit.Action) {
w := a.Widget w := a.Widget
log(debugToolkit, "NewGroup()", w.Name) log(debugToolkit, "NewGroup()", w.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "NewGroup() toolkit struct == nil. name=", w.Name) log(debugToolkit, "NewGroup() toolkit struct == nil. name=", w.Name)
listMap(debugToolkit) listMap(debugToolkit)

View File

@ -12,7 +12,7 @@ func newImage(a *toolkit.Action) {
w := a.Widget w := a.Widget
log(debugToolkit, "newImage()", w.Name) log(debugToolkit, "newImage()", w.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "newImage() toolkit struct == nil. name=", w.Name) log(debugToolkit, "newImage() toolkit struct == nil. name=", w.Name)
listMap(debugToolkit) listMap(debugToolkit)

View File

@ -12,7 +12,7 @@ func newLabel(a *toolkit.Action) {
w := a.Widget w := a.Widget
log(debugToolkit, "NewLabel()", w.Name) log(debugToolkit, "NewLabel()", w.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
listMap(debugError) listMap(debugError)
log(debugError, "ERROR newLabel() listMap()") log(debugError, "ERROR newLabel() listMap()")

View File

@ -44,13 +44,18 @@ func Action(a *toolkit.Action) {
func rawAction(a *toolkit.Action) { func rawAction(a *toolkit.Action) {
log(debugAction, "Action() START a.Type =", a.Type) log(debugAction, "Action() START a.ActionType =", a.ActionType)
log(debugAction, "Action() START a.S =", a.S) log(debugAction, "Action() START a.S =", a.S)
log(debugAction, "Action() START a.Widget =", a.Widget) log(debugAction, "Action() START a.Widget =", a.Widget)
log(logInfo, "Action() START a.WidgetId =", a.WidgetId, "a.WhereId =", a.WhereId) log(logInfo, "Action() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case toolkit.Flag:
flag(a)
return
}
switch a.Type { switch a.ActionType {
case toolkit.Add: case toolkit.Add:
add(a) add(a)
case toolkit.Show: case toolkit.Show:
@ -75,8 +80,6 @@ func rawAction(a *toolkit.Action) {
} }
case toolkit.Set: case toolkit.Set:
setText(a) setText(a)
case toolkit.SetFlag:
flag(a)
case toolkit.SetText: case toolkit.SetText:
setText(a) setText(a)
case toolkit.AddText: case toolkit.AddText:
@ -91,15 +94,13 @@ func rawAction(a *toolkit.Action) {
pad(a) pad(a)
case toolkit.Delete: case toolkit.Delete:
uiDelete(a) uiDelete(a)
case toolkit.Flag:
flag(a)
case toolkit.Move: case toolkit.Move:
log(debugNow, "attempt to move() =", a.Type, a.Widget) log(debugNow, "attempt to move() =", a.ActionType, a.Widget)
move(a) move(a)
default: default:
log(debugError, "Action() Unknown =", a.Type, a.Widget) log(debugError, "Action() Unknown =", a.ActionType, a.Widget)
} }
log(debugAction, "Action() END =", a.Type, a.Widget) log(debugAction, "Action() END =", a.ActionType, a.Widget)
} }
func flag(a *toolkit.Action) { func flag(a *toolkit.Action) {
@ -146,7 +147,7 @@ func setText(a *toolkit.Action) {
case toolkit.Group: case toolkit.Group:
t.uiGroup.SetTitle(a.S) t.uiGroup.SetTitle(a.S)
case toolkit.Checkbox: case toolkit.Checkbox:
switch a.Type { switch a.ActionType {
case toolkit.SetText: case toolkit.SetText:
t.uiCheckbox.SetText(a.S) t.uiCheckbox.SetText(a.S)
case toolkit.Get: case toolkit.Get:
@ -156,10 +157,10 @@ func setText(a *toolkit.Action) {
// t.uiCheckbox.SetChecked(a.B) // t.uiCheckbox.SetChecked(a.B)
t.tw.B = a.B t.tw.B = a.B
default: default:
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name)
} }
case toolkit.Textbox: case toolkit.Textbox:
switch a.Type { switch a.ActionType {
case toolkit.Set: case toolkit.Set:
t.uiMultilineEntry.SetText(a.S) t.uiMultilineEntry.SetText(a.S)
case toolkit.SetText: case toolkit.SetText:
@ -169,32 +170,32 @@ func setText(a *toolkit.Action) {
case toolkit.GetText: case toolkit.GetText:
t.tw.S = t.s t.tw.S = t.s
default: default:
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name)
} }
case toolkit.Label: case toolkit.Label:
t.uiLabel.SetText(a.S) t.uiLabel.SetText(a.S)
case toolkit.Button: case toolkit.Button:
t.uiButton.SetText(a.S) t.uiButton.SetText(a.S)
case toolkit.Slider: case toolkit.Slider:
switch a.Type { switch a.ActionType {
case toolkit.Get: case toolkit.Get:
t.tw.I = t.uiSlider.Value() t.tw.I = t.uiSlider.Value()
case toolkit.Set: case toolkit.Set:
t.uiSlider.SetValue(a.I) t.uiSlider.SetValue(a.I)
default: default:
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name)
} }
case toolkit.Spinner: case toolkit.Spinner:
switch a.Type { switch a.ActionType {
case toolkit.Get: case toolkit.Get:
t.tw.I = t.uiSpinbox.Value() t.tw.I = t.uiSpinbox.Value()
case toolkit.Set: case toolkit.Set:
t.uiSpinbox.SetValue(a.I) t.uiSpinbox.SetValue(a.I)
default: default:
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name)
} }
case toolkit.Dropdown: case toolkit.Dropdown:
switch a.Type { switch a.ActionType {
case toolkit.AddText: case toolkit.AddText:
AddDropdownName(a) AddDropdownName(a)
case toolkit.Set: case toolkit.Set:
@ -226,10 +227,10 @@ func setText(a *toolkit.Action) {
case toolkit.GetText: case toolkit.GetText:
t.tw.S = t.s t.tw.S = t.s
default: default:
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name)
} }
case toolkit.Combobox: case toolkit.Combobox:
switch a.Type { switch a.ActionType {
case toolkit.AddText: case toolkit.AddText:
t.AddComboboxName(a.S) t.AddComboboxName(a.S)
case toolkit.Set: case toolkit.Set:
@ -243,9 +244,9 @@ func setText(a *toolkit.Action) {
case toolkit.GetText: case toolkit.GetText:
t.tw.S = t.s t.tw.S = t.s
default: default:
log(debugError, "setText() unknown", a.Type, "on checkbox", t.tw.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name)
} }
default: default:
log(debugError, "plugin Send() Don't know how to setText on", t.tw.Type, "yet", a.Type) log(debugError, "plugin Send() Don't know how to setText on", t.tw.Type, "yet", a.ActionType)
} }
} }

View File

@ -10,9 +10,9 @@ import (
func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT { func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT {
var newt andlabsT var newt andlabsT
w := a.Widget w := a.Widget
log(debugToolkit, w.Name, w.Type, w.X, w.Y) // log(debugToolkit, w.Name, w.Type, w.X, w.Y)
s := ui.NewSlider(w.X, w.Y) s := ui.NewSlider(a.X, a.Y)
newt.uiSlider = s newt.uiSlider = s
newt.uiControl = s newt.uiControl = s
newt.tw = w newt.tw = w
@ -32,13 +32,13 @@ func newSlider(a *toolkit.Action) {
w := a.Widget w := a.Widget
log(debugToolkit, "newSlider()", w.Name) log(debugToolkit, "newSlider()", w.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugError, "newSlider() ERROR toolkit struct == nil. name=", w.Name) log(debugError, "newSlider() ERROR toolkit struct == nil. name=", w.Name)
return return
} }
w.X = a.X // w.X = a.X
w.Y = a.Y // w.Y = a.Y
newt = t.newSlider(a) newt = t.newSlider(a)
place(a, t, newt) place(a, t, newt)
} }

View File

@ -10,9 +10,9 @@ import (
func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT { func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT {
var newt andlabsT var newt andlabsT
w := a.Widget w := a.Widget
log(debugToolkit, "newSpinner()", w.X, w.Y) // log(debugToolkit, "newSpinner()", w.X, w.Y)
s := ui.NewSpinbox(w.X, w.Y) s := ui.NewSpinbox(a.X, a.Y)
newt.uiSpinbox = s newt.uiSpinbox = s
newt.uiControl = s newt.uiControl = s
newt.tw = w newt.tw = w
@ -31,13 +31,11 @@ func newSpinner(a *toolkit.Action) {
var newt *andlabsT var newt *andlabsT
w := a.Widget w := a.Widget
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugError, "NewSpinner() toolkit struct == nil. name=", w.Name) log(debugError, "NewSpinner() toolkit struct == nil. name=", w.Name)
return return
} }
w.X = a.X
w.Y = a.Y
newt = t.newSpinner(a) newt = t.newSpinner(a)
place(a, t, newt) place(a, t, newt)
} }

View File

@ -23,34 +23,34 @@ func (t *andlabsT) newTab(a *toolkit.Action) {
// var w *ui.Window // var w *ui.Window
var newt *andlabsT var newt *andlabsT
log(debugToolkit, "newTab() START", a.WidgetId, a.WhereId) log(debugToolkit, "newTab() START", a.WidgetId, a.ParentId)
if (t.uiTab == nil) { if (t.uiTab == nil) {
if (t.uiWindow == nil) { if (t.uiWindow == nil) {
log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", a.WidgetId, a.WhereId) log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", a.WidgetId, a.ParentId)
return return
} }
// this means you have to make a new tab // this means you have to make a new tab
log(debugToolkit, "newTab() GOOD. This should be the first tab:", a.WidgetId, a.WhereId) log(debugToolkit, "newTab() GOOD. This should be the first tab:", a.WidgetId, a.ParentId)
newt = rawTab(t.uiWindow, a.Title) newt = rawTab(t.uiWindow, a.Text)
t.uiTab = newt.uiTab t.uiTab = newt.uiTab
} else { } else {
// this means you have to append a tab // this means you have to append a tab
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", a.WidgetId, a.WhereId) log(debugToolkit, "newTab() GOOD. This should be an additional tab:", a.WidgetId, a.ParentId)
newt = t.appendTab(a.Title) newt = t.appendTab(a.Text)
} }
// add the structure to the array // add the structure to the array
if (andlabs[a.WidgetId] == nil) { if (andlabs[a.WidgetId] == nil) {
log(logInfo, "newTab() MAPPED", a.WidgetId, a.WhereId) log(logInfo, "newTab() MAPPED", a.WidgetId, a.ParentId)
andlabs[a.WidgetId] = newt andlabs[a.WidgetId] = newt
newt.Type = a.Widget.Type newt.Type = a.Widget.Type
} else { } else {
log(debugError, "newTab() DO WHAT?", a.WidgetId, a.WhereId) log(debugError, "newTab() DO WHAT?", a.WidgetId, a.ParentId)
log(debugError, "THIS IS BAD") log(debugError, "THIS IS BAD")
} }
newt.Name = a.Title newt.Name = a.Name
log(debugToolkit, "t:") log(debugToolkit, "t:")
t.Dump(debugToolkit) t.Dump(debugToolkit)
@ -120,11 +120,11 @@ func (t *andlabsT) appendTab(name string) *andlabsT {
func newTab(a *toolkit.Action) { func newTab(a *toolkit.Action) {
// w := a.Widget // w := a.Widget
log(debugToolkit, "newTab()", a.WhereId) log(debugToolkit, "newTab()", a.ParentId)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "newTab() parent toolkit == nil. new tab can not be made =", a.WhereId) log(debugToolkit, "newTab() parent toolkit == nil. new tab can not be made =", a.ParentId)
log(debugToolkit, "look for a window? check for an existing tab?") log(debugToolkit, "look for a window? check for an existing tab?")
return return
} }

View File

@ -32,7 +32,7 @@ func newTextbox(a *toolkit.Action) {
w := a.Widget w := a.Widget
log(debugToolkit, "newCombobox()", w.Name) log(debugToolkit, "newCombobox()", w.Name)
t := andlabs[a.WhereId] t := andlabs[a.ParentId]
if (t == nil) { if (t == nil) {
log(debugToolkit, "newCombobox() toolkit struct == nil. name=", w.Name) log(debugToolkit, "newCombobox() toolkit struct == nil. name=", w.Name)
listMap(debugToolkit) listMap(debugToolkit)

View File

@ -19,7 +19,7 @@ func newWindow(a *toolkit.Action) {
w := a.Widget w := a.Widget
var newt *andlabsT var newt *andlabsT
log(debugToolkit, "toolkit NewWindow", w.Name, w.Width, w.Height) // log(debugToolkit, "toolkit NewWindow", w.Name, w.Width, w.Height)
if (w == nil) { if (w == nil) {
log(debugToolkit, "wit/gui plugin error. widget == nil") log(debugToolkit, "wit/gui plugin error. widget == nil")
@ -31,7 +31,7 @@ func newWindow(a *toolkit.Action) {
newt.wId = a.WidgetId newt.wId = a.WidgetId
// menubar bool is if the OS defined border on the window should be used // menubar bool is if the OS defined border on the window should be used
win := ui.NewWindow(w.Name, w.Width, w.Height, menubar) win := ui.NewWindow(w.Name, a.Width, a.Height, menubar)
win.SetBorderless(canvas) win.SetBorderless(canvas)
win.SetMargined(margin) win.SetMargined(margin)
win.OnClosing(func(*ui.Window) bool { win.OnClosing(func(*ui.Window) bool {

View File

@ -9,3 +9,7 @@ plugin:
objdump: objdump:
objdump -t ../democui.so |less objdump -t ../democui.so |less
log:
reset
tail -f /tmp/witgui.* /tmp/guilogfile

49
toolkit/democui/click.go Normal file
View File

@ -0,0 +1,49 @@
package main
import (
"fmt"
"errors"
"strconv"
"github.com/awesome-gocui/gocui"
// "git.wit.org/wit/gui/toolkit"
)
func click(g *gocui.Gui, v *gocui.View) error {
var l string
var err error
log(logNow, "click() START", v.Name())
i, err := strconv.Atoi(v.Name())
if (err != nil) {
log(logNow, "click() Can't find widget. error =", err)
} else {
log(logNow, "click() Found widget id =", i)
if (me.widgets[i] != nil) {
w := me.widgets[i]
log(logNow, "click() Found widget =", w)
}
}
if _, err := g.SetCurrentView(v.Name()); err != nil {
return err
}
_, cy := v.Cursor()
if l, err = v.Line(cy); err != nil {
l = ""
}
maxX, maxY := g.Size()
if v, err := g.SetView("msg", maxX/2-10, maxY/2, maxX/2+10, maxY/2+2, 0); err == nil || errors.Is(err, gocui.ErrUnknownView) {
v.Clear()
v.SelBgColor = gocui.ColorCyan
v.SelFgColor = gocui.ColorBlack
fmt.Fprintln(v, l)
}
// this seems to delete the button(?)
// g.SetViewOnBottom(v.Name())
log(logNow, "click() END")
return nil
}

90
toolkit/democui/common.go Normal file
View File

@ -0,0 +1,90 @@
package main
import (
"github.com/awesome-gocui/gocui"
"git.wit.org/wit/gui/toolkit"
)
func setupWidgetT(a *toolkit.Action) *cuiWidget {
var w *cuiWidget
w = new(cuiWidget)
w.name = a.Name
w.text = a.Text
w.widgetType = a.WidgetType
w.id = a.WidgetId
if (w.id > me.highest) {
me.highest = w.id
}
w.parentId = a.ParentId
me.widgets[w.id] = w
// w.showWidgetPlacement(logNow)
return w
}
// ColorBlack ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite
// gocui.GetColor("#FFAA55") // Dark Purple
func (w *cuiWidget) SetDefaultWidgetColor() {
log(logInfo, "SetDefaultWidgetColor() on", w.widgetType, w.name)
if (w.v == nil) {
log(logError, "SetDefaultWidgetColor() failed on view == nil")
return
}
w.SetDefaultHighlight()
switch w.widgetType {
case toolkit.Button:
w.v.BgColor = gocui.ColorGreen
w.v.FrameColor = gocui.ColorGreen
case toolkit.Checkbox:
w.v.BgColor = gocui.GetColor("#FFAA55") // Dark Purple
w.v.FrameColor = gocui.GetColor("#FFEE11")
case toolkit.Dropdown:
w.v.BgColor = gocui.ColorCyan
w.v.FrameColor = gocui.ColorGreen
case toolkit.Textbox:
w.v.BgColor = gocui.ColorYellow
w.v.FrameColor = gocui.ColorGreen
case toolkit.Slider:
w.v.BgColor = gocui.GetColor("#FFAA55") // Dark Purple
w.v.FrameColor = gocui.ColorRed
case toolkit.Label:
w.v.FrameColor = gocui.ColorRed
default:
w.v.BgColor = gocui.ColorYellow
}
}
// SetColor("#FFAA55") // purple
func (w *cuiWidget) SetColor(c string) {
if (w.v == nil) {
log(logError, "SetColor() failed on view == nil")
return
}
w.v.SelBgColor = gocui.ColorCyan
w.v.SelFgColor = gocui.ColorBlack
switch c {
case "Green":
w.v.BgColor = gocui.ColorGreen
case "Purple":
w.v.BgColor = gocui.GetColor("#FFAA55")
case "Yellow":
w.v.BgColor = gocui.ColorYellow
case "Blue":
w.v.BgColor = gocui.ColorBlue
case "Red":
w.v.BgColor = gocui.ColorRed
default:
w.v.BgColor = gocui.GetColor(c)
}
}
func (w *cuiWidget) SetDefaultHighlight() {
if (w.v == nil) {
log(logError, "SetColor() failed on view == nil")
return
}
w.v.SelBgColor = gocui.ColorGreen
w.v.SelFgColor = gocui.ColorBlack
}

View File

@ -1,86 +1,46 @@
package main package main
import "git.wit.org/wit/gui/toolkit" import (
"fmt"
"strconv"
var defaultBehavior bool = true "git.wit.org/wit/gui/toolkit"
"github.com/awesome-gocui/gocui"
)
var bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? // var debugError bool = true
var canvas bool // if set to true, the windows are a raw canvas
var menubar bool // for windows
var stretchy bool // expand things like buttons to the maximum size
var padded bool // add space between things like buttons
var margin bool // add space around the frames of windows
var debugToolkit bool
var debugChange bool
var debugPlugin bool
var debugFlags bool
var debugError bool = true
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc // This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func setDefaultBehavior(s bool) { func setDefaultBehavior(s bool) {
defaultBehavior = s me.defaultBehavior = s
if (defaultBehavior) { if (me.defaultBehavior) {
log(debugToolkit, "Setting this toolkit to use the default behavior.") log(logInfo, "Setting this toolkit to use the default behavior.")
log(debugToolkit, "This is the 'guessing' part as defined by the wit/gui 'Principles'. Refer to the docs.") log(logInfo, "This is the 'guessing' part as defined by the wit/gui 'Principles'. Refer to the docs.")
stretchy = false me.stretchy = false
padded = true me.padded = true
menubar = true me.menubar = true
margin = true me.margin = true
canvas = false me.canvas = false
bookshelf = true // 99% of the time, things make a vertical stack of objects me.bookshelf = true // 99% of the time, things make a vertical stack of objects
} else { } else {
log(debugToolkit, "This toolkit is set to ignore the default behavior.") log(logInfo, "This toolkit is set to ignore the default behavior.")
} }
} }
func ShowDebug () { func actionDump(b bool, a *toolkit.Action) {
log(true, "debugToolkit =", debugToolkit) if (a == nil) {
log(true, "debugChange =", debugChange) log(b, "action = nil")
log(true, "debugPlugin =", debugPlugin)
log(true, "debugFlags =", debugFlags)
log(true, "debugError =", debugError)
}
/*
func (t *gocuiT) Dump(b bool) {
if ! b {
return return
} }
log(b, "Name = ", t.Name, t.Width, t.Height)
if (t.uiBox != nil) { log(b, "a.Name =", a.Name)
log(b, "uiBox =", t.uiBox) log(b, "a.Text =", a.Text)
} log(b, "a.WidgetId =", a.WidgetId)
if (t.uiButton != nil) { log(b, "a.ParentId =", a.ParentId)
log(b, "uiButton =", t.uiButton) log(b, "a.B =", a.B)
} log(b, "a.S =", a.S)
if (t.uiCombobox != nil) { widgetDump(b, a.Widget)
log(b, "uiCombobox =", t.uiCombobox)
}
if (t.uiWindow != nil) {
log(b, "uiWindow =", t.uiWindow)
}
if (t.uiTab != nil) {
log(b, "uiTab =", t.uiTab)
}
if (t.uiGroup != nil) {
log(b, "uiGroup =", t.uiGroup)
}
if (t.uiEntry != nil) {
log(b, "uiEntry =", t.uiEntry)
}
if (t.uiMultilineEntry != nil) {
log(b, "uiMultilineEntry =", t.uiMultilineEntry)
}
if (t.uiSlider != nil) {
log(b, "uiSlider =", t.uiSlider)
}
if (t.uiCheckbox != nil) {
log(b, "uiCheckbox =", t.uiCheckbox)
}
widgetDump(b, t.tw)
} }
*/
func widgetDump(b bool, w *toolkit.Widget) { func widgetDump(b bool, w *toolkit.Widget) {
if (w == nil) { if (w == nil) {
@ -88,6 +48,7 @@ func widgetDump(b bool, w *toolkit.Widget) {
return return
} }
/*
log(b, "widget.Name =", w.Name) log(b, "widget.Name =", w.Name)
log(b, "widget.Type =", w.Type) log(b, "widget.Type =", w.Type)
log(b, "widget.Custom =", w.Custom) log(b, "widget.Custom =", w.Custom)
@ -97,10 +58,66 @@ func widgetDump(b bool, w *toolkit.Widget) {
log(b, "widget.Height =", w.Height) log(b, "widget.Height =", w.Height)
log(b, "widget.X =", w.X) log(b, "widget.X =", w.X)
log(b, "widget.Y =", w.Y) log(b, "widget.Y =", w.Y)
*/
} }
/* func dumpWidgets(g *gocui.Gui, v *gocui.View) {
func GetDebugToolkit () bool { for _, view := range g.Views() {
return debugToolkit i, _ := strconv.Atoi(view.Name())
if (me.widgets[i] != nil) {
continue
}
log(logNow, "dump() not a widget. view.Name =", view.Name())
}
for i := 0; i <= me.highest; i++ {
w := me.widgets[i]
if (w == nil) {
continue
}
w.showWidgetPlacement(logNow, "")
if (w.v == nil) {
log(logError, "dump() ERROR w.v == nil")
} else {
if (strconv.Itoa(i) != w.v.Name()) {
log(logError, "dump() ERROR unequal str.Itoa(i) =", strconv.Itoa(i))
log(logError, "dump() ERROR unequal w.v.Name() =", w.v.Name())
}
}
}
}
func adjustWidgets() {
for i := 0; i <= me.highest; i++ {
w := me.widgets[i]
if (w == nil) {
continue
}
p := me.widgets[w.parentId]
if (p != nil) {
w.setParentLogical(p)
}
}
}
func (w *cuiWidget) showWidgetPlacement(b bool, s string) {
log(b, "dump()", s,
fmt.Sprintf("(wId,pId)=(%3d,%3d)", w.id, w.parentId),
fmt.Sprintf("real()=(%3d,%3d,%3d,%3d)", w.realSize.w0, w.realSize.h0, w.realSize.w1, w.realSize.h1),
"next()=(", w.nextX, ",", w.nextY, ")",
"logical()=(", w.logicalSize.w0, ",", w.logicalSize.h0, ",", w.logicalSize.w1, ",", w.logicalSize.h1, ")",
w.widgetType, ",", w.name)
if (w.realWidth != (w.realSize.w1 - w.realSize.w0)) {
log(b, "dump()", s,
"badsize()=(", w.realWidth, ",", w.realHeight, ")",
"badreal()=(", w.realSize.w0, ",", w.realSize.h0, ",", w.realSize.w1, ",", w.realSize.h1, ")",
w.widgetType, ",", w.name)
}
if (w.realHeight != (w.realSize.h1 - w.realSize.h0)) {
log(b, "dump()", s,
"badsize()=(", w.realWidth, ",", w.realHeight, ")",
"badreal()=(", w.realSize.w0, ",", w.realSize.h0, ",", w.realSize.w1, ",", w.realSize.h1, ")",
w.widgetType, ",", w.name)
}
} }
*/

View File

@ -12,29 +12,35 @@ import (
) )
func addHelp() { func addHelp() {
baseGui.SetManagerFunc(helplayout) me.baseGui.SetManagerFunc(helplayout)
} }
func helplayout(g *gocui.Gui) error { func helplayout(g *gocui.Gui) error {
var err error var err error
maxX, _ := g.Size() maxX, _ := g.Size()
helpLabel, err = g.SetView("help", maxX-32, 0, maxX-1, 12, 0) help, err := g.SetView("help", maxX-32, 0, maxX-1, 12, 0)
if err != nil { if err != nil {
if !errors.Is(err, gocui.ErrUnknownView) { if !errors.Is(err, gocui.ErrUnknownView) {
return err return err
} }
fmt.Fprintln(helpLabel, "KEYBINDINGS") help.SelBgColor = gocui.ColorGreen
fmt.Fprintln(helpLabel, "Enter: Click Button") help.SelFgColor = gocui.ColorBlack
fmt.Fprintln(helpLabel, "Tab/Space: Switch Buttons") fmt.Fprintln(help, "KEYBINDINGS")
fmt.Fprintln(helpLabel, "") fmt.Fprintln(help, "Enter: Click Button")
fmt.Fprintln(helpLabel, "h: Help") fmt.Fprintln(help, "Tab/Space: Switch Buttons")
fmt.Fprintln(helpLabel, "Backspace: Delete Button") fmt.Fprintln(help, "")
fmt.Fprintln(helpLabel, "Arrow keys: Move Button") fmt.Fprintln(help, "h: Help")
fmt.Fprintln(helpLabel, "t: Move Button to the top") fmt.Fprintln(help, "Backspace: Delete Button")
fmt.Fprintln(helpLabel, "b: Move Button to the button") fmt.Fprintln(help, "Arrow keys: Move Button")
fmt.Fprintln(helpLabel, "STDOUT: /tmp/witgui.log") fmt.Fprintln(help, "t: Move Button to the top")
fmt.Fprintln(helpLabel, "Ctrl-C or Q: Exit") fmt.Fprintln(help, "b: Move Button to the button")
fmt.Fprintln(help, "STDOUT: /tmp/witgui.log")
fmt.Fprintln(help, "Ctrl-C or Q: Exit")
if _, err := g.SetCurrentView("help"); err != nil {
return err
} }
}
me.helpLabel = help
return nil return nil
} }

View File

@ -0,0 +1,45 @@
// Copyright 2014 The gocui Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/awesome-gocui/gocui"
)
func defaultKeybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
return err
}
for _, n := range []string{"but1", "but2", "help", "but3"} {
if err := g.SetKeybinding(n, gocui.MouseLeft, gocui.ModNone, showMsg); err != nil {
return err
}
}
if err := g.SetKeybinding("", gocui.MouseRelease, gocui.ModNone, mouseUp); err != nil {
return err
}
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, globalDown); err != nil {
return err
}
if err := g.SetKeybinding("msg", gocui.MouseLeft, gocui.ModNone, msgDown); err != nil {
return err
}
addDebugKeys(g)
return nil
}
// dump out the widgets
func addDebugKeys(g *gocui.Gui) {
g.SetKeybinding("", 'd', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
dumpWidgets(g, v)
return nil
})
g.SetKeybinding("", 'r', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
adjustWidgets()
return nil
})
}

View File

@ -8,18 +8,26 @@ import (
"os" "os"
) )
/*
func OnExit(f func(string)) { func OnExit(f func(string)) {
Custom = f Custom = f
} }
*/
func Init() { func Init() {
log("Init() of democui") log(logInfo, "Init() of democui")
me.widgets = make(map[int]*cuiWidget)
me.defaultWidth = 10
me.defaultHeight = 2
me.defaultBehavior = true
} }
func Exit() { func Exit() {
g.Close() // TODO: exit correctly
me.baseGui.Close()
} }
/*
func mouseClick(name string) { func mouseClick(name string) {
// output screws up the console. Need to fix this by redirecting all console output to a file from log.Println() // output screws up the console. Need to fix this by redirecting all console output to a file from log.Println()
// log.Println("g.Close()") // log.Println("g.Close()")
@ -29,6 +37,7 @@ func mouseClick(name string) {
Custom(name) Custom(name)
// panic("got andlabs") // panic("got andlabs")
} }
*/
func Main(f func()) { func Main(f func()) {
log("start Init()") log("start Init()")

View File

@ -18,14 +18,14 @@ func MouseMain() {
} }
defer g.Close() defer g.Close()
baseGui = g me.baseGui = g
g.Cursor = true g.Cursor = true
g.Mouse = true g.Mouse = true
g.SetManagerFunc(layout) g.SetManagerFunc(layout)
if err := keybindings(g); err != nil { if err := defaultKeybindings(g); err != nil {
panic(err) panic(err)
} }
@ -72,27 +72,6 @@ func layout(g *gocui.Gui) error {
return nil return nil
} }
func keybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
return err
}
for _, n := range []string{"but1", "but2"} {
if err := g.SetKeybinding(n, gocui.MouseLeft, gocui.ModNone, showMsg); err != nil {
return err
}
}
if err := g.SetKeybinding("", gocui.MouseRelease, gocui.ModNone, mouseUp); err != nil {
return err
}
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, globalDown); err != nil {
return err
}
if err := g.SetKeybinding("msg", gocui.MouseLeft, gocui.ModNone, msgDown); err != nil {
return err
}
return nil
}
func quit(g *gocui.Gui, v *gocui.View) error { func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit return gocui.ErrQuit
} }

View File

@ -4,128 +4,15 @@ import (
// if you include more than just this import // if you include more than just this import
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27) // then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
"github.com/awesome-gocui/gocui"
) )
// This is a map between the widgets in wit/gui and the internal structures of gocui
var viewWidget map[*gocui.View]*toolkit.Widget
var stringWidget map[string]*toolkit.Widget
func Quit() { func Quit() {
g.Close() me.baseGui.Close()
}
// This lists out the know mappings
func listMap() {
for v, w := range viewWidget {
log("view =", v.Name, "widget name =", w.Name)
}
for s, w := range stringWidget {
log("string =", s, "widget =", w)
}
}
//
// This should be called ?
// Pass() ?
// This handles all interaction between the wit/gui package (what golang knows about)
// and this plugin that talks to the OS and does scary and crazy things to make
// a GUI on whatever OS or whatever GUI toolkit you might have (GTK, QT, WASM, libcurses)
//
// Once you are here, you should be in a protected goroutine created by the golang wit/gui package
//
// TODO: make sure you can't escape this goroutine
//
func Send(p *toolkit.Widget, c *toolkit.Widget) {
if (p == nil) {
log(debugPlugin, "Send() parent = nil")
} else {
log(debugPlugin, "Send() parent =", p.Name, ",", p.Type)
}
log(debugPlugin, "Send() child =", c.Name, ",", c.Type)
/*
if (c.Action == "SetMargin") {
log(debugError, "need to implement SetMargin here")
setMargin(c, c.B)
return
}
*/
switch c.Type {
/*
case toolkit.Window:
// doWindow(c)
case toolkit.Tab:
// doTab(p, c)
case toolkit.Group:
newGroup(p, c)
case toolkit.Button:
newButton(p, c)
case toolkit.Checkbox:
// doCheckbox(p, c)
case toolkit.Label:
// doLabel(p, c)
case toolkit.Textbox:
// doTextbox(p, c)
case toolkit.Slider:
// doSlider(p, c)
case toolkit.Spinner:
// doSpinner(p, c)
case toolkit.Dropdown:
// doDropdown(p, c)
case toolkit.Combobox:
// doCombobox(p, c)
case toolkit.Grid:
// doGrid(p, c)
*/
/*
case toolkit.Flag:
// log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type)
// log(debugFlags, "plugin Send() flag child =", c.Name, c.Type)
// log(debugFlags, "plugin Send() flag child.Action =", c.Action)
// log(debugFlags, "plugin Send() flag child.S =", c.S)
// log(debugFlags, "plugin Send() flag child.B =", c.B)
// log(debugFlags, "plugin Send() what to flag?")
// should set the checkbox to this value
switch c.S {
case "Toolkit":
debugToolkit = c.B
case "Change":
debugChange = c.B
case "Plugin":
debugPlugin = c.B
case "Flags":
debugFlags = c.B
case "Error":
debugError = c.B
case "Show":
ShowDebug()
default:
log(debugError, "Can't set unknown flag", c.S)
}
*/
default:
log(debugError, "plugin Send() unknown parent =", p.Name, p.Type)
log(debugError, "plugin Send() unknown child =", c.Name, c.Type)
log(debugError, "plugin Send() Don't know how to do", c.Type, "yet")
}
} }
func Action(a *toolkit.Action) { func Action(a *toolkit.Action) {
log(logNow, "Action() START a.Type =", a.Type) log(logNow, "Action()", a)
log(logNow, "Action() START a.S =", a.S) w := setupWidgetT(a)
log(logNow, "Action() START a.Widget =", a.Widget) place(w, a)
log(logInfo, "Action() END")
log(logNow, "Action() START a.WidgetId =", a.WidgetId, "a.WhereId =", a.WhereId)
switch a.Type {
case toolkit.Add:
log(logError, "Action() do add here() =", a.Type, a.Widget)
default:
log(logError, "Action() Unknown =", a.Type, a.Widget)
}
log(logNow, "Action() END =", a.Type, a.Widget)
} }

View File

@ -1,32 +1,127 @@
// Copyright 2014 The gocui Authors. All rights reserved. // LICENSE: same as the go language itself
// Use of this source code is governed by a BSD-style // Copyright 2023 WIT.COM
// license that can be found in the LICENSE file.
// all structures and variables are local (aka lowercase)
// since the plugin should be isolated to access only
// by functions() to insure everything here is run
// inside a dedicated goroutine
package main package main
import ( import (
"os" "fmt"
"sync"
"github.com/awesome-gocui/gocui" "github.com/awesome-gocui/gocui"
"git.wit.org/wit/gui/toolkit"
) )
const delta = 1 // const delta = 1
// It's probably a terrible idea to call this 'me'
var me config
type config struct {
highest int // highest widgetId
baseGui *gocui.Gui // the main gocui handle
widgets map[int]*cuiWidget
callback func(int)
helpLabel *gocui.View
defaultBehavior bool
defaultWidth int
defaultHeight int
nextW int // where the next window or tab flag should go
bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
canvas bool // if set to true, the windows are a raw canvas
menubar bool // for windows
stretchy bool // expand things like buttons to the maximum size
padded bool // add space between things like buttons
margin bool // add space around the frames of windows
}
/*
// This is a map between the widgets in wit/gui and the internal structures of gocui
var viewWidget map[*gocui.View]*toolkit.Widget
var stringWidget map[string]*toolkit.Widget
*/
var ( var (
g *gocui.Gui // g *gocui.Gui
Custom func(string) // Custom func(string)
initialMouseX, initialMouseY, xOffset, yOffset int initialMouseX, initialMouseY, xOffset, yOffset int
globalMouseDown, msgMouseDown, movingMsg bool globalMouseDown, msgMouseDown, movingMsg bool
views = []string{} // err error
curView = -1
idxView = 0
currentX = 5
currentY = 2
groupSize = 0
baseGui *gocui.Gui
helpLabel *gocui.View
err error
ch chan(func ())
outf *os.File
) )
// the gocui way
// the logical size of the widget
// corner starts at in the upper left corner
type rectType struct {
// this is the gocui way
w0, h0, w1, h1 int // left top right bottom
}
/*
type realSizeT struct {
width, height int
}
*/
type cuiWidget struct {
id int // widget ID
parentId int
widgetType toolkit.WidgetType
name string // a descriptive name of the widget
text string // the current text being displayed
visable bool // widget types like 'box' are 'false'
realWidth int // the real width
realHeight int // the real height
realSize rectType // the display size of this widget
logicalSize rectType // the logical size. Includes all the child widgets
nextX int
nextY int
// horizontal=true means layout widgets like books on a bookshelf
// horizontal=false means layout widgets like books in a stack
horizontal bool `default:false`
tainted bool
v *gocui.View
baseGui *gocui.Gui // use gogui.Manager ? as 'workspaces?'
// writeMutex protects locks the write process
writeMutex sync.Mutex
// deprecate
// logicalWidth int `default:8`
// logicalHeight int `default:2`
// rect rectType
// current rectType // the logical size. Includes all the child widgets
// width int
// height int
}
// from the gocui devs:
// Write appends a byte slice into the view's internal buffer. Because
// View implements the io.Writer interface, it can be passed as parameter
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
// be called to clear the view's buffer.
func (w *cuiWidget) Write(p []byte) (n int, err error) {
w.tainted = true
w.writeMutex.Lock()
defer w.writeMutex.Unlock()
// v.makeWriteable(v.wx, v.wy)
// v.writeRunes(bytes.Runes(p))
fmt.Fprintln(w.v, p)
log(logNow, "widget.Write()")
return len(p), nil
}

317
toolkit/democui/view.go Normal file
View File

@ -0,0 +1,317 @@
package main
import (
"fmt"
"errors"
"strconv"
"github.com/awesome-gocui/gocui"
"git.wit.org/wit/gui/toolkit"
)
var adjusted bool = false
// expands the logical size of the parents
func (w *cuiWidget) setParentLogical(p *cuiWidget) {
if (w.visable) {
// expand the parent logicalsize to include the widget realSize
if (p.logicalSize.w0 > w.realSize.w0) {
p.logicalSize.w0 = w.realSize.w0
adjusted = true
}
if (p.logicalSize.h0 > w.realSize.h0) {
p.logicalSize.h0 = w.realSize.h0
adjusted = true
}
if (p.logicalSize.w1 < w.realSize.w1) {
p.logicalSize.w1 = w.realSize.w1
adjusted = true
}
if (p.logicalSize.h1 < w.realSize.h1) {
p.logicalSize.h1 = w.realSize.h1
adjusted = true
}
} else {
// expand the parent logicalsize to include the widget logicalsize
if (p.logicalSize.w0 > w.logicalSize.w0) {
p.logicalSize.w0 = w.logicalSize.w0
adjusted = true
}
if (p.logicalSize.h0 > w.logicalSize.h0) {
p.logicalSize.h0 = w.logicalSize.h0
adjusted = true
}
if (p.logicalSize.w1 < w.logicalSize.w1) {
p.logicalSize.w1 = w.logicalSize.w1
adjusted = true
}
if (p.logicalSize.h1 < w.logicalSize.h1) {
p.logicalSize.h1 = w.logicalSize.h1
adjusted = true
}
}
if (w.visable) {
// adjust the widget realSize to the top left corner of the logicalsize
if (w.logicalSize.w0 > w.realSize.w0) {
w.realSize.w0 = w.logicalSize.w0
w.realSize.w1 = w.realSize.w0 + w.realWidth
adjusted = true
}
if (w.logicalSize.h0 > w.realSize.h0) {
w.realSize.h0 = w.logicalSize.h0
w.realSize.h1 = w.realSize.h0 + w.realHeight
adjusted = true
}
}
w.showWidgetPlacement(logNow, "setParentLogical() widget")
p.showWidgetPlacement(logNow, "setParentLogical() parent")
if (w.id == 0) || (p.id == 0) {
// stop resizing when you hit the root widget
return
}
// pass the logical resizing up
pP := me.widgets[p.parentId]
if (pP != nil) {
p.setParentLogical(pP)
}
}
var fakeStartWidth int = 80
var fakeStartHeight int = 0
func (w *cuiWidget) setFake() {
if (w.visable) {
return
}
// setup fake labels for non-visable things off screen
w.realWidth = me.defaultWidth
w.realHeight = me.defaultHeight
w.realSize.w0 = fakeStartWidth
w.realSize.h0 = fakeStartHeight
w.realSize.w1 = w.realSize.w0 + me.defaultWidth
w.realSize.h1 = w.realSize.h0 + me.defaultHeight
fakeStartHeight += 2
w.showWidgetPlacement(logNow, "setFake()")
}
func drawView(w *cuiWidget) *gocui.View {
var newName string = ""
newName = strconv.Itoa(w.id)
if (me.baseGui == nil) {
log(logError, "drawView() me.baseGui == nil")
return nil
}
a := w.realSize.w0
b := w.realSize.h0
c := w.realSize.w1
d := w.realSize.h1
v, err := me.baseGui.SetView(newName, a, b, c, d, 0)
if err == nil {
log(logError, "drawView() internal plugin error err = nil")
return nil
}
if !errors.Is(err, gocui.ErrUnknownView) {
log(logError, "drawView() internal plugin error error.IS()", err)
return nil
}
w.v = v
return v
}
func boxedPlace(w *cuiWidget) {
t := len(w.name)
if (w.id == 0) {
w.realWidth = 0
w.realHeight = 0
return
}
p := me.widgets[w.parentId]
if (p == nil) {
log(logError, "ERRRRRRRRRRRORRRRRRRRRRRRR: parentId widget == nil")
return
}
switch p.widgetType {
case toolkit.Box:
w.realWidth = t + 3
w.realHeight = me.defaultHeight
w.realSize.w0 = p.nextX
w.realSize.h0 = p.nextY
w.realSize.w1 = p.nextX + w.realWidth
w.realSize.h1 = p.nextY + w.realHeight
w.logicalSize.w0 = p.nextX
w.logicalSize.h0 = p.nextY
w.logicalSize.w1 = p.nextX + w.realWidth
w.logicalSize.h1 = p.nextY + w.realHeight
w.nextX = p.nextX
w.nextY = p.nextY
if (w.horizontal) {
log(logNow, "PARENT BOX IS HORIZONTAL")
p.nextX += w.realWidth
} else {
log(logNow, "PARENT BOX IS VERTICAL")
p.nextY += w.realHeight
}
case toolkit.Group:
w.realWidth = t + 3
w.realHeight = me.defaultHeight
w.realSize.w0 = p.nextX
w.realSize.h0 = p.nextY
w.realSize.w1 = p.nextX + w.realWidth
w.realSize.h1 = p.nextY + w.realHeight
w.logicalSize.w0 = p.nextX
w.logicalSize.h0 = p.nextY
w.logicalSize.w1 = p.nextX + w.realWidth
w.logicalSize.h1 = p.nextY + w.realHeight
w.nextX = w.logicalSize.w0 + 3 // default group padding
w.nextY = w.logicalSize.h1
// increment parent
p.nextY += w.realHeight
default:
w.realWidth = t + 3
w.realHeight = me.defaultHeight
w.realSize.w0 = p.nextX
w.realSize.h0 = p.nextY
w.realSize.w1 = w.realSize.w0 + w.realWidth
w.realSize.h1 = w.realSize.h0 + w.realHeight
// increment parent
p.nextY += w.realHeight
}
p.showWidgetPlacement(logNow, "bP parent")
w.showWidgetPlacement(logNow, "bP widget")
}
func findPlace(w *cuiWidget, a *toolkit.Action) {
t := len(w.name)
w.visable = true
switch w.widgetType {
case toolkit.Root:
w.visable = false
w.setFake()
w.showWidgetPlacement(logNow, "Root:")
case toolkit.Flag:
w.visable = false
w.setFake()
w.showWidgetPlacement(logNow, "Flag:")
case toolkit.Window:
w.realWidth = t + 3
w.realHeight = me.defaultHeight
w.realSize.w0 = me.nextW
w.realSize.h0 = 0
w.realSize.w1 = w.realSize.w0 + w.realWidth
w.realSize.h1 = w.realHeight
w.logicalSize.w0 = me.nextW
w.logicalSize.h0 = 0
w.logicalSize.w1 = w.logicalSize.w0 + w.realWidth
w.logicalSize.h1 = w.realHeight
w.nextX = w.logicalSize.w0 + t // default group padding
w.nextY = w.logicalSize.h1
me.nextW += w.realWidth
w.showWidgetPlacement(logNow, "window:")
case toolkit.Tab:
w.realWidth = t + 3
w.realHeight = me.defaultHeight
w.realSize.w0 = me.nextW
w.realSize.h0 = 0
w.realSize.w1 = w.realSize.w0 + w.realWidth
w.realSize.h1 = w.realHeight
w.logicalSize.w0 = me.nextW
w.logicalSize.h0 = 0
w.logicalSize.w1 = w.logicalSize.w0 + w.realWidth
w.logicalSize.h1 = w.realHeight
w.nextX = w.logicalSize.w0 + t // default group padding
w.nextY = w.logicalSize.h1
me.nextW += w.realWidth
w.showWidgetPlacement(logNow, "tab:")
case toolkit.Grid:
p := me.widgets[w.parentId]
w.horizontal = a.B
w.visable = false
w.setFake()
if (p == nil) {
log(logError, "ERRRRRRRRRRRORRRRRRRRRRRRR: parentId widget == nil")
return
}
w.logicalSize.w0 = p.nextX
w.logicalSize.h0 = p.nextY
w.logicalSize.w1 = p.nextX
w.logicalSize.h1 = p.nextY
w.nextX = p.nextX
w.nextY = p.nextY
w.showWidgetPlacement(logNow, "grid:")
case toolkit.Box:
p := me.widgets[w.parentId]
w.horizontal = a.B
w.visable = false
w.setFake()
if (p == nil) {
log(logError, "ERRRRRRRRRRRORRRRRRRRRRRRR: parentId widget == nil")
return
}
w.logicalSize.w0 = p.nextX
w.logicalSize.h0 = p.nextY
w.logicalSize.w1 = p.nextX
w.logicalSize.h1 = p.nextY
w.nextX = p.nextX
w.nextY = p.nextY
w.showWidgetPlacement(logNow, "box:")
case toolkit.Group:
p := me.widgets[w.parentId]
w.horizontal = a.B
w.visable = false
w.setFake()
if (p == nil) {
log(logError, "ERRRRRRRRRRRORRRRRRRRRRRRR: parentId widget == nil")
return
}
w.logicalSize.w0 = p.nextX
w.logicalSize.h0 = p.nextY
w.logicalSize.w1 = p.nextX
w.logicalSize.h1 = p.nextY
w.nextX = p.nextX
w.nextY = p.nextY
w.showWidgetPlacement(logNow, "group:")
default:
boxedPlace(w)
}
}
func place(w *cuiWidget, a *toolkit.Action) {
log(logInfo, "place() START")
findPlace(w, a)
v := drawView(w)
if (v == nil) {
log(logError, "place() drawView(w) returned nil")
return
}
me.baseGui.SetKeybinding(v.Name(), gocui.MouseLeft, gocui.ModNone, click)
v.Wrap = true
fmt.Fprintln(v, " " + w.name)
w.SetDefaultWidgetColor()
log(logInfo, "place() END")
return
}

View File

@ -88,6 +88,7 @@ func widgetDump(b bool, w *toolkit.Widget) {
return return
} }
/*
log(b, "widget.Name =", w.Name) log(b, "widget.Name =", w.Name)
// log(b, "widget.Action =", w.Action) // log(b, "widget.Action =", w.Action)
log(b, "widget.Type =", w.Type) log(b, "widget.Type =", w.Type)
@ -98,6 +99,7 @@ func widgetDump(b bool, w *toolkit.Widget) {
log(b, "widget.Height =", w.Height) log(b, "widget.Height =", w.Height)
log(b, "widget.X =", w.X) log(b, "widget.X =", w.X)
log(b, "widget.Y =", w.Y) log(b, "widget.Y =", w.Y)
*/
} }
/* /*

View File

@ -7,6 +7,8 @@ type ActionType int
// //
// All Toolkit interactions should be done via a channel or Queue() // All Toolkit interactions should be done via a channel or Queue()
// TODO: FIGURE OUT HOW TO IMPLEMENT THIS // TODO: FIGURE OUT HOW TO IMPLEMENT THIS
// https://ieftimov.com/post/golang-datastructures-trees/
// TODO: protobuf ?
// //
// This is the only thing that is passed between the toolkit plugin // This is the only thing that is passed between the toolkit plugin
// //
@ -28,7 +30,7 @@ type Widget struct {
Callback func() Callback func()
// re-adding an id to test channels // re-adding an id to test channels
id int Id int
// This is how the values are passed back and forth // This is how the values are passed back and forth
// values from things like checkboxes & dropdown's // values from things like checkboxes & dropdown's
@ -38,30 +40,17 @@ type Widget struct {
// maybe safe if there is correctly working Custom() between goroutines? // maybe safe if there is correctly working Custom() between goroutines?
// (still probably not, almost certainly not. not possible. layer violation?) // (still probably not, almost certainly not. not possible. layer violation?)
S string // not safe to have 'S' S string // not safe to have 'S'
// This GUI is intended for simple things
// We are not laying out PDF's here
// This is used for things like a slider(0,100)
Width int
Height int
X int
Y int
// Put space around elements to improve look & feel
Margin bool
// Make widgets fill up the space available
Expand bool
} }
type Action struct { type Action struct {
Type ActionType ActionType ActionType
ActionT ActionType WidgetType WidgetType
WidgetT WidgetType
WidgetId int WidgetId int
WhereId int ParentId int
Title string
Text string // what is visable to the user
Name string // a name useful for programming
// this should be the widget // this should be the widget
// if the action is New, Hide, Enable, etc // if the action is New, Hide, Enable, etc
@ -92,31 +81,30 @@ type Action struct {
Expand bool Expand bool
} }
// https://ieftimov.com/post/golang-datastructures-trees/
// TODO: protobuf ?
const ( const (
Unknown WidgetType = iota Unknown WidgetType = iota
Window Root // the master 'root' node of the binary tree
Tab // internally, this should be a window (?) Flag // used to send configuration values to plugins
Frame // should windows and tab's be frames (?) Window // in certain gui's (ncurses), these are tabs
Grid // a grid of frames ? Tab // internally, this is a window
Group // internally, this should be a grid (?) Frame // deprecate?
Box // internally, this should be a grid (?) Grid // like drawers in a chest
Group // like the 'Appetizers' section on a menu
Box // a vertical or horizontal stack of widgets
Button Button
Checkbox Checkbox // select 'on' or 'off'
Dropdown Dropdown
Combobox // dropdown with edit=true (?) Combobox // dropdown with edit=true
Label Label
Textbox // is this a Label with edit=true? Textbox // is this a Label with edit=true
Slider Slider // like a progress bar
Spinner Spinner // like setting the oven temperature
Image Image // TODO
Area Area // TODO
Form Form // TODO
Font Font // TODO
Color Color // TODO
Dialog Dialog // TODO
) )
const ( const (
@ -124,7 +112,6 @@ const (
Delete Delete
Get Get
Set Set
SetFlag
GetText GetText
SetText SetText
AddText AddText
@ -139,11 +126,14 @@ const (
Append Append
Move Move
Dump Dump
Flag
) )
func (s WidgetType) String() string { func (s WidgetType) String() string {
switch s { switch s {
case Root:
return "Root"
case Flag:
return "Flag"
case Window: case Window:
return "Window" return "Window"
case Tab: case Tab:
@ -187,7 +177,7 @@ func (s WidgetType) String() string {
case Unknown: case Unknown:
return "Unknown" return "Unknown"
} }
return "Widget.Type.String() Error" return "WidgetType.String() Error"
} }
func (s ActionType) String() string { func (s ActionType) String() string {
@ -200,8 +190,6 @@ func (s ActionType) String() string {
return "Get" return "Get"
case Set: case Set:
return "Set" return "Set"
case SetFlag:
return "SetFlag"
case GetText: case GetText:
return "GetText" return "GetText"
case SetText: case SetText:
@ -228,22 +216,8 @@ func (s ActionType) String() string {
return "Append" return "Append"
case Move: case Move:
return "Move" return "Move"
case Flag:
return "Flag"
case Dump: case Dump:
return "Dump" return "Dump"
} }
return "Action.Type.String() Error" return "ActionType.String() Error"
}
// this is hopefully just used in a very few places for
// debuging the interaction between go apps and the underlying
// toolkits. Hopefully this is less prone to problems and can
// detect memory leaks, threading problems, memory allocation & mapping errors, etc
func (w *Widget) GetId() int {
return w.id
}
func (w *Widget) SetId(i int) {
w.id = i
} }

View File

@ -34,16 +34,15 @@ func NewWindow() *Node {
} }
} }
// Windows are created off of the master node of the Binary Tree // Windows are created off of the master node of the Binary Tree
newNode = Config.master.New(Config.Title, toolkit.Window, custom) newNode = Config.rootNode.New(Config.Title, toolkit.Window, custom)
newNode.widget.Width = Config.Width log(logInfo, "NewWindow()", Config.Title)
newNode.widget.Height = Config.Height
log(debugGui, "Window()", Config.Title)
var a toolkit.Action var a toolkit.Action
a.Type = toolkit.Add a.ActionType = toolkit.Add
newaction(&a, newNode, Config.master) a.Width = Config.Width
a.Height = Config.Height
newaction(&a, newNode, Config.rootNode)
return newNode return newNode
} }