more code cleanups

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-05-09 20:25:37 -05:00
parent 48575ec782
commit e206fa143e
21 changed files with 50 additions and 105 deletions

2
box.go
View File

@ -5,7 +5,7 @@ import (
)
func (parent *Node) NewBox(name string, b bool) *Node {
newNode := parent.newNode(name, toolkit.Box, nil)
newNode := parent.newNode(name, toolkit.Box)
newNode.B = b
a := newAction(newNode, toolkit.Add)

View File

@ -3,7 +3,8 @@ package gui
import "git.wit.org/wit/gui/toolkit"
func (parent *Node) NewButton(name string, custom func()) *Node {
newNode := parent.newNode(name, toolkit.Button, custom)
newNode := parent.newNode(name, toolkit.Button)
newNode.Custom = custom
a := newAction(newNode, toolkit.Add)
sendAction(a)

View File

@ -7,7 +7,7 @@ func (n *Node) Checked() bool {
}
func (n *Node) NewCheckbox(name string) *Node {
newNode := n.newNode(name, toolkit.Checkbox, nil)
newNode := n.newNode(name, toolkit.Checkbox)
a := newAction(newNode, toolkit.Add)
sendAction(a)

View File

@ -20,7 +20,7 @@ func (n *Node) SetDropdownName(name string) {
}
func (n *Node) NewDropdown(name string) *Node {
newNode := n.newNode(name, toolkit.Dropdown, nil)
newNode := n.newNode(name, toolkit.Dropdown)
a := newAction(newNode, toolkit.Add)
sendAction(a)
@ -29,7 +29,7 @@ func (n *Node) NewDropdown(name string) *Node {
}
func (n *Node) NewCombobox(name string) *Node {
newNode := n.newNode(name, toolkit.Combobox, nil)
newNode := n.newNode(name, toolkit.Combobox)
a := newAction(newNode, toolkit.Add)
sendAction(a)

10
grid.go
View File

@ -23,21 +23,15 @@ import (
// -----------------------------
func (n *Node) NewGrid(name string, w int, h int) *Node {
newNode := n.newNode(name, toolkit.Grid, func() {
log(debugChange, "click() NewGrid not defined =", name)
})
newNode := n.newNode(name, toolkit.Grid)
a := newAction(newNode, toolkit.Add)
a.X = w
a.Y = h
newNode.X = w
newNode.Y = h
newNode.NextW = 1
newNode.NextH = 1
a := newAction(newNode, toolkit.Add)
sendAction(a)
return newNode
}

View File

@ -9,7 +9,7 @@ import (
// pre-canned andlabs/ui gtk,macos,windows thing
func (parent *Node) NewGroup(name string) *Node {
var newNode *Node
newNode = parent.newNode(name, toolkit.Group, nil)
newNode = parent.newNode(name, toolkit.Group)
a := newAction(newNode, toolkit.Add)
sendAction(a)

View File

@ -6,7 +6,7 @@ import (
func (parent *Node) NewImage(name string) *Node {
var newNode *Node
newNode = parent.newNode(name, toolkit.Image, nil)
newNode = parent.newNode(name, toolkit.Image)
a := newAction(newNode, toolkit.Add)
sendAction(a)

View File

@ -5,7 +5,7 @@ import (
)
func (parent *Node) NewLabel(text string) *Node {
newNode := parent.newNode(text, toolkit.Label, nil)
newNode := parent.newNode(text, toolkit.Label)
a := newAction(newNode, toolkit.Add)
sendAction(a)
return newNode

View File

@ -24,10 +24,10 @@ func init() {
me.rootNode.WidgetType = toolkit.Root
// used to pass debugging flags to the toolkit plugins
me.flag = me.rootNode.newNode("flag", 0, nil)
me.flag = me.rootNode.newNode("flag", 0)
me.flag.WidgetType = toolkit.Flag
me.flag = me.rootNode.newNode("stdout", 0, nil)
me.flag = me.rootNode.newNode("stdout", 0)
me.flag.WidgetType = toolkit.Stdout
me.guiChan = make(chan toolkit.Action, 1)

View File

@ -5,12 +5,11 @@ import "git.wit.org/wit/gui/toolkit"
/*
generic function to create a new node on the binary tree
*/
func (n *Node) newNode(title string, t toolkit.WidgetType, custom func()) *Node {
func (n *Node) newNode(title string, t toolkit.WidgetType) *Node {
var newN *Node
newN = addNode(title)
newN.WidgetType = t
newN.Custom = custom
if n.WidgetType == toolkit.Grid {
n.gridIncrement()

View File

@ -5,9 +5,11 @@ import (
)
func (parent *Node) NewSlider(name string, x int, y int) *Node {
newNode := parent.newNode(name, toolkit.Slider, func() {
newNode := parent.newNode(name, toolkit.Slider)
newNode.Custom = func() {
log(debugGui, "even newer clicker() name in NewSlider name =", name)
})
}
newNode.X = x
newNode.Y = y

View File

@ -5,9 +5,11 @@ import (
)
func (parent *Node) NewSpinner(name string, x int, y int) *Node {
newNode := parent.newNode(name, toolkit.Spinner, func() {
newNode := parent.newNode(name, toolkit.Spinner)
newNode.Custom = func() {
log(debugChange, "default NewSpinner() change", name)
})
}
newNode.X = x
newNode.Y = y

2
tab.go
View File

@ -28,7 +28,7 @@ func (n *Node) NewTab(text string) *Node {
// go up the binary tree until we find a window widget to add a tab too
return n.parent.NewTab(text)
}
newNode := n.newNode(text, toolkit.Tab, nil)
newNode := n.newNode(text, toolkit.Tab)
a := newAction(newNode, toolkit.Add)
sendAction(a)

View File

@ -5,9 +5,11 @@ import (
)
func (parent *Node) NewTextbox(name string) *Node {
newNode := parent.newNode(name, toolkit.Textbox, func() {
newNode := parent.newNode(name, toolkit.Textbox)
newNode.Custom = func() {
log(debugGui, "NewTextbox changed =", name)
})
}
a := newAction(newNode, toolkit.Add)
sendAction(a)

View File

@ -108,12 +108,12 @@ func (p *node) place(n *node) bool {
switch p.WidgetType {
case toolkit.Grid:
log(debugGrid, "place() Grid try at Parent X,Y =", n.X, n.Y)
n.tk.gridX = n.X
n.tk.gridY = n.Y
n.tk.gridX = n.AtW - 1
n.tk.gridY = n.AtH - 1
log(debugGrid, "place() Grid try at gridX,gridY", n.tk.gridX, n.tk.gridY)
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
p.tk.uiGrid.Append(n.tk.uiControl,
n.tk.gridY - 1, n.tk.gridX - 1, 1, 1,
n.tk.gridY, n.tk.gridX, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
return true
case toolkit.Group:

View File

@ -19,8 +19,6 @@ func (p *node) newGrid(n *node) {
c := ui.NewGrid()
newt.uiGrid = c
newt.uiControl = c
newt.gridX = 0
newt.gridY = 0
n.tk = newt
p.place(n)

View File

@ -1,72 +0,0 @@
// myplugin/myplugin.go
package main
/*
from chatgpt:
// put this in widget.go
import (
"fmt"
// "toolkit"
)
type Plugin interface {
Process(input chan string, output chan string)
}
// put this in wit/gui/toolkit/*
type myPlugin struct{}
var Plugin myPlugin
func (p *myPlugin) Process(input chan string, output chan string) {
go func() {
for msg := range input {
// Your processing logic goes here
result := fmt.Sprintf("Processed: %s", msg)
output <- result
}
}()
}
// main.go put this in wit/gui
package main
import (
"fmt"
"plugin"
"pluginapi"
)
func main() {
plug, err := plugin.Open("myplugin.so")
if err != nil {
panic(err)
}
symPlugin, err := plug.Lookup("Plugin")
if err != nil {
panic(err)
}
p, ok := symPlugin.(pluginapi.Plugin)
if !ok {
panic("Invalid plugin type")
}
input := make(chan string)
output := make(chan string)
p.Process(input, output)
input <- "Hello, World!"
close(input)
for result := range output {
fmt.Println(result)
}
}
*/
// func main() {}

View File

@ -32,6 +32,12 @@ type node struct {
X int
Y int
// This is for the grid size & widget position
W int
H int
AtW int
AtH int
// the internal plugin toolkit structure
tk *andlabsT
}

View File

@ -35,9 +35,15 @@ func addWidget(a *toolkit.Action) *node {
n.I = a.I
n.S = a.S
n.B = a.B
n.X = a.X
n.Y = a.Y
n.W = a.W
n.H = a.H
n.AtW = a.AtW
n.AtH = a.AtH
// store the internal toolkit information
n.tk = new(nocuiT)

View File

@ -27,6 +27,12 @@ type node struct {
X int
Y int
// This is for the grid size & widget position
W int
H int
AtW int
AtH int
// the internal plugin toolkit structure
tk *nocuiT
}

View File

@ -10,7 +10,8 @@ func (parent *Node) NewWindow(title string) *Node {
var newNode *Node
// Windows are created off of the master node of the Binary Tree
newNode = parent.newNode(title, toolkit.Window, StandardExit)
newNode = parent.newNode(title, toolkit.Window)
newNode.Custom = StandardExit
log(logInfo, "NewWindow()", title)