2022-11-13 08:53:03 -06:00
|
|
|
package toolkit
|
2022-11-09 08:38:50 -06:00
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
type WidgetType int
|
|
|
|
type ActionType int
|
|
|
|
|
2022-11-09 08:38:50 -06:00
|
|
|
// passes information between the toolkit library (plugin)
|
2023-02-25 14:05:25 -06:00
|
|
|
//
|
2022-11-09 08:38:50 -06:00
|
|
|
// All Toolkit interactions should be done via a channel or Queue()
|
2023-03-23 12:35:12 -05:00
|
|
|
// TODO: FIGURE OUT HOW TO IMPLEMENT THIS
|
2023-03-29 23:03:04 -05:00
|
|
|
// https://ieftimov.com/post/golang-datastructures-trees/
|
|
|
|
// TODO: protobuf ?
|
2023-02-25 14:05:25 -06:00
|
|
|
//
|
2022-11-09 08:38:50 -06:00
|
|
|
// This is the only thing that is passed between the toolkit plugin
|
2023-02-25 14:05:25 -06:00
|
|
|
//
|
2022-11-09 08:38:50 -06:00
|
|
|
// what names should be used? This is not part of [[Graphical Widget]]
|
2023-03-23 12:35:12 -05:00
|
|
|
// Event() seems like a good name.
|
|
|
|
// Event is used too much: web dev, cloud, etc
|
|
|
|
// I'm using "Action". Maybe it should really be
|
|
|
|
// "Interaction" as per wikipedia [[User interface]]
|
2022-11-09 08:38:50 -06:00
|
|
|
// Could a protobuf be used here? (Can functions be passed?)
|
|
|
|
type Widget struct {
|
2023-03-12 08:47:16 -05:00
|
|
|
Name string
|
2023-03-01 11:35:36 -06:00
|
|
|
Type WidgetType
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// This function is how you interact with the toolkit
|
|
|
|
// latest attempt. seems to work so far (2023/02/28)
|
|
|
|
// Hopefully this will be the barrier between the goroutines
|
|
|
|
// TODO: move this interaction to channels
|
|
|
|
Custom func()
|
2023-03-23 12:35:12 -05:00
|
|
|
Callback func()
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
// re-adding an id to test channels
|
2023-03-29 23:03:04 -05:00
|
|
|
Id int
|
2023-03-12 08:47:16 -05:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
// This is how the values are passed back and forth
|
|
|
|
// values from things like checkboxes & dropdown's
|
|
|
|
// The string is also used to set the button name
|
|
|
|
B bool
|
|
|
|
I int
|
2023-03-12 08:47:16 -05:00
|
|
|
// maybe safe if there is correctly working Custom() between goroutines?
|
|
|
|
// (still probably not, almost certainly not. not possible. layer violation?)
|
2023-03-01 11:35:36 -06:00
|
|
|
S string // not safe to have 'S'
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
type Action struct {
|
2023-03-29 23:03:04 -05:00
|
|
|
ActionType ActionType
|
|
|
|
WidgetType WidgetType
|
|
|
|
|
|
|
|
WidgetId int
|
|
|
|
ParentId int
|
|
|
|
|
|
|
|
Text string // what is visable to the user
|
|
|
|
Name string // a name useful for programming
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
// this should be the widget
|
|
|
|
// if the action is New, Hide, Enable, etc
|
|
|
|
Widget *Widget
|
2023-03-29 23:03:04 -05:00
|
|
|
Callback func(int)
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
// This is how the values are passed back and forth
|
|
|
|
// values from things like checkboxes & dropdown's
|
|
|
|
// The string is also used to set the button name
|
|
|
|
B bool
|
|
|
|
I int
|
|
|
|
// maybe safe if there is correctly working Custom() between goroutines?
|
|
|
|
// (still probably not, almost certainly not. not possible. layer violation?)
|
|
|
|
S string // not safe to have 'S'
|
|
|
|
|
|
|
|
// This GUI is intended for simple things
|
|
|
|
// We are not laying out PDF's here
|
|
|
|
// This is used for things like a slider(0,100)
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
|
|
|
|
// Put space around elements to improve look & feel
|
|
|
|
Margin bool
|
|
|
|
|
|
|
|
// Make widgets fill up the space available
|
|
|
|
Expand bool
|
|
|
|
}
|
|
|
|
|
2022-11-09 08:38:50 -06:00
|
|
|
const (
|
2023-03-01 11:35:36 -06:00
|
|
|
Unknown WidgetType = iota
|
2023-03-29 23:03:04 -05:00
|
|
|
Root // the master 'root' node of the binary tree
|
|
|
|
Flag // used to send configuration values to plugins
|
|
|
|
Window // in certain gui's (ncurses), these are tabs
|
|
|
|
Tab // internally, this is a window
|
|
|
|
Frame // deprecate?
|
|
|
|
Grid // like drawers in a chest
|
|
|
|
Group // like the 'Appetizers' section on a menu
|
|
|
|
Box // a vertical or horizontal stack of widgets
|
2023-03-01 11:35:36 -06:00
|
|
|
Button
|
2023-03-29 23:03:04 -05:00
|
|
|
Checkbox // select 'on' or 'off'
|
2023-03-01 11:35:36 -06:00
|
|
|
Dropdown
|
2023-03-29 23:03:04 -05:00
|
|
|
Combobox // dropdown with edit=true
|
2022-11-09 08:38:50 -06:00
|
|
|
Label
|
2023-03-29 23:03:04 -05:00
|
|
|
Textbox // is this a Label with edit=true
|
|
|
|
Slider // like a progress bar
|
|
|
|
Spinner // like setting the oven temperature
|
|
|
|
Image // TODO
|
|
|
|
Area // TODO
|
|
|
|
Form // TODO
|
|
|
|
Font // TODO
|
|
|
|
Color // TODO
|
|
|
|
Dialog // TODO
|
2023-03-23 12:35:12 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
Add ActionType = iota
|
|
|
|
Delete
|
|
|
|
Get
|
|
|
|
Set
|
|
|
|
GetText
|
|
|
|
SetText
|
|
|
|
AddText
|
|
|
|
Show
|
|
|
|
Hide
|
|
|
|
Enable
|
|
|
|
Disable
|
|
|
|
Margin
|
|
|
|
Unmargin
|
|
|
|
Pad
|
|
|
|
Unpad
|
|
|
|
Append
|
|
|
|
Move
|
|
|
|
Dump
|
2022-11-09 08:38:50 -06:00
|
|
|
)
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func (s WidgetType) String() string {
|
2022-11-09 08:38:50 -06:00
|
|
|
switch s {
|
2023-03-29 23:03:04 -05:00
|
|
|
case Root:
|
|
|
|
return "Root"
|
|
|
|
case Flag:
|
|
|
|
return "Flag"
|
2022-11-09 08:38:50 -06:00
|
|
|
case Window:
|
|
|
|
return "Window"
|
|
|
|
case Tab:
|
|
|
|
return "Tab"
|
|
|
|
case Frame:
|
|
|
|
return "Frame"
|
2023-03-23 12:35:12 -05:00
|
|
|
case Grid:
|
|
|
|
return "Grid"
|
|
|
|
case Group:
|
|
|
|
return "Group"
|
|
|
|
case Box:
|
|
|
|
return "Box"
|
2023-03-01 11:35:36 -06:00
|
|
|
case Button:
|
|
|
|
return "Button"
|
|
|
|
case Checkbox:
|
|
|
|
return "Checkbox"
|
|
|
|
case Dropdown:
|
|
|
|
return "Dropdown"
|
2023-03-03 14:41:38 -06:00
|
|
|
case Combobox:
|
|
|
|
return "Combobox"
|
2022-11-09 08:38:50 -06:00
|
|
|
case Label:
|
|
|
|
return "Label"
|
2023-03-01 11:35:36 -06:00
|
|
|
case Textbox:
|
|
|
|
return "Textbox"
|
|
|
|
case Slider:
|
|
|
|
return "Slider"
|
|
|
|
case Spinner:
|
|
|
|
return "Spinner"
|
2023-03-12 08:47:16 -05:00
|
|
|
case Image:
|
|
|
|
return "Image"
|
2023-03-23 12:35:12 -05:00
|
|
|
case Area:
|
|
|
|
return "Area"
|
|
|
|
case Form:
|
|
|
|
return "Form"
|
|
|
|
case Font:
|
|
|
|
return "Font"
|
|
|
|
case Color:
|
|
|
|
return "Color"
|
|
|
|
case Dialog:
|
|
|
|
return "Dialog"
|
2023-03-01 11:35:36 -06:00
|
|
|
case Unknown:
|
|
|
|
return "Unknown"
|
2022-11-09 08:38:50 -06:00
|
|
|
}
|
2023-03-29 23:03:04 -05:00
|
|
|
return "WidgetType.String() Error"
|
2023-03-23 12:35:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s ActionType) String() string {
|
|
|
|
switch s {
|
|
|
|
case Add:
|
|
|
|
return "Add"
|
|
|
|
case Delete:
|
|
|
|
return "Delete"
|
|
|
|
case Get:
|
|
|
|
return "Get"
|
|
|
|
case Set:
|
|
|
|
return "Set"
|
|
|
|
case GetText:
|
|
|
|
return "GetText"
|
|
|
|
case SetText:
|
|
|
|
return "SetText"
|
|
|
|
case AddText:
|
|
|
|
return "AddText"
|
|
|
|
case Show:
|
|
|
|
return "Show"
|
|
|
|
case Hide:
|
|
|
|
return "Hide"
|
|
|
|
case Enable:
|
|
|
|
return "Enable"
|
|
|
|
case Disable:
|
|
|
|
return "Disable"
|
|
|
|
case Margin:
|
|
|
|
return "Margin"
|
|
|
|
case Unmargin:
|
|
|
|
return "Unmargin"
|
|
|
|
case Pad:
|
|
|
|
return "Pad"
|
|
|
|
case Unpad:
|
|
|
|
return "Unpad"
|
|
|
|
case Append:
|
|
|
|
return "Append"
|
|
|
|
case Move:
|
|
|
|
return "Move"
|
|
|
|
case Dump:
|
|
|
|
return "Dump"
|
|
|
|
}
|
2023-03-29 23:03:04 -05:00
|
|
|
return "ActionType.String() Error"
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|