simplify sendAction()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-05-09 18:50:16 -05:00
parent 75954affce
commit d9f9b3c688
7 changed files with 43 additions and 48 deletions

13
box.go
View File

@ -4,16 +4,11 @@ import (
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
func (n *Node) NewBox(name string, b bool) *Node { func (parent *Node) NewBox(name string, b bool) *Node {
newNode := n.newNode(name, toolkit.Box, nil) newNode := parent.newNode(name, toolkit.Box, nil)
newNode.B = b newNode.B = b
var a toolkit.Action a := newAction(newNode, toolkit.Add)
a.ActionType = toolkit.Add sendAction(a, newNode, parent)
a.Name = name
a.Text = name
a.B = b
newaction(&a, newNode, n)
return newNode return newNode
} }

View File

@ -7,16 +7,13 @@ import (
// TODO: make a "Group" a "Grid" ? // TODO: make a "Group" a "Grid" ?
// probably since right now group is just a // probably since right now group is just a
// pre-canned andlabs/ui gtk,macos,windows thing // 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 var newNode *Node
newNode = n.newNode(name, toolkit.Group, nil) newNode = parent.newNode(name, toolkit.Group, nil)
var a toolkit.Action a := newAction(newNode, toolkit.Add)
a.ActionType = toolkit.Add sendAction(a, newNode, parent)
a.Name = name
a.Text = name
newaction(&a, newNode, n)
newBox := newNode.NewBox("group vBox", false) newBox := newNode.NewBox("defaultGroupBox", false)
return newBox return newBox
} }

View File

@ -4,13 +4,11 @@ import (
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
func (n *Node) NewImage(name string) *Node { func (parent *Node) NewImage(name string) *Node {
var newNode *Node var newNode *Node
newNode = n.newNode(name, toolkit.Image, nil) newNode = parent.newNode(name, toolkit.Image, nil)
var a toolkit.Action
a.ActionType = toolkit.Add
newaction(&a, newNode, n)
a := newAction(newNode, toolkit.Add)
sendAction(a, newNode, parent)
return newNode return newNode
} }

View File

@ -212,16 +212,31 @@ func newAction(n *Node, atype toolkit.ActionType) *toolkit.Action {
a.Name = n.Name a.Name = n.Name
a.Text = n.Text a.Text = n.Text
a.WidgetId = n.id a.WidgetId = n.id
a.B = n.B
a.X = n.X
a.Y = n.Y
if (n.parent != nil) { if (n.parent != nil) {
a.ParentId = n.parent.id a.ParentId = n.parent.id
} }
a.WidgetType = n.WidgetType a.WidgetType = n.WidgetType
return &a return &a
} }
// func sendAction(a *toolkit.Action) {
func sendAction(a *toolkit.Action, n *Node, where *Node) { 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 // 2023/04/06 Queue() is also being used and channels are being used. memcopy() only

10
tab.go
View File

@ -30,12 +30,12 @@ func (n *Node) NewTab(text string) *Node {
} }
newNode := n.newNode(text, toolkit.Tab, nil) newNode := n.newNode(text, toolkit.Tab, nil)
var a toolkit.Action a := newAction(newNode, toolkit.Add)
a.ActionType = toolkit.Add sendAction(a, newNode, n)
a.Name = text
a.Text = text
newaction(&a, newNode, n)
// by default, create a box inside the tab
// TODO: allow this to be configurable
newBox := newNode.NewBox(text, true) newBox := newNode.NewBox(text, true)
return newBox return newBox
} }

View File

@ -4,16 +4,12 @@ import (
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
func (n *Node) NewTextbox(name string) *Node { func (parent *Node) NewTextbox(name string) *Node {
newNode := n.newNode(name, toolkit.Textbox, func() { newNode := parent.newNode(name, toolkit.Textbox, func() {
log(debugGui, "NewTextbox changed =", name) log(debugGui, "NewTextbox changed =", name)
}) })
var a toolkit.Action a := newAction(newNode, toolkit.Add)
a.ActionType = toolkit.Add sendAction(a, newNode, parent)
a.Name = name
a.Text = name
newaction(&a, newNode, n)
return newNode return newNode
} }

View File

@ -6,21 +6,15 @@ import (
// This routine creates a blank window with a Title and size (W x H) // 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 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(title, toolkit.Window, StandardExit) newNode = parent.newNode(title, toolkit.Window, StandardExit)
log(logInfo, "NewWindow()", title) log(logInfo, "NewWindow()", title)
var a toolkit.Action a := newAction(newNode, toolkit.Add)
a.ActionType = toolkit.Add sendAction(a, newNode, parent)
a.X = n.X
a.Y = n.Y
a.Name = title
a.Text = title
newaction(&a, newNode, n)
return newNode return newNode
} }