2019-05-24 13:32:47 -05:00
|
|
|
package gui
|
|
|
|
|
2021-10-04 21:33:03 -05:00
|
|
|
import "log"
|
2019-05-24 13:32:47 -05:00
|
|
|
import "image/color"
|
2019-05-29 17:46:21 -05:00
|
|
|
import "golang.org/x/image/font"
|
2019-05-24 13:32:47 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
//
|
|
|
|
// All GUI Data Structures and functions that are external
|
|
|
|
// If you need cross platform support, these might only
|
|
|
|
// be the safe way to interact with the GUI
|
|
|
|
//
|
2019-05-30 00:24:41 -05:00
|
|
|
var Data GuiData
|
2019-06-02 17:49:52 -05:00
|
|
|
var Config GuiConfig
|
|
|
|
|
|
|
|
type GuiConfig struct {
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
Debug bool
|
|
|
|
DebugTable bool
|
2019-06-17 10:09:28 -05:00
|
|
|
Exit func(*GuiWindow)
|
2019-06-02 17:49:52 -05:00
|
|
|
}
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2019-05-30 00:24:41 -05:00
|
|
|
type GuiData struct {
|
2019-05-24 13:32:47 -05:00
|
|
|
// a fallback default function to handle mouse events
|
|
|
|
// if nothing else is defined to handle them
|
2019-05-30 10:55:54 -05:00
|
|
|
MouseClick func(*GuiButton)
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2019-05-31 08:58:23 -05:00
|
|
|
// A map of all the entry boxes
|
|
|
|
AllEntries []*GuiEntry
|
2019-06-03 17:45:40 -05:00
|
|
|
WindowMap map[string]*GuiWindow
|
2019-05-31 08:58:23 -05:00
|
|
|
|
2019-06-14 17:41:30 -05:00
|
|
|
// Windows []*GuiWindow
|
|
|
|
|
2019-05-24 13:32:47 -05:00
|
|
|
// A map of all buttons everywhere on all
|
|
|
|
// windows, all tabs, across all goroutines
|
|
|
|
// This is "GLOBAL"
|
2019-06-01 14:43:40 -05:00
|
|
|
//
|
|
|
|
// This has to work this way because of how
|
|
|
|
// andlabs/ui & andlabs/libui work
|
2019-05-30 13:56:34 -05:00
|
|
|
AllButtons []*GuiButton
|
2019-06-03 00:22:04 -05:00
|
|
|
buttonMap map[*ui.Button]*GuiButton
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|
|
|
|
|
2019-06-01 14:43:40 -05:00
|
|
|
//
|
|
|
|
// stores information on the 'window'
|
|
|
|
//
|
|
|
|
// This merges the concept of andlabs/ui *Window and *Tab
|
|
|
|
//
|
2019-05-31 11:01:46 -05:00
|
|
|
// More than one Window is not supported in a cross platform
|
|
|
|
// sense & may never be. On Windows and MacOS, you have to have
|
|
|
|
// 'tabs'. Even under Linux, more than one Window is currently
|
|
|
|
// unstable
|
|
|
|
//
|
2019-06-01 14:43:40 -05:00
|
|
|
// This code will make a 'GuiWindow' regardless of if it is
|
|
|
|
// a stand alone window (which is more or less working on Linux)
|
|
|
|
// or a 'tab' inside a window (which is all that works on MacOS
|
|
|
|
// and MSWindows.
|
2019-05-31 11:01:46 -05:00
|
|
|
//
|
|
|
|
// This struct keeps track of what is in the window so you
|
|
|
|
// can destroy and replace it with something else
|
|
|
|
//
|
|
|
|
type GuiWindow struct {
|
2019-06-02 23:56:43 -05:00
|
|
|
Name string // field for human readable name
|
2019-05-31 19:37:53 -05:00
|
|
|
Width int
|
|
|
|
Height int
|
2019-06-04 02:56:58 -05:00
|
|
|
Axis int // does it add items to the X or Y axis
|
2019-06-13 14:08:47 -05:00
|
|
|
TabNumber *int // the andlabs/ui tab index
|
2019-05-31 11:01:46 -05:00
|
|
|
|
2019-06-01 13:45:15 -05:00
|
|
|
// the callback function to make the window contents
|
2019-06-13 16:17:05 -05:00
|
|
|
// MakeWindow func(*GuiBox) *GuiBox
|
2019-06-01 13:45:15 -05:00
|
|
|
|
|
|
|
// the components of the window
|
|
|
|
BoxMap map[string]*GuiBox
|
|
|
|
EntryMap map[string]*GuiEntry
|
|
|
|
Area *GuiArea
|
|
|
|
|
2019-06-01 00:28:02 -05:00
|
|
|
// andlabs/ui abstraction mapping
|
2019-05-31 19:37:53 -05:00
|
|
|
UiWindow *ui.Window
|
2019-05-31 15:15:38 -05:00
|
|
|
UiTab *ui.Tab // if this != nil, the window is 'tabbed'
|
2019-05-31 11:01:46 -05:00
|
|
|
}
|
|
|
|
|
2019-06-02 13:02:14 -05:00
|
|
|
// GuiBox is any type of ui.Hbox or ui.Vbox
|
|
|
|
// There can be lots of these for each GuiWindow
|
|
|
|
type GuiBox struct {
|
2019-06-02 23:56:43 -05:00
|
|
|
Name string // field for human readable name
|
2019-06-03 02:50:05 -05:00
|
|
|
Axis int // does it add items to the X or Y axis
|
|
|
|
Window *GuiWindow // the parent Window
|
2019-06-02 13:02:14 -05:00
|
|
|
|
|
|
|
// andlabs/ui abstraction mapping
|
|
|
|
UiBox *ui.Box
|
|
|
|
}
|
2019-05-31 11:01:46 -05:00
|
|
|
|
2021-10-04 21:33:03 -05:00
|
|
|
func (s GuiBox) SetTitle(title string) {
|
|
|
|
log.Println("DID IT!", title)
|
|
|
|
if (s.Window == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (s.Window.UiWindow == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.Window.UiWindow.SetTitle(title)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s GuiBox) InitTab(title string) {
|
|
|
|
if (s.Window == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (s.Window.UiWindow == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
window := s.Window.UiWindow
|
|
|
|
tab := ui.NewTab()
|
|
|
|
window.SetChild(tab)
|
|
|
|
window.SetMargined(true)
|
|
|
|
|
|
|
|
tab.Append(title, InitBlankWindow())
|
|
|
|
tab.SetMargined(0, true)
|
|
|
|
|
|
|
|
s.Window.UiTab = tab
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s GuiBox) AddTab(title string) {
|
|
|
|
if (s.Window == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (s.Window.UiTab == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
tab := s.Window.UiTab
|
|
|
|
|
|
|
|
tab.Append(title, InitBlankWindow())
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:58:05 -05:00
|
|
|
// Note: every mouse click is handled
|
|
|
|
// as a 'Button' regardless of where
|
|
|
|
// the user clicks it. You could probably
|
|
|
|
// call this 'GuiMouseClick'
|
|
|
|
type GuiButton struct {
|
2019-06-02 17:19:53 -05:00
|
|
|
Name string // field for human readable name
|
2019-05-31 08:58:23 -05:00
|
|
|
Box *GuiBox // what box the button click was in
|
2019-05-30 11:58:05 -05:00
|
|
|
|
|
|
|
// a callback function for the main application
|
2019-06-02 17:19:53 -05:00
|
|
|
Custom func (*GuiButton)
|
2019-06-02 21:49:17 -05:00
|
|
|
Values interface {}
|
2019-06-05 12:01:36 -05:00
|
|
|
Color color.RGBA
|
2019-06-02 21:49:17 -05:00
|
|
|
|
2019-05-31 08:58:23 -05:00
|
|
|
// andlabs/ui abstraction mapping
|
|
|
|
B *ui.Button
|
|
|
|
FB *ui.FontButton
|
2019-06-05 12:01:36 -05:00
|
|
|
CB *ui.ColorButton
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|
|
|
|
|
2019-06-02 13:02:14 -05:00
|
|
|
// text entry fields
|
2019-05-30 10:52:28 -05:00
|
|
|
type GuiEntry struct {
|
2019-06-02 23:56:43 -05:00
|
|
|
Name string // field for human readable name
|
2019-05-27 18:27:43 -05:00
|
|
|
Edit bool
|
2019-06-02 23:56:43 -05:00
|
|
|
Last string // the last value
|
2019-05-27 19:23:19 -05:00
|
|
|
Normalize func (string) string // function to 'normalize' the data
|
2019-05-27 18:27:43 -05:00
|
|
|
|
2019-05-31 08:58:23 -05:00
|
|
|
B *GuiButton
|
2019-06-01 00:28:02 -05:00
|
|
|
Box *GuiBox
|
2019-06-01 13:45:15 -05:00
|
|
|
|
2019-06-01 00:28:02 -05:00
|
|
|
// andlabs/ui abstraction mapping
|
|
|
|
UiEntry *ui.Entry
|
2019-05-27 18:27:43 -05:00
|
|
|
}
|
|
|
|
|
2019-05-30 11:58:05 -05:00
|
|
|
//
|
|
|
|
// AREA STRUCTURES START
|
|
|
|
// AREA STRUCTURES START
|
|
|
|
// AREA STRUCTURES START
|
|
|
|
//
|
|
|
|
type GuiArea struct{
|
2019-05-31 08:58:23 -05:00
|
|
|
Button *GuiButton // what button handles mouse events
|
2019-06-01 00:28:02 -05:00
|
|
|
Box *GuiBox
|
2019-05-30 11:58:05 -05:00
|
|
|
|
|
|
|
UiAttrstr *ui.AttributedString
|
|
|
|
UiArea *ui.Area
|
|
|
|
}
|
|
|
|
|
2019-05-29 17:46:21 -05:00
|
|
|
type FontString struct {
|
|
|
|
S string
|
|
|
|
Size int
|
|
|
|
F font.Face
|
|
|
|
W font.Weight
|
2019-05-29 13:48:32 -05:00
|
|
|
}
|
2019-05-30 11:58:05 -05:00
|
|
|
//
|
|
|
|
// AREA STRUCTURES END
|
|
|
|
// AREA STRUCTURES END
|
2019-05-26 00:07:37 -05:00
|
|
|
// AREA STRUCTURES END
|
2019-05-30 11:58:05 -05:00
|
|
|
//
|
2019-05-26 00:07:37 -05:00
|
|
|
|
2019-05-24 13:32:47 -05:00
|
|
|
//
|
|
|
|
// TABLE DATA STRUCTURES START
|
2019-05-30 11:58:05 -05:00
|
|
|
// TABLE DATA STRUCTURES START
|
|
|
|
// TABLE DATA STRUCTURES START
|
2019-05-24 13:32:47 -05:00
|
|
|
//
|
|
|
|
|
2019-05-30 11:58:05 -05:00
|
|
|
//
|
|
|
|
// This is the structure that andlabs/ui uses to pass information
|
|
|
|
// to the GUI. This is the "authoritative" data.
|
|
|
|
//
|
|
|
|
type TableData struct {
|
|
|
|
RowCount int // This is the number of 'rows' which really means data elements not what the human sees
|
|
|
|
RowWidth int // This is how wide each row is
|
|
|
|
Rows []RowData // This is all the table data by row
|
|
|
|
generatedColumnTypes []ui.TableValue // generate this dynamically
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2019-05-30 11:58:05 -05:00
|
|
|
Cells [20]CellData
|
|
|
|
Human [20]HumanMap
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2019-05-31 22:14:15 -05:00
|
|
|
Box *GuiBox
|
2019-05-30 11:58:05 -05:00
|
|
|
|
|
|
|
lastRow int
|
|
|
|
lastColumn int
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This maps the andlabs/ui & libui components into a "human"
|
|
|
|
// readable cell reference list. The reason is that there
|
|
|
|
// are potentially 3 values for each cell. The Text, the Color
|
|
|
|
// and an image. These are not always needed so the number
|
|
|
|
// of fields varies between 1 and 3. Internally, the toolkit
|
|
|
|
// GUI abstraction needs to list all of them, but it's then
|
|
|
|
// hard to figure out which column goes with the columns that
|
|
|
|
// you see when you visually are looking at it like a spreadsheet
|
|
|
|
//
|
|
|
|
// This makes a map so that we can say "give me the value at
|
|
|
|
// row 4 and column 2" and find the fields that are needed
|
|
|
|
//
|
2019-05-30 11:58:05 -05:00
|
|
|
// TODO: re-add images and the progress bar (works in andlabs/ui)
|
2019-05-24 13:32:47 -05:00
|
|
|
//
|
|
|
|
type HumanCellData struct {
|
|
|
|
Name string // what kind of row is this?
|
|
|
|
Text string
|
|
|
|
TextID int
|
|
|
|
Color color.RGBA
|
|
|
|
ColorID int
|
2019-05-30 10:55:54 -05:00
|
|
|
Button *GuiButton
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type HumanMap struct {
|
|
|
|
Name string // what kind of row is this?
|
|
|
|
TextID int
|
|
|
|
ColorID int
|
|
|
|
}
|
|
|
|
|
2019-05-30 11:58:05 -05:00
|
|
|
type TableColumnData struct {
|
|
|
|
Index int
|
|
|
|
CellType string
|
|
|
|
Heading string
|
|
|
|
Color string
|
|
|
|
}
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2019-05-30 11:58:05 -05:00
|
|
|
type CellData struct {
|
|
|
|
Index int
|
|
|
|
HumanID int
|
|
|
|
Name string // what type of cell is this?
|
|
|
|
}
|
2019-05-24 13:32:47 -05:00
|
|
|
|
2019-05-30 11:58:05 -05:00
|
|
|
// hmm. will this stand the test of time?
|
|
|
|
type RowData struct {
|
|
|
|
Name string // what kind of row is this?
|
|
|
|
Status string // status of the row?
|
|
|
|
/*
|
|
|
|
// TODO: These may or may not be implementable
|
2019-06-01 00:28:02 -05:00
|
|
|
// depending on if it's possible to detect the bgcolor or what row is selected
|
2019-05-30 11:58:05 -05:00
|
|
|
click func() // what function to call if the user clicks on it
|
|
|
|
doubleclick func() // what function to call if the user double clicks on it
|
|
|
|
*/
|
|
|
|
HumanData [20]HumanCellData
|
2019-05-24 13:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// TABLE DATA STRUCTURES END
|
|
|
|
//
|