diff options
| author | Jeff Carr <[email protected]> | 2022-10-11 11:59:42 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2022-10-11 11:59:42 -0500 |
| commit | 3c899365154e48aefbc0b5ee48cd089f49339cb2 (patch) | |
| tree | 13f3c0aa281d17c55306ed2e0323aa5188087e04 /structs.go | |
| parent | 2294e22484be61a934ca8b523f4aeb40d20d6196 (diff) | |
| parent | 770fa06a18652b30db0cd4ee64e8e89d06d7de2e (diff) | |
Merge branch 'master' into develv0.3.1
Diffstat (limited to 'structs.go')
| -rw-r--r-- | structs.go | 266 |
1 files changed, 176 insertions, 90 deletions
@@ -1,37 +1,53 @@ package gui -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) + Title string + Width int + Height int + Exit func(*Node) + + Debug bool + DebugNode bool + DebugTabs bool + DebugTable bool + DebugWindow bool + + depth int + counter int // used to make unique ID's + prefix string } 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 + // Store access to everything via binary tree's + NodeMap map[string]*Node + NodeArray []*Node + NodeSlice []*Node // A map of all buttons everywhere on all // windows, all tabs, across all goroutines @@ -39,8 +55,14 @@ type GuiData struct { // // This has to work this way because of how // andlabs/ui & andlabs/libui work - AllButtons []*GuiButton - buttonMap map[*ui.Button]*GuiButton + AllButtons []*GuiButton + buttonMap map[*ui.Button]*GuiButton +} + +type GuiTab struct { + Name string // field for human readable name + Number int // the andlabs/ui tab index + Window *GuiWindow // the parent Window } // @@ -62,34 +84,97 @@ type GuiData 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 + + node *Node // 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' +} + +func (w *GuiWindow) Dump() { + log.Println("gui.GuiWindow.Dump() Name = ", w.Name) + log.Println("gui.GuiWindow.Dump() node = ", w.node) + log.Println("gui.GuiWindow.Dump() Width = ", w.Width) + log.Println("gui.GuiWindow.Dump() Height = ", w.Height) } // 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 + + node *Node // andlabs/ui abstraction mapping - UiBox *ui.Box + UiBox *ui.Box +} + +func (b *GuiBox) Dump() { + log.Println("gui.GuiBox.Dump() Name = ", b.Name) + log.Println("gui.GuiBox.Dump() Axis = ", b.Axis) + log.Println("gui.GuiBox.Dump() GuiWindow = ", b.Window) + log.Println("gui.GuiBox.Dump() node = ", b.node) + log.Println("gui.GuiBox.Dump() UiBox = ", b.UiBox) +} + +func (b *GuiBox) SetTitle(title string) { + log.Println("DID IT!", title) + if b.Window == nil { + return + } + if b.Window.UiWindow == nil { + return + } + b.Window.UiWindow.SetTitle(title) + return +} + +func (w *GuiWindow) SetNode(n *Node) { + if (w.node != nil) { + w.Dump() + panic("gui.SetNode() Error not nil") + } + w.node = n + if (w.node == nil) { + w.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) SetNode(n *Node) { + if (b.node != nil) { + b.Dump() + panic("gui.SetNode() Error not nil") + } + b.node = n + if (b.node == nil) { + b.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) Append(child ui.Control, x bool) { + if b.UiBox == nil { + panic("GuiBox.Append() can't work. UiBox == nil") + return + } + b.UiBox.Append(child, x) } // Note: every mouse click is handled @@ -97,32 +182,32 @@ type GuiBox struct { // 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 } // @@ -130,20 +215,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 @@ -161,18 +247,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 } // @@ -191,44 +277,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 } // |
