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,11 +1,14 @@
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
@ -102,10 +105,10 @@ type GuiBox struct {
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
}
@ -204,8 +223,8 @@ type GuiButton struct {
Box *GuiBox // what box the button click was in
// a callback function for the main application
Custom func (*GuiButton)
Values interface {}
Custom func(*GuiButton)
Values interface{}
Color color.RGBA
// andlabs/ui abstraction mapping
@ -219,7 +238,7 @@ 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
Normalize func(string) string // function to 'normalize' the data
B *GuiButton
Box *GuiBox
@ -233,7 +252,7 @@ type GuiEntry struct {
// AREA STRUCTURES START
// AREA STRUCTURES START
//
type GuiArea struct{
type GuiArea struct {
Button *GuiButton // what button handles mouse events
Box *GuiBox
@ -247,6 +266,7 @@ type FontString struct {
F font.Face
W font.Weight
}
//
// AREA STRUCTURES END
// AREA STRUCTURES END
@ -325,12 +345,12 @@ type CellData struct {
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
}

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
}