summaryrefslogtreecommitdiff
path: root/structs.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2021-10-06 13:23:00 -0500
committerJeff Carr <[email protected]>2021-10-06 13:23:00 -0500
commit7c6fae3efea5e96ae8aad2a3171f42ab4e69b3b1 (patch)
treea696673cd1f4325283f96670e044c9f108ca16e7 /structs.go
parent18119fe04019d72f62c71c129a4eb2cb3f08ff7c (diff)
TAB: correctly lookup and add tabs to blank windows
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'structs.go')
-rw-r--r--structs.go226
1 files changed, 123 insertions, 103 deletions
diff --git a/structs.go b/structs.go
index 6387b45..71921bd 100644
--- a/structs.go
+++ b/structs.go
@@ -1,36 +1,39 @@
package gui
-import "log"
-import "image/color"
-import "golang.org/x/image/font"
+import (
+ "image/color"
+ "log"
-import "github.com/andlabs/ui"
-import _ "github.com/andlabs/ui/winmanifest"
+ "github.com/andlabs/ui"
+ "golang.org/x/image/font"
+
+ _ "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
//
-var Data GuiData
-var Config GuiConfig
+var Data GuiData
+var Config GuiConfig
type GuiConfig struct {
- Width int
- Height int
- Debug bool
- DebugTable bool
- Exit func(*GuiWindow)
+ Width int
+ Height int
+ Debug bool
+ DebugTable bool
+ Exit func(*GuiWindow)
}
type GuiData struct {
- // a fallback default function to handle mouse events
+ // a fallback default function to handle mouse events
// if nothing else is defined to handle them
- MouseClick func(*GuiButton)
+ MouseClick func(*GuiButton)
// A map of all the entry boxes
- AllEntries []*GuiEntry
- WindowMap map[string]*GuiWindow
+ AllEntries []*GuiEntry
+ WindowMap map[string]*GuiWindow
// Windows []*GuiWindow
@@ -40,15 +43,15 @@ type GuiData struct {
//
// This has to work this way because of how
// andlabs/ui & andlabs/libui work
- AllButtons []*GuiButton
- buttonMap map[*ui.Button]*GuiButton
- Nodes *Node
+ AllButtons []*GuiButton
+ buttonMap map[*ui.Button]*GuiButton
+ Nodes *Node
}
type GuiTab struct {
- Name string // field for human readable name
- Number int // the andlabs/ui tab index
- Window *GuiWindow // the parent Window
+ Name string // field for human readable name
+ Number int // the andlabs/ui tab index
+ Window *GuiWindow // the parent Window
}
//
@@ -70,42 +73,42 @@ type GuiTab struct {
// can destroy and replace it with something else
//
type GuiWindow struct {
- Name string // field for human readable name
- Width int
- Height int
- Axis int // does it add items to the X or Y axis
- TabNumber *int // the andlabs/ui tab index
+ Name string // field for human readable name
+ Width int
+ Height int
+ Axis int // does it add items to the X or Y axis
+ TabNumber *int // the andlabs/ui tab index
// the callback function to make the window contents
// MakeWindow func(*GuiBox) *GuiBox
// the components of the window
- BoxMap map[string]*GuiBox
- EntryMap map[string]*GuiEntry
- Area *GuiArea
+ BoxMap map[string]*GuiBox
+ EntryMap map[string]*GuiEntry
+ Area *GuiArea
// andlabs/ui abstraction mapping
- UiWindow *ui.Window
- UiTab *ui.Tab // if this != nil, the window is 'tabbed'
+ UiWindow *ui.Window
+ UiTab *ui.Tab // if this != nil, the window is 'tabbed'
}
// GuiBox is any type of ui.Hbox or ui.Vbox
// There can be lots of these for each GuiWindow
type GuiBox struct {
- Name string // field for human readable name
- Axis int // does it add items to the X or Y axis
- Window *GuiWindow // the parent Window
+ Name string // field for human readable name
+ Axis int // does it add items to the X or Y axis
+ Window *GuiWindow // the parent Window
// andlabs/ui abstraction mapping
- UiBox *ui.Box
+ UiBox *ui.Box
}
func (s GuiBox) SetTitle(title string) {
log.Println("DID IT!", title)
- if (s.Window == nil) {
+ if s.Window == nil {
return
}
- if (s.Window.UiWindow == nil) {
+ if s.Window.UiWindow == nil {
return
}
s.Window.UiWindow.SetTitle(title)
@@ -113,17 +116,33 @@ func (s GuiBox) SetTitle(title string) {
}
func (s GuiBox) Append(child ui.Control, x bool) {
- if (s.UiBox == nil) {
+ if s.UiBox == nil {
return
}
s.UiBox.Append(child, x)
}
+func (w GuiWindow) InitBox(title string) *GuiBox {
+ if w.UiWindow == nil {
+ log.Println("gui.InitBox() THIS SHOULD NEVER HAPPEN. Window doesn't exist", w)
+ return nil
+ }
+ tab := ui.NewTab()
+ w.UiWindow.SetChild(tab)
+ w.UiWindow.SetMargined(true)
+
+ tab.Append(title, initBlankWindow())
+ tab.SetMargined(0, true)
+
+ w.UiTab = tab
+ return nil
+}
+
func (s GuiBox) InitTab(title string) *ui.Tab {
- if (s.Window == nil) {
+ if s.Window == nil {
return nil
}
- if (s.Window.UiWindow == nil) {
+ if s.Window.UiWindow == nil {
return nil
}
@@ -141,10 +160,10 @@ func (s GuiBox) InitTab(title string) *ui.Tab {
}
func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab {
- if (s.Window == nil) {
+ if s.Window == nil {
return nil
}
- if (s.Window.UiTab == nil) {
+ if s.Window.UiTab == nil {
return nil
}
@@ -155,10 +174,10 @@ func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab {
}
func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab {
- if (s.Window == nil) {
+ if s.Window == nil {
return nil
}
- if (s.Window.UiTab == nil) {
+ if s.Window.UiTab == nil {
return nil
}
@@ -200,32 +219,32 @@ func tabSetMargined(tab *ui.Tab) {
// the user clicks it. You could probably
// call this 'GuiMouseClick'
type GuiButton struct {
- Name string // field for human readable name
- Box *GuiBox // what box the button click was in
+ Name string // field for human readable name
+ Box *GuiBox // what box the button click was in
// a callback function for the main application
- Custom func (*GuiButton)
- Values interface {}
- Color color.RGBA
+ Custom func(*GuiButton)
+ Values interface{}
+ Color color.RGBA
// andlabs/ui abstraction mapping
- B *ui.Button
- FB *ui.FontButton
- CB *ui.ColorButton
+ B *ui.Button
+ FB *ui.FontButton
+ CB *ui.ColorButton
}
// text entry fields
type GuiEntry struct {
- Name string // field for human readable name
- Edit bool
- Last string // the last value
- Normalize func (string) string // function to 'normalize' the data
+ Name string // field for human readable name
+ Edit bool
+ Last string // the last value
+ Normalize func(string) string // function to 'normalize' the data
- B *GuiButton
- Box *GuiBox
+ B *GuiButton
+ Box *GuiBox
// andlabs/ui abstraction mapping
- UiEntry *ui.Entry
+ UiEntry *ui.Entry
}
//
@@ -233,20 +252,21 @@ type GuiEntry struct {
// AREA STRUCTURES START
// AREA STRUCTURES START
//
-type GuiArea struct{
- Button *GuiButton // what button handles mouse events
- Box *GuiBox
+type GuiArea struct {
+ Button *GuiButton // what button handles mouse events
+ Box *GuiBox
- UiAttrstr *ui.AttributedString
- UiArea *ui.Area
+ UiAttrstr *ui.AttributedString
+ UiArea *ui.Area
}
type FontString struct {
- S string
- Size int
- F font.Face
- W font.Weight
+ S string
+ Size int
+ F font.Face
+ W font.Weight
}
+
//
// AREA STRUCTURES END
// AREA STRUCTURES END
@@ -264,18 +284,18 @@ type FontString struct {
// 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
+ 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
- Cells [20]CellData
- Human [20]HumanMap
+ Cells [20]CellData
+ Human [20]HumanMap
- Box *GuiBox
+ Box *GuiBox
- lastRow int
- lastColumn int
+ lastRow int
+ lastColumn int
}
//
@@ -294,44 +314,44 @@ type TableData struct {
// TODO: re-add images and the progress bar (works in andlabs/ui)
//
type HumanCellData struct {
- Name string // what kind of row is this?
- Text string
- TextID int
- Color color.RGBA
- ColorID int
- Button *GuiButton
+ Name string // what kind of row is this?
+ Text string
+ TextID int
+ Color color.RGBA
+ ColorID int
+ Button *GuiButton
}
type HumanMap struct {
- Name string // what kind of row is this?
- TextID int
- ColorID int
+ Name string // what kind of row is this?
+ TextID int
+ ColorID int
}
type TableColumnData struct {
- Index int
- CellType string
- Heading string
- Color string
+ Index int
+ CellType string
+ Heading string
+ Color string
}
type CellData struct {
- Index int
- HumanID int
- Name string // what type of cell is this?
+ Index int
+ HumanID int
+ Name string // what type of cell is this?
}
// 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
- // depending on if it's possible to detect the bgcolor or what row is selected
- 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
+ Name string // what kind of row is this?
+ Status string // status of the row?
+ /*
+ // TODO: These may or may not be implementable
+ // depending on if it's possible to detect the bgcolor or what row is selected
+ 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
}
//