1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
package gui
import (
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
"go.wit.com/widget"
)
// Why have NewWindow() when there isn't just Window()
// That's how smalltalk did things in 1972. Keep it Simple.
// todo: remove 'New' from every function name
// will that work? Are there problems with that?
// Button() Grid() Box(), Label()
// 2024/01/04 Naw, having NewWindow is more readable
/*
func (parent *Node) Window(title string) *Node {
return parent.NewWindow(title)
}
*/
// This routine creates a blank window with a Title
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, widget.Window)
newNode.Custom = StandardExit
log.Log(INFO, "NewWindow()", title)
newNode.progname = title
newNode.label = title
newNode.margin = true
newNode.visable = true
newNode.hidden = false
// inform the toolkits
sendAction(newNode, widget.Add)
return newNode
}
// This creates a window off the root of the binary tree
func NewWindow(title string) *Node {
return me.rootNode.NewWindow(title)
}
func RawWindow(title string) *Node {
return me.rootNode.RawWindow(title)
}
// allow window create without actually sending it to the toolkit
func (parent *Node) RawWindow(title string) *Node {
var newNode *Node
// Windows are created off of the master node of the Binary Tree
newNode = parent.newNode(title, widget.Window)
newNode.hidden = true
newNode.visable = false
log.Log(INFO, "RawWindow()", title)
return newNode
}
// TODO: send protobuf
func (n *Node) Draw() *Node {
if !n.Ready() {
return n
}
n.hidden = false
n.changed = true
// inform the toolkits
sendAction(n, widget.Add)
return n
}
func (n *Node) TestDrawPB(pb bool) {
n.visable = true
n.hidden = false
n.changed = true
if !pb {
log.Log(NOW, "TestDrawPB() using TestDraw()")
n.TestDraw()
return
}
widgets := guipb.NewWidgets()
n.makePB(widgets.Tree)
a := getNewAction(me.rootNode, widget.Show)
a.WidgetPB, err = widgets.Marshal()
if err != nil {
log.Log(WARN, "unmarshal error", err)
return
}
log.Log(NOW, "TestDrawPB() start")
sendActionToPlugin(a)
log.Log(NOW, "TestDrawPB() end")
return
}
// TODO: remove this after switching to protobuf
// when a window is redrawn, every widget in the window
// needs to be sent to the toolkit
func (n *Node) TestDraw() {
if n == nil {
return
}
n.changed = true
n.visable = true
log.Log(INFO, "TestDraw() sending widget.Add", n.id, n.WidgetType, n.progname)
sendAction(n, widget.Add)
for _, child := range n.children {
child.TestDraw()
}
return
}
func (n *Node) makePB(parent *guipb.Widget) *guipb.Widget {
w := new(guipb.Widget)
w.Id = int64(n.id)
w.Name = n.label
parent.Children = append(parent.Children, w)
for _, child := range n.children {
w.Children = append(w.Children, child.makePB(w))
}
return w
}
func (n *Node) TestPB() {
if n == nil {
return
}
a := getNewAction(me.rootNode, widget.Show)
log.Info("gui.UpdateTable() TODO: move the widget update val logic here instead of tree")
a.WidgetPB, err = me.widgets.Marshal()
if err != nil {
log.Info("unmarshal error", err)
return
}
sendActionToPlugin(a)
return
}
|