2019-05-24 13:32:47 -05:00
|
|
|
package gui
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
import (
|
2023-03-29 23:03:04 -05:00
|
|
|
"sync"
|
2023-04-28 07:29:46 -05:00
|
|
|
"embed"
|
2024-01-05 13:18:44 -06:00
|
|
|
"go.wit.com/gui/widget"
|
2021-10-06 13:23:00 -05:00
|
|
|
)
|
2019-05-24 13:32:47 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// All GUI Data Structures and functions that are external
|
2022-10-20 06:55:42 -05:00
|
|
|
// within the toolkit/ abstraction layer
|
|
|
|
//
|
2023-02-25 14:05:25 -06:00
|
|
|
// 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
|
2019-05-24 13:32:47 -05:00
|
|
|
//
|
2023-02-25 14:05:25 -06:00
|
|
|
// If that is the case, this code abstracts the concept of
|
2024-01-11 19:32:40 -06:00
|
|
|
// windows and makes each window a 'tab' in a single window.
|
2023-02-25 14:05:25 -06:00
|
|
|
//
|
|
|
|
// Reminder from Goals: This is for simple GUI's.
|
|
|
|
// For example, a "Mouse Control Panel" not the GIMP or blender.
|
2022-10-20 06:55:42 -05:00
|
|
|
//
|
|
|
|
|
2023-04-28 10:35:57 -05:00
|
|
|
var me guiConfig
|
2019-06-02 17:49:52 -05:00
|
|
|
|
2024-01-11 19:32:40 -06:00
|
|
|
// Range(1, 10) includes the values 1 and 10
|
|
|
|
// almost all toolkits use integers so there doesn't
|
|
|
|
// seem to be a good idea to use 'type any' here as it
|
|
|
|
// just makes things more complicated for no good reason
|
|
|
|
type Range struct {
|
|
|
|
Low int
|
|
|
|
High int
|
|
|
|
}
|
|
|
|
|
|
|
|
type List []string
|
|
|
|
|
2023-04-28 10:30:27 -05:00
|
|
|
type guiConfig struct {
|
2023-05-09 17:48:21 -05:00
|
|
|
initOnce sync.Once
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
// This is the master node. The Binary Tree starts here
|
2023-03-29 23:03:04 -05:00
|
|
|
rootNode *Node
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
// A node off of rootNode for passing debugging flags
|
2023-03-03 14:41:38 -06:00
|
|
|
flag *Node
|
|
|
|
|
2023-04-28 10:30:27 -05:00
|
|
|
counter int // used to make unique WidgetId's
|
2023-04-06 18:00:18 -05:00
|
|
|
|
2023-04-07 21:22:51 -05:00
|
|
|
// sets the chan for the plugins to call back too
|
2024-01-05 13:18:44 -06:00
|
|
|
guiChan chan widget.Action
|
2023-04-28 07:29:46 -05:00
|
|
|
|
|
|
|
// option to pass in compiled plugins as embedded files
|
|
|
|
resFS embed.FS
|
2023-04-28 10:30:27 -05:00
|
|
|
|
|
|
|
// used to beautify logging to Stdout
|
|
|
|
depth int
|
|
|
|
prefix string
|
2019-06-02 17:49:52 -05:00
|
|
|
}
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
// 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
|
2022-10-20 06:55:42 -05:00
|
|
|
type Node struct {
|
2024-01-06 13:53:15 -06:00
|
|
|
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
|
2022-10-11 11:25:46 -05:00
|
|
|
|
2024-01-05 13:18:44 -06:00
|
|
|
WidgetType widget.WidgetType
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2024-01-11 19:32:40 -06:00
|
|
|
// the current widget value.
|
|
|
|
value any
|
2023-12-29 03:00:03 -06:00
|
|
|
|
|
|
|
// this can programatically identify the widget
|
|
|
|
// The name must be unique
|
2024-01-11 19:32:40 -06:00
|
|
|
progname string // a name useful for debugging
|
2023-03-23 12:35:12 -05:00
|
|
|
|
2023-04-28 10:30:27 -05:00
|
|
|
// used for Windows in toolkits measured in pixels
|
|
|
|
width int
|
|
|
|
height int
|
2022-10-11 11:25:46 -05:00
|
|
|
|
2023-05-10 14:28:30 -05:00
|
|
|
// used for anything that needs a range (for example: a slider)
|
2023-03-23 12:35:12 -05:00
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
|
2023-12-29 03:00:03 -06:00
|
|
|
// 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
|
2023-05-10 14:28:30 -05:00
|
|
|
W int
|
|
|
|
H int
|
2023-12-29 03:00:03 -06:00
|
|
|
|
2023-05-10 14:28:30 -05:00
|
|
|
// where the next widget should be put in this grid
|
2023-05-09 17:48:21 -05:00
|
|
|
NextW int
|
|
|
|
NextH int
|
2023-03-23 12:35:12 -05:00
|
|
|
|
2023-12-29 03:00:03 -06:00
|
|
|
// if this widget is in a grid, this is the position of a widget
|
2023-05-10 14:28:30 -05:00
|
|
|
AtW int
|
|
|
|
AtH int
|
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
// this function is run when there are mouse or keyboard events
|
2023-03-01 11:35:36 -06:00
|
|
|
Custom func()
|
2022-11-06 12:59:24 -06:00
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
parent *Node
|
|
|
|
children []*Node
|
2022-10-11 11:25:46 -05:00
|
|
|
}
|