compiles. kinda works

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-05 09:05:09 -06:00
parent 6291ddc13d
commit 8f937c19ee
3 changed files with 42 additions and 16 deletions

View File

@ -20,6 +20,10 @@ func (n *Node) String() string {
return widget.GetString(n.State.Value) return widget.GetString(n.State.Value)
} }
func (n *Node) ProgName() string {
return n.State.ProgName
}
func (n *Node) Hidden() bool { func (n *Node) Hidden() bool {
return n.State.Hidden return n.State.Hidden
} }

34
init.go
View File

@ -10,18 +10,40 @@ import (
var muAction sync.Mutex var muAction sync.Mutex
/* func (me *TreeInfo) newAction(a widget.Action) {
func (me *TreeInfo) newAction(a widget.Action) *tree.Node { n := me.treeRoot.FindWidgetId(a.WidgetId)
switch a.ActionType { switch a.ActionType {
case widget.Add: case widget.Add:
n := me.treeRoot.FindWidgetId(a.WidgetId)
if n == nil { if n == nil {
n := me.AddNode(&a) n := me.AddNode(&a)
me.ActionFromChannel(n, a.ActionType) me.Add(n)
return
} }
case widget.SetText:
switch n.WidgetType {
case widget.Dropdown:
me.SetText(n, widget.GetString(a.State.Value))
case widget.Combobox:
me.SetText(n, widget.GetString(a.State.Value))
case widget.Window:
me.SetTitle(n, a.State.Label)
default:
// buttons, checkboxes, groups, etc
me.SetLabel(n, a.State.Label)
}
case widget.AddText:
switch n.WidgetType {
case widget.Dropdown:
me.AddText(n, widget.GetString(a.State.Value))
case widget.Combobox:
me.AddText(n, widget.GetString(a.State.Value))
default:
log.Warn("AddText() not supported on widget", n.WidgetType, n.String())
}
default:
me.NodeAction(n, a.ActionType)
} }
} }
*/
func (me *TreeInfo) catchActionChannel() { func (me *TreeInfo) catchActionChannel() {
defer func() { defer func() {
@ -42,8 +64,8 @@ func (me *TreeInfo) catchActionChannel() {
log.Error(errors.New("toolkit ActionFromChannel == nil"), a.WidgetId, a.ActionType, a.WidgetType) log.Error(errors.New("toolkit ActionFromChannel == nil"), a.WidgetId, a.ActionType, a.WidgetType)
} else { } else {
// send this to the toolkit // send this to the toolkit
me.newAction(a)
me.ActionFromChannel(a) me.ActionFromChannel(a)
// me.newAction(a)
} }
muAction.Unlock() muAction.Unlock()
} }

View File

@ -1,24 +1,18 @@
package tree package tree
/* /*
These code should be common to all gui plugins
There are some helper functions that are probably going to be There are some helper functions that are probably going to be
the same everywhere. Mostly due to handling the binary tree structure the same everywhere. Mostly due to handling the binary tree structure
and the channel communication and the channel communication
For now, it's just a symlink to the 'master' version in
./toolkit/nocui/common.go
*/ */
import ( import (
// "go.wit.com/log"
"go.wit.com/widget" "go.wit.com/widget"
) )
// var me *TreeInfo
type TreeInfo struct { type TreeInfo struct {
PluginName string
// this is the channel we send user events like // this is the channel we send user events like
// mouse clicks or keyboard events back to the program // mouse clicks or keyboard events back to the program
callback chan widget.Action callback chan widget.Action
@ -27,9 +21,15 @@ type TreeInfo struct {
pluginChan chan widget.Action pluginChan chan widget.Action
treeRoot *Node treeRoot *Node
NodeI interface{} // NodeI interface{}
ActionFromChannel func(widget.Action) ActionFromChannel func(widget.Action)
PluginName string NodeAction func(*Node, widget.ActionType)
Add func(*Node)
AddText func(*Node, string)
SetText func(*Node, string)
SetTitle func(*Node, string)
SetLabel func(*Node, string)
} }
type Node struct { type Node struct {