diff options
| author | Jeff Carr <[email protected]> | 2024-01-13 22:02:12 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-13 22:02:12 -0600 |
| commit | 47b15946de10a75cda026a7317a90d4857b453c8 (patch) | |
| tree | ab6a8c085226263982d3b19f2913e540707af2a1 /action.go | |
| parent | 4ef8409eeadcd4a359b7593b5ea35f9f523bfb64 (diff) | |
work on hiding widgetsv0.12.5
When widgets are hidden, their state works exactly the same
as normal, but updates are not sent to the toolkits
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'action.go')
| -rw-r--r-- | action.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/action.go b/action.go new file mode 100644 index 0000000..516cf15 --- /dev/null +++ b/action.go @@ -0,0 +1,68 @@ +package gui + +/* + This is where the communication to the toolkit plugin happens. + + We copy the current values from the widget node of the binary tree + and send an "action" to the toolkit over a channel. + + TODO: use protobuf +*/ + +import ( + "go.wit.com/log" + "go.wit.com/gui/widget" +) + +// 2024/01/11 finally moving to type any. simplify to just 'value' +// 2023/05/09 pretty clean +// 2023/04/06 Queue() is also being used and channels are being used. +func sendAction(n *Node, atype widget.ActionType) { + if n == nil { + return + } + if n.hidden { + return + } + + var a widget.Action + a.ActionType = atype + + // These should be "stable" at this point (2024/01/13) + a.WidgetId = n.id + a.ProgName = n.progname + a.Value = n.value + a.Direction = n.direction + a.Strings = n.strings + + // These should be improved/deprecated based on the gui/widget docs + a.Expand = n.expand + + a.X = n.X + a.Y = n.Y + + a.AtW = n.AtW + a.AtH = n.AtH + + if (n.parent != nil) { + a.ParentId = n.parent.id + } + a.WidgetType = n.WidgetType + sendActionToPlugin(&a) +} + +// sends the action/event to each toolkit via a golang plugin channel +func sendActionToPlugin(a *widget.Action) { + for _, aplug := range allPlugins { + log.Log(PLUG, "Action() aplug =", aplug.name, "Action type=", a.ActionType) + if (aplug.pluginChan == nil) { + log.Info("Action() retrieving the aplug.PluginChannel()", aplug.name) + aplug.pluginChan = aplug.PluginChannel() + log.Info("Action() retrieved", aplug.pluginChan) + } + log.Info("Action() SEND to pluginChan", aplug.name, a.ActionType, a.WidgetType, a.WidgetId, a.ProgName) + aplug.pluginChan <- *a + // added during debugging. might be a good idea in general for a tactile experience + log.Sleep(.02) // this delay makes it so SetText() works on initial widget creation + } +} |
