further code cleanups
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bafb7eb06b
commit
a132b48ada
|
@ -107,6 +107,12 @@ external things which might be useful
|
|||
* [GO Style Guide]
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||
```golang
|
||||
var Config guiConfig
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
### func [DebugWidgetWindow](/debugWidget.go#L52)
|
||||
|
@ -123,7 +129,7 @@ Creates a window helpful for debugging this package
|
|||
|
||||
`func ExampleCatcher(f func())`
|
||||
|
||||
### func [Indent](/debug.go#L126)
|
||||
### func [Indent](/debug.go#L127)
|
||||
|
||||
`func Indent(b bool, a ...interface{})`
|
||||
|
||||
|
@ -139,7 +145,7 @@ Creates a window helpful for debugging this package
|
|||
|
||||
`func ShowDebugValues()`
|
||||
|
||||
### func [StandardExit](/main.go#L231)
|
||||
### func [StandardExit](/main.go#L219)
|
||||
|
||||
`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
|
||||
|
||||
### type [GuiConfig](/structs.go#L33)
|
||||
|
||||
`type GuiConfig struct { ... }`
|
||||
|
||||
#### Variables
|
||||
|
||||
```golang
|
||||
var Config GuiConfig
|
||||
```
|
||||
|
||||
### type [Node](/structs.go#L63)
|
||||
### type [Node](/structs.go#L55)
|
||||
|
||||
`type Node struct { ... }`
|
||||
|
||||
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
|
||||
|
||||
#### func [New](/main.go#L202)
|
||||
#### func [New](/main.go#L190)
|
||||
|
||||
`func New() *Node`
|
||||
|
||||
|
|
15
debug.go
15
debug.go
|
@ -96,16 +96,12 @@ func ShowDebugValues() {
|
|||
SetFlag("Show", true)
|
||||
}
|
||||
|
||||
func (n *Node) Dump(b bool) {
|
||||
func (n *Node) Dump() {
|
||||
b := true
|
||||
// log("Dump() dump =", b)
|
||||
if ! b {
|
||||
return
|
||||
}
|
||||
Indent(b, "NODE DUMP START")
|
||||
Indent(b, "id = ", n.id)
|
||||
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, "Next (X,Y) = ", n.NextX, n.NextY)
|
||||
|
||||
|
@ -121,6 +117,11 @@ func (n *Node) Dump(b bool) {
|
|||
Indent(b, "Custom = ", n.Custom)
|
||||
}
|
||||
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{}) {
|
||||
|
@ -154,7 +155,6 @@ func (n *Node) ListChildren(dump bool) {
|
|||
}
|
||||
|
||||
n.dumpWidget(dump)
|
||||
// n.Dump(dump)
|
||||
if len(n.children) == 0 {
|
||||
if (n.parent == nil) {
|
||||
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?
|
||||
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) {
|
||||
log(debugNode, "\t\t", child.id, "has no children")
|
||||
} else {
|
||||
|
|
|
@ -105,11 +105,7 @@ func DebugWidgetWindow(w *Node) {
|
|||
activeWidget.Hide()
|
||||
})
|
||||
g.NewButton("Dump()", func () {
|
||||
activeWidget.Dump(true)
|
||||
|
||||
var a toolkit.Action
|
||||
a.ActionType = toolkit.Dump
|
||||
newaction(&a, activeWidget, nil)
|
||||
activeWidget.Dump()
|
||||
})
|
||||
|
||||
g = bugWidget.NewGroup("add things")
|
||||
|
@ -266,7 +262,7 @@ func (n *Node) debugAddWidgetButton() {
|
|||
log("activeWidget.NextX =", activeWidget.NextX)
|
||||
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)
|
||||
activeWidget.Dump(true)
|
||||
activeWidget.Dump()
|
||||
|
||||
// activeWidget.X = newX
|
||||
// activeWidget.Y = newY
|
||||
|
|
|
@ -121,7 +121,7 @@ func dropdownWindow(p *Node) {
|
|||
|
||||
// var last = ""
|
||||
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)
|
||||
// last = child.Name
|
||||
mapWindows[child.Name] = child
|
||||
|
|
14
main.go
14
main.go
|
@ -14,23 +14,11 @@ import (
|
|||
const Xaxis = 0 // stack things horizontally
|
||||
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() {
|
||||
log("init() has been run")
|
||||
|
||||
Config.counter = 0
|
||||
Config.prefix = "wit"
|
||||
Config.Width = 640
|
||||
Config.Height = 480
|
||||
|
||||
// Populates the top of the binary tree
|
||||
Config.rootNode = addNode("guiBinaryTree")
|
||||
|
@ -74,7 +62,7 @@ func watchCallback() {
|
|||
}
|
||||
// this maybe a good idea?
|
||||
// TODO: Throttle user events somehow
|
||||
sleep(.1)
|
||||
sleep(.01)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
node.go
22
node.go
|
@ -12,7 +12,7 @@ func (n *Node) newNode(title string, t toolkit.WidgetType, custom func()) *Node
|
|||
newN.WidgetType = t
|
||||
newN.Custom = custom
|
||||
|
||||
n.Append(newN)
|
||||
n.children = append(n.children, newN)
|
||||
newN.parent = n
|
||||
return newN
|
||||
}
|
||||
|
@ -35,30 +35,14 @@ func (n *Node) Parent() *Node {
|
|||
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) {
|
||||
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) {
|
||||
log(debugNode, "\t\t Deleting this")
|
||||
n.children = append(n.children[:i], n.children[i+1:]...)
|
||||
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)
|
||||
}
|
||||
|
|
32
structs.go
32
structs.go
|
@ -21,7 +21,7 @@ import (
|
|||
// 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
|
||||
type GuiArgs struct {
|
||||
|
@ -30,32 +30,24 @@ type GuiArgs struct {
|
|||
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
|
||||
rootNode *Node
|
||||
|
||||
// A node off of rootNode for passing debugging flags
|
||||
flag *Node
|
||||
|
||||
// These are shortcuts to pass default values to make a new window
|
||||
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
|
||||
counter int // used to make unique WidgetId's
|
||||
|
||||
// sets the chan for the plugins to call back too
|
||||
guiChan chan toolkit.Action
|
||||
|
||||
// option to pass in compiled plugins as embedded files
|
||||
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
|
||||
|
@ -64,18 +56,14 @@ type Node struct {
|
|||
id int
|
||||
initOnce sync.Once
|
||||
|
||||
// widget toolkit.Widget
|
||||
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
|
||||
Name string // a name useful for programming
|
||||
|
||||
// used for Windows
|
||||
Width int
|
||||
Height int
|
||||
// used for Windows in toolkits measured in pixels
|
||||
width int
|
||||
height int
|
||||
|
||||
// used for anything that needs a range
|
||||
X int
|
||||
|
|
|
@ -10,14 +10,14 @@ func (n *Node) NewWindow(title string) *Node {
|
|||
var newNode *Node
|
||||
|
||||
// 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
|
||||
a.ActionType = toolkit.Add
|
||||
a.X = Config.Width
|
||||
a.Y = Config.Height
|
||||
a.X = n.X
|
||||
a.Y = n.Y
|
||||
a.Name = title
|
||||
a.Text = title
|
||||
newaction(&a, newNode, n)
|
||||
|
|
Loading…
Reference in New Issue