2019-05-24 13:32:47 -05:00
|
|
|
package gui
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
import (
|
2022-11-14 14:30:28 -06:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2023-03-29 23:03:04 -05:00
|
|
|
"sync"
|
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
|
|
|
|
// 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.
|
2022-10-20 06:55:42 -05:00
|
|
|
//
|
|
|
|
|
2021-10-06 13:23:00 -05:00
|
|
|
var Config GuiConfig
|
2019-06-02 17:49:52 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
// This struct can be used with the go-arg package
|
|
|
|
type GuiArgs struct {
|
|
|
|
Toolkit []string `arg:"--toolkit" help:"The order to attempt loading plugins [gocui,andlabs,gtk,qt]"`
|
|
|
|
GuiDebug bool `arg:"--gui-debug" help:"debug the GUI"`
|
2023-03-01 11:35:36 -06:00
|
|
|
GuiVerbose bool `arg:"--gui-verbose" help:"enable all GUI flags"`
|
2022-11-05 10:19:04 -05:00
|
|
|
}
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
// var verbose GuiArgs.GuiDebug
|
|
|
|
|
2019-06-02 17:49:52 -05:00
|
|
|
type GuiConfig struct {
|
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
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
// These are shortcuts to pass default values to make a new window
|
2021-10-31 14:21:36 -05:00
|
|
|
Title string
|
2021-10-06 13:23:00 -05:00
|
|
|
Width int
|
|
|
|
Height int
|
2021-10-31 14:21:36 -05:00
|
|
|
Exit func(*Node)
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
// hacks
|
2021-10-31 14:21:36 -05:00
|
|
|
depth int
|
|
|
|
counter int // used to make unique ID's
|
|
|
|
prefix string
|
2023-03-01 11:35:36 -06:00
|
|
|
|
|
|
|
ActionCh1 chan int
|
|
|
|
ActionCh2 chan int
|
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 {
|
2022-11-06 12:59:24 -06:00
|
|
|
id int
|
2023-03-29 23:03:04 -05:00
|
|
|
initOnce sync.Once
|
2022-10-11 11:25:46 -05:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
widget toolkit.Widget
|
2023-03-29 23:03:04 -05:00
|
|
|
WidgetType toolkit.WidgetType
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
// Title string // what is visable to the user
|
|
|
|
// Desc string // a name useful for programming
|
|
|
|
|
|
|
|
Text string // what is visable to the user
|
|
|
|
Name string // a name useful for programming
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
// used for Windows
|
2022-10-20 06:55:42 -05:00
|
|
|
Width int
|
|
|
|
Height int
|
2022-10-11 11:25:46 -05:00
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
// used for anything that needs a range
|
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
|
|
|
|
// used for grids and tables
|
|
|
|
NextX int
|
|
|
|
NextY int
|
|
|
|
|
|
|
|
// used for values
|
|
|
|
I int
|
|
|
|
S string
|
|
|
|
B bool
|
|
|
|
|
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
|
|
|
}
|