TAB: correctly lookup and add tabs to blank windows

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-06 13:23:00 -05:00
parent c58dee3d01
commit 908615c038
4 changed files with 178 additions and 135 deletions

View File

@ -33,8 +33,12 @@ func WatchGUI() {
}
func DumpMap() {
for name, _ := range Data.WindowMap {
for name, window := range Data.WindowMap {
log.Println("gui.DumpBoxes() MAP: ", name)
log.Println("gui.DumpBoxes() BOXES:", name)
for name, abox := range window.BoxMap {
log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name)
}
}
}

View File

@ -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 (s GuiBox) InitTab(title string) *ui.Tab {
if (s.Window == nil) {
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
}
if (s.Window.UiWindow == 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 {
return 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
}
//

View File

@ -20,7 +20,7 @@ func makeWindowDebug() ui.Control {
vbox.Append(pbar, false)
/////////////////////////////////////////////////////
vbox = addGroup(hbox, "WindowMap 2")
vbox = addGroup(hbox, "Window")
cbox := ui.NewCombobox()
for name, _ := range Data.WindowMap {
@ -39,9 +39,9 @@ func makeWindowDebug() ui.Control {
})
/////////////////////////////////////////////////////
vbox = addGroup(hbox, "Buttons")
vbox = addGroup(hbox, "Debug Window")
b1 := addButton(vbox, "dumpBox(name)")
b1 := addButton(vbox, "dumpBox(window)")
b1.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
@ -49,23 +49,12 @@ func makeWindowDebug() ui.Control {
dumpBox(names[x])
})
dump2 := addButton(vbox, "Dump Boxes")
dump2.OnClicked(func(*ui.Button) {
DumpBoxes()
})
dump1 := addButton(vbox, "Dump MAP")
dump1.OnClicked(func(*ui.Button) {
DumpMap()
})
b2 := addButton(vbox, "SetMargined()")
b2 := addButton(vbox, "SetMargined(tab)")
b2.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("findBox; names[x] =", names[x])
findBox(names[x])
gw := findBox(names[x])
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
@ -82,13 +71,12 @@ func makeWindowDebug() ui.Control {
gw.UiTab.SetMargined(*gw.TabNumber, true)
})
b3 := addButton(vbox, "Hide()")
b3 := addButton(vbox, "Hide(tab)")
b3.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("findBox; names[x] =", names[x])
findBox(names[x])
gw := findBox(names[x])
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
@ -98,13 +86,12 @@ func makeWindowDebug() ui.Control {
gw.UiTab.Hide()
})
b4 := addButton(vbox, "Show()")
b4 := addButton(vbox, "Show(tab)")
b4.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("findBox; names[x] =", names[x])
findBox(names[x])
gw := findBox(names[x])
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
@ -114,13 +101,12 @@ func makeWindowDebug() ui.Control {
gw.UiTab.Show()
})
b5 := addButton(vbox, "Delete()")
b5 := addButton(vbox, "Delete(tab)")
b5.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("findBox; names[x] =", names[x])
findBox(names[x])
gw := findBox(names[x])
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
@ -133,6 +119,19 @@ func makeWindowDebug() ui.Control {
gw.UiTab.Delete(*gw.TabNumber)
})
/////////////////////////////////////////////////////
vbox = addGroup(hbox, "Global Debug")
dump2 := addButton(vbox, "Dump Boxes")
dump2.OnClicked(func(*ui.Button) {
DumpBoxes()
})
dump1 := addButton(vbox, "Dump MAP")
dump1.OnClicked(func(*ui.Button) {
DumpMap()
})
return hbox
}
@ -156,12 +155,28 @@ func addGroup(b *ui.Box, name string) *ui.Box {
return vbox
}
func findBox(s string) *GuiWindow {
func FindWindow(s string) *GuiWindow {
for name, window := range Data.WindowMap {
if name == s {
return window
}
}
log.Printf("COULD NOT FIND WINDOW", s)
return nil
}
func FindBox(s string) *GuiBox {
for name, window := range Data.WindowMap {
if name != s {
continue
}
for name, abox := range window.BoxMap {
log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name)
return abox
}
log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name)
}
log.Println("gui.FindBox() COULD NOT FIND BOX", s)
return nil
}
@ -180,6 +195,7 @@ func dumpBox(s string) {
// log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow))
log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow)
log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab)
log.Println("gui.dumpBox() BoxMap START")
for name, abox := range window.BoxMap {
log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name)
if name == "MAINBOX" {
@ -189,6 +205,7 @@ func dumpBox(s string) {
}
}
}
log.Println("gui.dumpBox() BoxMap END")
if window.UiTab != nil {
pages := window.UiTab.NumPages()
log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages)

View File

@ -210,6 +210,8 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox {
box.Window = &newGuiWindow
box.Name = title
newGuiWindow.BoxMap["jcarrInitTest"] = &box
return &box
}