From d9f9b3c688418557f27a34358a465187a7a56f89 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 9 May 2023 18:50:16 -0500 Subject: [PATCH] simplify sendAction() Signed-off-by: Jeff Carr --- box.go | 13 ++++--------- group.go | 13 +++++-------- image.go | 10 ++++------ plugin.go | 19 +++++++++++++++++-- tab.go | 10 +++++----- textbox.go | 12 ++++-------- window.go | 14 ++++---------- 7 files changed, 43 insertions(+), 48 deletions(-) diff --git a/box.go b/box.go index 4b067af..9148d83 100644 --- a/box.go +++ b/box.go @@ -4,16 +4,11 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func (n *Node) NewBox(name string, b bool) *Node { - newNode := n.newNode(name, toolkit.Box, nil) +func (parent *Node) NewBox(name string, b bool) *Node { + newNode := parent.newNode(name, toolkit.Box, nil) newNode.B = b - var a toolkit.Action - a.ActionType = toolkit.Add - a.Name = name - a.Text = name - a.B = b - newaction(&a, newNode, n) - + a := newAction(newNode, toolkit.Add) + sendAction(a, newNode, parent) return newNode } diff --git a/group.go b/group.go index a695ef3..aadc883 100644 --- a/group.go +++ b/group.go @@ -7,16 +7,13 @@ import ( // TODO: make a "Group" a "Grid" ? // probably since right now group is just a // pre-canned andlabs/ui gtk,macos,windows thing -func (n *Node) NewGroup(name string) *Node { +func (parent *Node) NewGroup(name string) *Node { var newNode *Node - newNode = n.newNode(name, toolkit.Group, nil) + newNode = parent.newNode(name, toolkit.Group, nil) - var a toolkit.Action - a.ActionType = toolkit.Add - a.Name = name - a.Text = name - newaction(&a, newNode, n) + a := newAction(newNode, toolkit.Add) + sendAction(a, newNode, parent) - newBox := newNode.NewBox("group vBox", false) + newBox := newNode.NewBox("defaultGroupBox", false) return newBox } diff --git a/image.go b/image.go index c764eff..4531f23 100644 --- a/image.go +++ b/image.go @@ -4,13 +4,11 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func (n *Node) NewImage(name string) *Node { +func (parent *Node) NewImage(name string) *Node { var newNode *Node - newNode = n.newNode(name, toolkit.Image, nil) - - var a toolkit.Action - a.ActionType = toolkit.Add - newaction(&a, newNode, n) + newNode = parent.newNode(name, toolkit.Image, nil) + a := newAction(newNode, toolkit.Add) + sendAction(a, newNode, parent) return newNode } diff --git a/plugin.go b/plugin.go index eba3256..1b9b290 100644 --- a/plugin.go +++ b/plugin.go @@ -212,16 +212,31 @@ func newAction(n *Node, atype toolkit.ActionType) *toolkit.Action { a.Name = n.Name a.Text = n.Text a.WidgetId = n.id + a.B = n.B + a.X = n.X + a.Y = n.Y if (n.parent != nil) { a.ParentId = n.parent.id } a.WidgetType = n.WidgetType - return &a } +// func sendAction(a *toolkit.Action) { func sendAction(a *toolkit.Action, n *Node, where *Node) { - newaction(a, n, where) + // newaction(a, n, where) + for _, aplug := range allPlugins { + log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.ActionType) + if (aplug.pluginChan == nil) { + log(logInfo, "Action() retrieving the aplug.PluginChannel()", aplug.name) + aplug.pluginChan = aplug.PluginChannel() + log(logInfo, "Action() retrieved", aplug.pluginChan) + } + log(logInfo, "Action() SEND to pluginChan", aplug.name) + aplug.pluginChan <- *a + // added during debugging. might be a good idea in general for a tactile experience + sleep(.02) + } } // 2023/04/06 Queue() is also being used and channels are being used. memcopy() only diff --git a/tab.go b/tab.go index 59f6496..10c2e08 100644 --- a/tab.go +++ b/tab.go @@ -30,12 +30,12 @@ func (n *Node) NewTab(text string) *Node { } newNode := n.newNode(text, toolkit.Tab, nil) - var a toolkit.Action - a.ActionType = toolkit.Add - a.Name = text - a.Text = text - newaction(&a, newNode, n) + a := newAction(newNode, toolkit.Add) + sendAction(a, newNode, n) + // by default, create a box inside the tab + // TODO: allow this to be configurable newBox := newNode.NewBox(text, true) + return newBox } diff --git a/textbox.go b/textbox.go index 63b14b0..61c9a5d 100644 --- a/textbox.go +++ b/textbox.go @@ -4,16 +4,12 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func (n *Node) NewTextbox(name string) *Node { - newNode := n.newNode(name, toolkit.Textbox, func() { +func (parent *Node) NewTextbox(name string) *Node { + newNode := parent.newNode(name, toolkit.Textbox, func() { log(debugGui, "NewTextbox changed =", name) }) - var a toolkit.Action - a.ActionType = toolkit.Add - a.Name = name - a.Text = name - newaction(&a, newNode, n) - + a := newAction(newNode, toolkit.Add) + sendAction(a, newNode, parent) return newNode } diff --git a/window.go b/window.go index db254d4..09265d1 100644 --- a/window.go +++ b/window.go @@ -6,21 +6,15 @@ import ( // This routine creates a blank window with a Title and size (W x H) -func (n *Node) NewWindow(title string) *Node { +func (parent *Node) NewWindow(title string) *Node { var newNode *Node // Windows are created off of the master node of the Binary Tree - newNode = n.newNode(title, toolkit.Window, StandardExit) + newNode = parent.newNode(title, toolkit.Window, StandardExit) log(logInfo, "NewWindow()", title) - var a toolkit.Action - a.ActionType = toolkit.Add - a.X = n.X - a.Y = n.Y - a.Name = title - a.Text = title - newaction(&a, newNode, n) - + a := newAction(newNode, toolkit.Add) + sendAction(a, newNode, parent) return newNode }