further code cleanups

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-28 10:30:27 -05:00
parent bafb7eb06b
commit a132b48ada
8 changed files with 38 additions and 87 deletions

View File

@ -107,6 +107,12 @@ external things which might be useful
* [GO Style Guide] * [GO Style Guide]
``` ```
## Variables
```golang
var Config guiConfig
```
## Functions ## Functions
### func [DebugWidgetWindow](/debugWidget.go#L52) ### func [DebugWidgetWindow](/debugWidget.go#L52)
@ -123,7 +129,7 @@ Creates a window helpful for debugging this package
`func ExampleCatcher(f func())` `func ExampleCatcher(f func())`
### func [Indent](/debug.go#L126) ### func [Indent](/debug.go#L127)
`func Indent(b bool, a ...interface{})` `func Indent(b bool, a ...interface{})`
@ -139,7 +145,7 @@ Creates a window helpful for debugging this package
`func ShowDebugValues()` `func ShowDebugValues()`
### func [StandardExit](/main.go#L231) ### func [StandardExit](/main.go#L219)
`func StandardExit()` `func StandardExit()`
@ -163,24 +169,14 @@ This goroutine can be used like a watchdog timer
This struct can be used with the go-arg package This struct can be used with the go-arg package
### type [GuiConfig](/structs.go#L33) ### type [Node](/structs.go#L55)
`type GuiConfig struct { ... }`
#### Variables
```golang
var Config GuiConfig
```
### type [Node](/structs.go#L63)
`type Node struct { ... }` `type Node struct { ... }`
The Node is a binary tree. This is how all GUI elements are stored The Node is a binary tree. This is how all GUI elements are stored
simply the name and the size of whatever GUI element exists simply the name and the size of whatever GUI element exists
#### func [New](/main.go#L202) #### func [New](/main.go#L190)
`func New() *Node` `func New() *Node`

View File

@ -96,16 +96,12 @@ func ShowDebugValues() {
SetFlag("Show", true) SetFlag("Show", true)
} }
func (n *Node) Dump(b bool) { func (n *Node) Dump() {
b := true
// log("Dump() dump =", b) // log("Dump() dump =", b)
if ! b {
return
}
Indent(b, "NODE DUMP START") Indent(b, "NODE DUMP START")
Indent(b, "id = ", n.id) Indent(b, "id = ", n.id)
Indent(b, "Name = ", n.Name) Indent(b, "Name = ", n.Name)
Indent(b, "Width = ", n.Width)
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)
@ -121,6 +117,11 @@ func (n *Node) Dump(b bool) {
Indent(b, "Custom = ", n.Custom) Indent(b, "Custom = ", n.Custom)
} }
Indent(b, "NODE DUMP END") Indent(b, "NODE DUMP END")
var a toolkit.Action
a.ActionType = toolkit.Dump
a.WidgetId = n.id
newaction(&a, activeWidget, nil)
} }
func Indent(b bool, a ...interface{}) { func Indent(b bool, a ...interface{}) {
@ -154,7 +155,6 @@ func (n *Node) ListChildren(dump bool) {
} }
n.dumpWidget(dump) n.dumpWidget(dump)
// n.Dump(dump)
if len(n.children) == 0 { if len(n.children) == 0 {
if (n.parent == nil) { if (n.parent == nil) {
return return
@ -181,7 +181,6 @@ func (n *Node) ListChildren(dump bool) {
// can all binary tree changes to Node.parent & Node.child be forced into a singular goroutine? // can all binary tree changes to Node.parent & Node.child be forced into a singular goroutine?
panic("something is wrong with the wit golang gui logic and the binary tree is broken. child has no parent") panic("something is wrong with the wit golang gui logic and the binary tree is broken. child has no parent")
} }
child.Dump(debugDump)
if (child.children == nil) { if (child.children == nil) {
log(debugNode, "\t\t", child.id, "has no children") log(debugNode, "\t\t", child.id, "has no children")
} else { } else {

View File

@ -105,11 +105,7 @@ func DebugWidgetWindow(w *Node) {
activeWidget.Hide() activeWidget.Hide()
}) })
g.NewButton("Dump()", func () { g.NewButton("Dump()", func () {
activeWidget.Dump(true) activeWidget.Dump()
var a toolkit.Action
a.ActionType = toolkit.Dump
newaction(&a, activeWidget, nil)
}) })
g = bugWidget.NewGroup("add things") g = bugWidget.NewGroup("add things")
@ -266,7 +262,7 @@ func (n *Node) debugAddWidgetButton() {
log("activeWidget.NextX =", activeWidget.NextX) log("activeWidget.NextX =", activeWidget.NextX)
log("activeWidget.NextY =", activeWidget.NextY) log("activeWidget.NextY =", activeWidget.NextY)
log(debugNow, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (X,Y) =", activeWidget.NextX, activeWidget.NextY) log(debugNow, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (X,Y) =", activeWidget.NextX, activeWidget.NextY)
activeWidget.Dump(true) activeWidget.Dump()
// activeWidget.X = newX // activeWidget.X = newX
// activeWidget.Y = newY // activeWidget.Y = newY

View File

@ -121,7 +121,7 @@ func dropdownWindow(p *Node) {
// var last = "" // var last = ""
for _, child := range Config.rootNode.children { for _, child := range Config.rootNode.children {
log(debugGui, "\t\t", child.id, child.Width, child.Height, child.Name) log(logInfo, "\t\t", child.id, child.Name)
dd.AddDropdownName(child.Name) dd.AddDropdownName(child.Name)
// last = child.Name // last = child.Name
mapWindows[child.Name] = child mapWindows[child.Name] = child

14
main.go
View File

@ -14,23 +14,11 @@ import (
const Xaxis = 0 // stack things horizontally const Xaxis = 0 // stack things horizontally
const Yaxis = 1 // stack things vertically const Yaxis = 1 // stack things vertically
/*
// TODO: 2023/03/03 rethink how to get a plugin or figure out how
// golang packages can include a binary. Pull from /usr/go/go-gui/ ?
// may this plugin work when all other plugins fail
// if this is in the plugin, the packages can't work with go.mod builds
# don't do this in the plugin // go:embed /usr/lib/go-gui/toolkit/gocui.so
# don't do this in the plugin var res embed.FS
*/
func init() { func init() {
log("init() has been run") log("init() has been run")
Config.counter = 0 Config.counter = 0
Config.prefix = "wit" Config.prefix = "wit"
Config.Width = 640
Config.Height = 480
// Populates the top of the binary tree // Populates the top of the binary tree
Config.rootNode = addNode("guiBinaryTree") Config.rootNode = addNode("guiBinaryTree")
@ -74,7 +62,7 @@ func watchCallback() {
} }
// this maybe a good idea? // this maybe a good idea?
// TODO: Throttle user events somehow // TODO: Throttle user events somehow
sleep(.1) sleep(.01)
} }
} }
} }

22
node.go
View File

@ -12,7 +12,7 @@ func (n *Node) newNode(title string, t toolkit.WidgetType, custom func()) *Node
newN.WidgetType = t newN.WidgetType = t
newN.Custom = custom newN.Custom = custom
n.Append(newN) n.children = append(n.children, newN)
newN.parent = n newN.parent = n
return newN return newN
} }
@ -35,30 +35,14 @@ func (n *Node) Parent() *Node {
return n.parent return n.parent
} }
/*
func (n *Node) Window() *Node {
return n.parent
}
*/
func (n *Node) Append(child *Node) {
n.children = append(n.children, child)
if (debugNode) {
log(debugNode, "child node:")
child.Dump(debugDump)
log(debugNode, "parent node:")
n.Dump(debugDump)
}
}
func (n *Node) Delete(d *Node) { func (n *Node) Delete(d *Node) {
for i, child := range n.children { for i, child := range n.children {
log(debugNode, "\t", i, child.id, child.Width, child.Height, child.Name) log(debugNode, "\t", i, child.id, child.Name)
if (child.id == d.id) { if (child.id == d.id) {
log(debugNode, "\t\t Deleting this") log(debugNode, "\t\t Deleting this")
n.children = append(n.children[:i], n.children[i+1:]...) n.children = append(n.children[:i], n.children[i+1:]...)
return return
} }
} }
log(debugError, "did not find node to delete", d.id, d.Width, d.Height, d.Name) log(debugError, "did not find node to delete", d.id, d.Name)
} }

View File

@ -21,7 +21,7 @@ import (
// For example, a "Mouse Control Panel" not the GIMP or blender. // For example, a "Mouse Control Panel" not the GIMP or blender.
// //
var Config GuiConfig var Config guiConfig
// This struct can be used with the go-arg package // This struct can be used with the go-arg package
type GuiArgs struct { type GuiArgs struct {
@ -30,32 +30,24 @@ type GuiArgs struct {
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"` GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
} }
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
rootNode *Node rootNode *Node
// A node off of rootNode 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 counter int // used to make unique WidgetId's
Title string
Width int
Height int
Exit func(*Node)
// hacks
depth int
counter int // used to make unique ID's
prefix string
ActionCh1 chan int
ActionCh2 chan int
// sets the chan for the plugins to call back too // sets the chan for the plugins to call back too
guiChan chan toolkit.Action guiChan chan toolkit.Action
// option to pass in compiled plugins as embedded files // option to pass in compiled plugins as embedded files
resFS embed.FS resFS embed.FS
// used to beautify logging to Stdout
depth int
prefix string
} }
// The Node is a binary tree. This is how all GUI elements are stored // The Node is a binary tree. This is how all GUI elements are stored
@ -64,18 +56,14 @@ type Node struct {
id int id int
initOnce sync.Once initOnce sync.Once
// widget toolkit.Widget
WidgetType toolkit.WidgetType WidgetType toolkit.WidgetType
// Title string // what is visable to the user
// Desc string // a name useful for programming
Text string // what is visable to the user Text string // what is visable to the user
Name string // a name useful for programming Name string // a name useful for programming
// used for Windows // used for Windows in toolkits measured in pixels
Width int width int
Height int height int
// used for anything that needs a range // used for anything that needs a range
X int X int

View File

@ -10,14 +10,14 @@ func (n *Node) NewWindow(title string) *Node {
var newNode *Node var newNode *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 = n.newNode(Config.Title, toolkit.Window, StandardExit) newNode = n.newNode(title, toolkit.Window, StandardExit)
log(logInfo, "NewWindow()", Config.Title) log(logInfo, "NewWindow()", title)
var a toolkit.Action var a toolkit.Action
a.ActionType = toolkit.Add a.ActionType = toolkit.Add
a.X = Config.Width a.X = n.X
a.Y = Config.Height a.Y = n.Y
a.Name = title a.Name = title
a.Text = title a.Text = title
newaction(&a, newNode, n) newaction(&a, newNode, n)