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
|
package gui
import (
"embed"
"sync"
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/widget"
)
//
// All GUI Data Structures and functions that are external
// within the toolkit/ abstraction layer
//
// More than one Window does not exist in every GUI situtaion and
// can never be. On many toolkits you have to have 'tabs', like
// Native Windows and MacOS toolkits
//
// If that is the case, this code abstracts the concept of
// windows and makes each window a 'tab' in a single window.
//
// Reminder from Goals: This is for simple GUI's.
// For example, a "Mouse Control Panel" not the GIMP or blender.
//
var me guiConfig
type guiConfig struct {
rootNode *Node // This is the master node. The Binary Tree starts here
resFS embed.FS // option to pass in compiled plugins as embedded files
guiChan chan widget.Action // sets the chan for the plugins to call back too
tables []*guipb.Tables // a list of active protobuf tables
postMustParse func(string) string // used to get the final go-arg values after all user configuration is finished
counter int // used to make unique WidgetId's. this is a fun variable, but kinda dumb and should go
appPlugin string // deprecate. what the application would like the default GUI plugin to be
widgets *guipb.Widgets // switch to this and/or tree below
// tree *guipb.Tree // the protobuf. switch to this. deprecate rootNode
}
/*
The Node is a binary tree. This is how all GUI elements are stored
simply the name and the size of whatever GUI element exists
value : most widgets need 1 value. this is it.
For a window -- the title. For a button -- the name
hidden : this means the widget is not displayed yet. In that
case, don't waste time trying to pass information to
the toolkits. This makes things efficient and fast if
the GUI does not have to display anything
Custom() : if the user does something like click on a button,
this function will be called. (this should probably
be renamed Callback()
progname : a short name to reference the widgets in the debugger
n.NewButton("click here to send it").SetProgName("SENT")
parent, children : the binary tree
pad, margin, expand : re-think these names and clarify
*/
// TODO: MOVE MUCH OF THIS TO PROTOBUFS
type Node struct {
widget *guipb.Widget // deprecate everything below and switch to this protobuf
id int // should be unique
hidden bool // don't update the toolkits when it's hidden
changed bool // do we need to inform the toolkit something changed?
enabled bool // if false, then the the user can't click on it
tablepb *guipb.Table // set in the parent if this is a tablepb
mu sync.Mutex // this is old and probably is wrong at this point
// deprecate below here if possible
WidgetType widget.WidgetType // deprecate
// most widgets need one value, this is current alue
// value any
defaultS string
newString string
currentS string
//
label string
// this can programatically identify the widget
// The name must be unique
progname string // a name useful for debugging
// for widgets that a user select from a list of strings
strings map[string]int
// how to arrange widgets
direction widget.Orientation
// for widgets that have on/off things
checked bool
// tells the toolkits if the user should currently see it
// state updates are only sent to the toolkits for visable widgets
visable bool
// borderless windows
borderless bool
// this function is run when there are mouse or keyboard events
Custom func()
parent *Node
children []*Node
// Experiment. This might be a great idea or a terrible idea
isMirror *Node // is a mirror of some other widget
hasMirrors []*Node // has a mirror
// RETHINK EVERYTHING BELOW HERE
pad bool // the toolkit may use this. it's up to the toolkit
margin bool // the toolkit may use this. it's up to the toolkit
expand bool // the toolkit may use this. it's up to the toolkit
// used for Windows in toolkits measured in pixels
width int
height int
// used for anything that needs a range (for example: a slider)
X int
Y int
// the grid widget max width and height
// the max height can be implemented in the toolkit plugin
// to restrict the number of rows to display
W int
H int
// where the next widget should be put in this grid
NextW int
NextH int
// if this widget is in a grid, this is the position of a widget
AtW int
AtH int
}
type Widget interface {
Node() *Node
String() string
}
|