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"
|
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"`
|
2022-11-05 10:19:04 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
master *Node
|
|
|
|
|
|
|
|
// 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
|
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
|
2022-10-11 11:25:46 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
Widget toolkit.Widget
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// deprecate these and use toolkit.Widget
|
2022-10-20 06:55:42 -05:00
|
|
|
Name string
|
|
|
|
Width int
|
|
|
|
Height int
|
2022-10-11 11:25:46 -05:00
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
// this function is run when there are mouse or keyboard events
|
|
|
|
OnChanged func(*Node)
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
parent *Node
|
|
|
|
children []*Node
|
2022-10-11 11:25:46 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
// is keeping
|
|
|
|
// deprecate these things if they don't really need to exist
|
2022-10-21 11:40:08 -05:00
|
|
|
custom func()
|
|
|
|
checked bool
|
|
|
|
text string
|
2022-10-11 11:25:46 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
func (n *Node) Parent() *Node {
|
|
|
|
return n.parent
|
2022-10-11 11:25:46 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
func (n *Node) Window() *Node {
|
|
|
|
return n.parent
|
2022-10-11 11:25:46 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
func (n *Node) Append(child *Node) {
|
|
|
|
n.children = append(n.children, child)
|
2023-02-25 14:05:25 -06:00
|
|
|
if (debugGui) {
|
|
|
|
log(debugNode, "child node:")
|
2022-10-20 06:55:42 -05:00
|
|
|
child.Dump()
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugNode, "parent node:")
|
2022-10-20 06:55:42 -05:00
|
|
|
n.Dump()
|
|
|
|
}
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|