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
|
2024-01-13 22:02:12 -06:00
|
|
|
type RangeMovedToWidget struct {
|
2024-01-11 19:32:40 -06:00
|
|
|
Low int
|
|
|
|
High int
|
|
|
|
}
|
|
|
|
|
2024-01-13 22:02:12 -06:00
|
|
|
// type List []string
|
2024-01-11 19:32:40 -06:00
|
|
|
|
2023-04-28 10:30:27 -05:00
|
|
|
type guiConfig struct {
|
2024-01-13 22:02:12 -06:00
|
|
|
// a toolkit requirement. never allow more than one per program
|
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
|
2024-01-13 22:02:12 -06:00
|
|
|
// depth int
|
|
|
|
// prefix string
|
2019-06-02 17:49:52 -05:00
|
|
|
}
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2024-01-13 22:02:12 -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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
type Node struct {
|
2024-01-06 13:53:15 -06:00
|
|
|
id int // should be unique
|
2024-01-13 22:02:12 -06:00
|
|
|
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
|
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-13 22:02:12 -06:00
|
|
|
// most widgets need one value, this is current alue
|
2024-01-11 19:32:40 -06:00
|
|
|
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
|
|
|
|
2024-01-13 22:02:12 -06:00
|
|
|
// for widgets that a user select from a list of strings
|
|
|
|
strings []string
|
|
|
|
|
|
|
|
// how to arrange widgets
|
|
|
|
direction widget.Orientation
|
|
|
|
|
|
|
|
// this function is run when there are mouse or keyboard events
|
|
|
|
Custom func()
|
|
|
|
|
|
|
|
parent *Node
|
|
|
|
children []*Node
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
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
|
2022-10-11 11:25:46 -05:00
|
|
|
}
|