summaryrefslogtreecommitdiff
path: root/structs.go
blob: b84317d5587874c691aaaa8387a29ece1b18db3a (plain)
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
package gui

import (
	"sync"
	"embed"
	"go.wit.com/gui/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 'tabs' 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 {
	initOnce sync.Once

	// This is the master node. The Binary Tree starts here
	rootNode *Node

	// A node off of rootNode for passing debugging flags
	flag	*Node

	counter    int  // used to make unique WidgetId's

	// sets the chan for the plugins to call back too
	guiChan chan widget.Action

	// option to pass in compiled plugins as embedded files
	resFS	embed.FS

	// used to beautify logging to Stdout
	depth      int
	prefix     string
}

// 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
type Node struct {
	id	int // should be unique
	hidden	bool // Sierpinski Carpet mode. It's there, but you can't see it.
	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

	WidgetType	widget.WidgetType

	// for NewLabel("hello"), Text = 'hello'
	Text string  // what is visable to the user

	// for NewLabel("hello"), if Name = 'HELLO'
	// this can programatically identify the widget
	// The name must be unique
	Name string  // a name useful for debugging

	// 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

	// the current widget value.
	I	int
	S	string
	B	bool
	value	any

	// this function is run when there are mouse or keyboard events
	Custom func()

	parent	*Node
	children []*Node
}