From e206fa143e6107eb5fb787a3f3dfeb83a16af527 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 9 May 2023 20:25:37 -0500 Subject: [PATCH] more code cleanups Signed-off-by: Jeff Carr --- box.go | 2 +- button.go | 3 +- checkbox.go | 2 +- dropdown.go | 4 +-- grid.go | 10 ++---- group.go | 2 +- image.go | 2 +- label.go | 2 +- main.go | 4 +-- node.go | 3 +- slider.go | 6 ++-- spinner.go | 6 ++-- tab.go | 2 +- textbox.go | 6 ++-- toolkit/andlabs/add.go | 6 ++-- toolkit/andlabs/grid.go | 2 -- toolkit/andlabs/process.go | 72 -------------------------------------- toolkit/andlabs/structs.go | 6 ++++ toolkit/nocui/common.go | 6 ++++ toolkit/nocui/structs.go | 6 ++++ window.go | 3 +- 21 files changed, 50 insertions(+), 105 deletions(-) delete mode 100644 toolkit/andlabs/process.go diff --git a/box.go b/box.go index a864e80..122d685 100644 --- a/box.go +++ b/box.go @@ -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) diff --git a/button.go b/button.go index 6204efe..ccd7670 100644 --- a/button.go +++ b/button.go @@ -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) diff --git a/checkbox.go b/checkbox.go index 502acb4..db3eb19 100644 --- a/checkbox.go +++ b/checkbox.go @@ -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) diff --git a/dropdown.go b/dropdown.go index ce49db6..cd00bf3 100644 --- a/dropdown.go +++ b/dropdown.go @@ -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) diff --git a/grid.go b/grid.go index 103b8f7..6b2df82 100644 --- a/grid.go +++ b/grid.go @@ -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 } diff --git a/group.go b/group.go index 2c1974d..3f49a0f 100644 --- a/group.go +++ b/group.go @@ -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) diff --git a/image.go b/image.go index 16f7e9b..5d566ee 100644 --- a/image.go +++ b/image.go @@ -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) diff --git a/label.go b/label.go index 3adab5b..4525769 100644 --- a/label.go +++ b/label.go @@ -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 diff --git a/main.go b/main.go index 4017314..17b69ba 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/node.go b/node.go index 93d0ca8..daba6d5 100644 --- a/node.go +++ b/node.go @@ -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() diff --git a/slider.go b/slider.go index 3f18b35..ffb041a 100644 --- a/slider.go +++ b/slider.go @@ -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 diff --git a/spinner.go b/spinner.go index bfbf5bf..d24bf16 100644 --- a/spinner.go +++ b/spinner.go @@ -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 diff --git a/tab.go b/tab.go index 82f6289..95d9fa4 100644 --- a/tab.go +++ b/tab.go @@ -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) diff --git a/textbox.go b/textbox.go index 5877b32..5b416a7 100644 --- a/textbox.go +++ b/textbox.go @@ -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) diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go index 9d40b4f..c25603d 100644 --- a/toolkit/andlabs/add.go +++ b/toolkit/andlabs/add.go @@ -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: diff --git a/toolkit/andlabs/grid.go b/toolkit/andlabs/grid.go index 60e2ebf..8764962 100644 --- a/toolkit/andlabs/grid.go +++ b/toolkit/andlabs/grid.go @@ -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) diff --git a/toolkit/andlabs/process.go b/toolkit/andlabs/process.go deleted file mode 100644 index d70877e..0000000 --- a/toolkit/andlabs/process.go +++ /dev/null @@ -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() {} diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go index ac35183..c71732d 100644 --- a/toolkit/andlabs/structs.go +++ b/toolkit/andlabs/structs.go @@ -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 } diff --git a/toolkit/nocui/common.go b/toolkit/nocui/common.go index e68308d..a012138 100644 --- a/toolkit/nocui/common.go +++ b/toolkit/nocui/common.go @@ -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) diff --git a/toolkit/nocui/structs.go b/toolkit/nocui/structs.go index ed004de..c3ece3b 100644 --- a/toolkit/nocui/structs.go +++ b/toolkit/nocui/structs.go @@ -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 } diff --git a/window.go b/window.go index 2e3187e..87d965b 100644 --- a/window.go +++ b/window.go @@ -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)