doesn't crash

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-02 11:02:14 -07:00
parent f00e40d649
commit b57b12549e
5 changed files with 197 additions and 138 deletions

174
box.go Normal file
View File

@ -0,0 +1,174 @@
package gui
import "log"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
// import pb "git.wit.com/wit/witProtobuf"
// import "github.com/davecgh/go-spew/spew"
// THIS IS CLEAN
// add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX'
// add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box
// add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX'
// add(box, newbox, name) // add 'newbox' to 'box' and call it 'name'
func add(box *GuiBox, newbox *GuiBox) {
log.Println("gui.add() START box =", box)
log.Println("gui.add() START newbox =", newbox)
if (box == nil) {
log.Println("\tgui.add() add to Window as MAINBOX")
newbox.Window.BoxMap["MAINBOX"] = newbox
if (newbox.Window.UiTab != nil) {
log.Println("\tgui.add() add to Window as a UiTab")
newbox.Window.UiTab.InsertAt(newbox.Name, 0, newbox.UiBox)
newbox.Window.UiTab.SetMargined(0, true)
// create a new tab here
// add the box to it as MAINBOX
} else {
log.Println("\tgui.add() DONT KNOW HOW TO ADD TO A RAW WINDOW YET")
// add this to the window
}
log.Println("\tgui.add() add to Window as MAINBOX DONE")
log.Println("gui.add() END")
return
}
log.Println("gui.add() adding", newbox.Name, "to", box.Name)
// copy the box settings over
newbox.Window = box.Window
box.UiBox.Append(newbox.UiBox, false)
// add the newbox to the Window.BoxMap[]
box.Window.BoxMap[newbox.Name] = newbox
log.Println("gui.add() END")
}
func HardHorizontalBox(gw *GuiWindow) *GuiBox {
log.Println("HardHorizontalBreak START")
var newbox *GuiBox
newbox = new(GuiBox)
newbox.Window = gw
box := gw.BoxMap["MAINBOX"]
if (box != nil) {
// There is already a box. Add a Seperator
tmp := ui.NewHorizontalSeparator()
box.UiBox.Append(tmp, true)
add(gw.BoxMap["MAINBOX"], newbox)
}
hbox := ui.NewVerticalBox()
hbox.SetPadded(true)
newbox.UiBox = hbox
newbox.Name = "Hbox1"
add(gw.BoxMap["MAINBOX"], newbox)
log.Println("HardHorizontalBreak END")
return newbox
}
func HardVerticalBreak(box *GuiBox) {
log.Println("HardVerticalBreak START")
gw := box.Window
mainbox := gw.BoxMap["MAIN"]
if (mainbox == nil) {
log.Println("HardHorizontalBreak ERROR MAIN box == nil")
return
}
tmp := ui.NewVerticalSeparator()
mainbox.UiBox.Append(tmp, false)
hbox := ui.NewVerticalBox()
hbox.SetPadded(true)
box.UiBox = hbox
mainbox.UiBox.Append(hbox, false)
log.Println("HardVerticalBreak END")
}
func HorizontalBreak(box *GuiBox) {
tmp := ui.NewHorizontalSeparator()
box.UiBox.Append(tmp, false)
}
func VerticalBreak(box *GuiBox) {
tmp := ui.NewVerticalSeparator()
box.UiBox.Append(tmp, false)
}
func AddGenericBox(gw *GuiWindow, name string) *GuiBox {
log.Println("AddGenericBox() START name =", name)
// create a new vertical box off of the mainbox
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
var newbox *GuiBox
newbox = new(GuiBox)
newbox.UiBox = vbox
newbox.Window = gw
newbox.Name = name
add(gw.BoxMap["MAINBOX"], newbox)
// create a new horizonal box off of the vertical box
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
var newhbox *GuiBox
newhbox = new(GuiBox)
newhbox.UiBox = hbox
newhbox.Window = gw
newhbox.Name = "Hbox1"
add(newbox, newhbox)
return newbox
}
func CreateGenericBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{
log.Println("CreateAddVmBox() START name =", name)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
box.UiBox = vbox
box.Window = gw
gw.BoxMap["ADD VM" + name] = box
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
AddBoxToTab(name, gw.UiTab, vbox)
return box
}
func CreateBox(gw *GuiWindow, name string) *GuiBox {
log.Println("CreateVmBox() START")
log.Println("CreateVmBox() vm.Name =", name)
log.Println("CreateVmBox() gw =", gw)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
log.Println("CreateVmBox() vbox =", vbox)
log.Println("CreateVmBox() box.UiBox =", box.UiBox)
box.UiBox = vbox
log.Println("CreateVmBox() box.Window =", box.Window)
box.Window = gw
log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap)
gw.BoxMap[name] = box
hboxAccount := ui.NewHorizontalBox()
hboxAccount.SetPadded(true)
vbox.Append(hboxAccount, false)
box.UiBox = hboxAccount
AddBoxToTab(name, gw.UiTab, vbox)
return box
}

View File

@ -137,7 +137,7 @@ func WatchGUI() {
if (count > 20) {
log.Println("Sleep() in watchGUI() Data.State =", Data.State)
for i, window := range Data.Windows {
log.Println("watchGUI() Data.Windows i =", i, "Action =", window.Action)
log.Println("watchGUI() Data.Windows", i, "Action =", window.Action)
for name, abox := range window.BoxMap {
log.Println("\twatchGUI() BOX name =", name)
if (name == "SplashArea3") {

127
gui.go
View File

@ -208,6 +208,10 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton {
return &newGB
}
func NewLabel(box *GuiBox, text string) {
box.UiBox.Append(ui.NewLabel(text), false)
}
func GetText(box *GuiBox, name string) string {
if (box == nil) {
log.Println("gui.GetText() ERROR box == nil")
@ -278,10 +282,6 @@ func MakeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action s
return e
}
func NewLabel(box *GuiBox, text string) {
box.UiBox.Append(ui.NewLabel(text), false)
}
func AddEntry(box *GuiBox, name string) *GuiEntry {
var ge *GuiEntry
ge = new(GuiEntry)
@ -298,122 +298,3 @@ func AddEntry(box *GuiBox, name string) *GuiEntry {
return ge
}
func HardHorizontalBreak(box *GuiBox) {
log.Println("HardHorizontalBreak START")
gw := box.Window
mainbox := gw.BoxMap["MAIN"]
if (mainbox == nil) {
log.Println("HardHorizontalBreak ERROR MAIN box == nil")
return
}
uibox := mainbox.UiBox
tmp := ui.NewHorizontalSeparator()
uibox.Append(tmp, false)
hbox := ui.NewVerticalBox()
hbox.SetPadded(true)
box.UiBox = hbox
uibox.Append(hbox, true)
log.Println("HardHorizontalBreak END")
}
func HardVerticalBreak(box *GuiBox) {
log.Println("HardVerticalBreak START")
gw := box.Window
mainbox := gw.BoxMap["MAIN"]
if (mainbox == nil) {
log.Println("HardHorizontalBreak ERROR MAIN box == nil")
return
}
tmp := ui.NewVerticalSeparator()
mainbox.UiBox.Append(tmp, false)
hbox := ui.NewVerticalBox()
hbox.SetPadded(true)
box.UiBox = hbox
mainbox.UiBox.Append(hbox, false)
log.Println("HardVerticalBreak END")
}
func HorizontalBreak(box *GuiBox) {
tmp := ui.NewHorizontalSeparator()
box.UiBox.Append(tmp, false)
}
func VerticalBreak(box *GuiBox) {
tmp := ui.NewVerticalSeparator()
box.UiBox.Append(tmp, false)
}
func AddGenericBox(gw *GuiWindow) *GuiBox {
var gb *GuiBox
gb = new(GuiBox)
// gb.EntryMap = make(map[string]*GuiEntry)
// gb.EntryMap["test"] = nil
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
// gw.Box1 = vbox
gb.UiBox = vbox
gb.Window = gw
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
return gb
}
func CreateGenericBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{
log.Println("CreateAddVmBox() START name =", name)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
box.UiBox = vbox
box.Window = gw
gw.BoxMap["ADD VM" + name] = box
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
AddBoxToTab(name, gw.UiTab, vbox)
return box
}
func CreateBox(gw *GuiWindow, name string) *GuiBox {
log.Println("CreateVmBox() START")
log.Println("CreateVmBox() vm.Name =", name)
log.Println("CreateVmBox() gw =", gw)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
log.Println("CreateVmBox() vbox =", vbox)
log.Println("CreateVmBox() box.UiBox =", box.UiBox)
box.UiBox = vbox
log.Println("CreateVmBox() box.Window =", box.Window)
box.Window = gw
log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap)
gw.BoxMap[name] = box
hboxAccount := ui.NewHorizontalBox()
hboxAccount.SetPadded(true)
vbox.Append(hboxAccount, false)
box.UiBox = hboxAccount
AddBoxToTab(name, gw.UiTab, vbox)
return box
}

11
misc.go
View File

@ -24,9 +24,14 @@ func ShowTab(gw *GuiWindow, tabname string, title string) *GuiWindow {
window.UiTab.Delete(0)
abox := window.MakeWindow(window)
window.BoxMap[tabname] = abox
window.UiTab.InsertAt(title, 0, abox.UiBox)
window.UiTab.SetMargined(0, true)
// add(nil, abox)
log.Println("ShowTab() NOT INSERTING TAB abox =", abox)
log.Println("ShowTab() NOT INSERTING TAB")
log.Println("ShowTab() NOT INSERTING TAB")
log.Println("ShowTab() NOT INSERTING TAB")
// window.BoxMap[tabname] = abox
// window.UiTab.InsertAt(title, 0, abox.UiBox)
// window.UiTab.SetMargined(0, true)
return window
}

View File

@ -95,6 +95,15 @@ type GuiWindow struct {
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 {
Window *GuiWindow
Name string
// andlabs/ui abstraction mapping
UiBox *ui.Box
}
// Note: every mouse click is handled
// as a 'Button' regardless of where
@ -103,7 +112,6 @@ type GuiWindow struct {
type GuiButton struct {
Action string // what type of button
Box *GuiBox // what box the button click was in
// Area *GuiArea // indicates the button click was in an Area
GW *GuiWindow // what window the button click was in (redundant?)
Account *pb.Account // associated with what account?
@ -117,16 +125,7 @@ type GuiButton struct {
FB *ui.FontButton
}
// GuiBox is any type of ui.Hbox or ui.Vbox
// There can be lots of these for each GuiWindow
type GuiBox struct {
Window *GuiWindow
// EntryMap map[string]*GuiEntry
// andlabs/ui abstraction mapping
UiBox *ui.Box
}
// text entry fields
type GuiEntry struct {
Action string // what type of button
Edit bool