From b0da8996b3c5b3b9bfb81b6214c89894cdc348ea Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 31 May 2019 23:29:06 -0700 Subject: [PATCH 01/15] start moving vm logic into the control panel Signed-off-by: Jeff Carr --- gui.go | 6 ----- vmBox.go | 68 -------------------------------------------------------- 2 files changed, 74 deletions(-) diff --git a/gui.go b/gui.go index 84618a0..ec5688f 100644 --- a/gui.go +++ b/gui.go @@ -109,12 +109,6 @@ func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnDa return mh } -func SocketError(gw *GuiWindow) { - ui.MsgBoxError(gw.UiWindow, - "There was a socket error", - "More detailed information can be shown here.") -} - func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { ui.MsgBox(gw.UiWindow, msg1, msg2) } diff --git a/vmBox.go b/vmBox.go index ae04554..6e6b960 100644 --- a/vmBox.go +++ b/vmBox.go @@ -112,71 +112,3 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) { AddBoxToTab(name, gw.UiTab, vbox) } - -// -// THIS IS THE STANDARD VM DISPLAY TABLE -// This maps the 'human' indexed cells in the table -// to the machine's andlabs/libui values. That way -// if you want to work against column 4, then you -// can just reference 4 instead of the internal number -// which could be anything since TEXTCOLOR, TEXT, BG, etc -// fields use between 1 and 3 values internally -// -func AddVmsTab(gw *GuiWindow, name string, count int, a *pb.Account) *TableData { - var parts []TableColumnData - - human := 0 - - tmp := TableColumnData{} - tmp.CellType = "BG" - tmp.Heading = "background" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - tmp = TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "name" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - tmp = TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "hostname" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - tmp = TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "IPv6" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - tmp = TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "cpus" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - tmp = TableColumnData{} - tmp.CellType = "TEXTCOLOR" - tmp.Heading = "memory" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - tmp = TableColumnData{} - tmp.CellType = "BUTTON" - tmp.Heading = "Details" - tmp.Index = human - parts = append(parts, tmp) - human += 1 - - mh := AddTableTab(gw, name, count, parts, a) -// mh := - return mh -} From 6cde27f608cafa4ba39fcfa9ea18ecab20d4d391 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 31 May 2019 23:45:53 -0700 Subject: [PATCH 02/15] rearrange some code Signed-off-by: Jeff Carr --- gui.go | 33 +++++++++++++++++++++++++++++++++ mainCloudBox.go | 44 +++++++++++++++++++++++--------------------- vmBox.go | 20 +++++++++++--------- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/gui.go b/gui.go index ec5688f..45b61f3 100644 --- a/gui.go +++ b/gui.go @@ -10,6 +10,8 @@ import pb "git.wit.com/wit/witProtobuf" import "github.com/davecgh/go-spew/spew" +// THIS IS CLEAN (all that is left is the 'createAddVmBox') + func InitColumns(mh *TableData, parts []TableColumnData) { tmpBTindex := 0 humanID := 0 @@ -284,3 +286,34 @@ func SetText(box *GuiBox, name string, value string) error { log.Println("gui.SetText() END") return nil } + +// makeEntryBox(box, "hostname:", "blah.foo.org") { +func MakeEntryVbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry { + // Start 'Nickname' vertical box + vboxN := ui.NewVerticalBox() + vboxN.SetPadded(true) + vboxN.Append(ui.NewLabel(a), false) + + e := defaultMakeEntry(startValue, edit, action) + + vboxN.Append(e.UiEntry, false) + box.UiBox.Append(vboxN, false) + // End 'Nickname' vertical box + + return e +} + +func MakeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry { + // Start 'Nickname' vertical box + hboxN := ui.NewHorizontalBox() + hboxN.SetPadded(true) + hboxN.Append(ui.NewLabel(a), false) + + e := defaultMakeEntry(startValue, edit, action) + hboxN.Append(e.UiEntry, false) + + box.UiBox.Append(hboxN, false) + // End 'Nickname' vertical box + + return e +} diff --git a/mainCloudBox.go b/mainCloudBox.go index 6f5d971..86a04cd 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -249,20 +249,9 @@ func InitWindow(gw *GuiWindow) { gw.UiWindow.Show() } -// makeEntryBox(box, "hostname:", "blah.foo.org") { -func makeEntryVbox(hbox *ui.Box, a string, startValue string, edit bool, action string) *GuiEntry { - // Start 'Nickname' vertical box - vboxN := ui.NewVerticalBox() - vboxN.SetPadded(true) - vboxN.Append(ui.NewLabel(a), false) - - e := defaultMakeEntry(startValue, edit, action) - - vboxN.Append(e.UiEntry, false) - hbox.Append(vboxN, false) - // End 'Nickname' vertical box - - return e +func AddBoxToTab(name string, tab *ui.Tab, box *ui.Box) { + tab.Append(name, box) + tab.SetMargined(0, true) } /* @@ -341,7 +330,24 @@ func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry { return &newEntry } -func makeEntryHbox(hbox *ui.Box, a string, startValue string, edit bool, action string) *GuiEntry { +/* +// makeEntryBox(box, "hostname:", "blah.foo.org") { +func makeEntryVbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry { + // Start 'Nickname' vertical box + vboxN := ui.NewVerticalBox() + vboxN.SetPadded(true) + vboxN.Append(ui.NewLabel(a), false) + + e := defaultMakeEntry(startValue, edit, action) + + vboxN.Append(e.UiEntry, false) + box.UiBox.Append(vboxN, false) + // End 'Nickname' vertical box + + return e +} + +func makeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry { // Start 'Nickname' vertical box hboxN := ui.NewHorizontalBox() hboxN.SetPadded(true) @@ -350,13 +356,9 @@ func makeEntryHbox(hbox *ui.Box, a string, startValue string, edit bool, action e := defaultMakeEntry(startValue, edit, action) hboxN.Append(e.UiEntry, false) - hbox.Append(hboxN, false) + box.UiBox.Append(hboxN, false) // End 'Nickname' vertical box return e } - -func AddBoxToTab(name string, tab *ui.Tab, box *ui.Box) { - tab.Append(name, box) - tab.SetMargined(0, true) -} +*/ diff --git a/vmBox.go b/vmBox.go index 6e6b960..bb5bd69 100644 --- a/vmBox.go +++ b/vmBox.go @@ -36,13 +36,15 @@ func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) { hboxAccount.SetPadded(true) vbox.Append(hboxAccount, false) + box.UiBox = hboxAccount + // Add hostname entry box - makeEntryVbox(hboxAccount, "hostname:", vm.Hostname, true, "Hostname") - makeEntryVbox(hboxAccount, "IPv6:", vm.IPv6, true, "IPv6") - makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",vm.Memory), true, "Memory") - makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",vm.Cpus), true, "Cpus") - makeEntryVbox(hboxAccount, "Disk (GB):",fmt.Sprintf("%d",vm.Disk), true, "Disk") - makeEntryVbox(hboxAccount, "OS Image:", vm.BaseImage, true, "BaseImage") + MakeEntryVbox(box, "hostname:", vm.Hostname, true, "Hostname") + MakeEntryVbox(box, "IPv6:", vm.IPv6, true, "IPv6") + MakeEntryVbox(box, "RAM:", fmt.Sprintf("%d",vm.Memory), true, "Memory") + MakeEntryVbox(box, "CPU:", fmt.Sprintf("%d",vm.Cpus), true, "Cpus") + MakeEntryVbox(box, "Disk (GB):",fmt.Sprintf("%d",vm.Disk), true, "Disk") + MakeEntryVbox(box, "OS Image:", vm.BaseImage, true, "BaseImage") vbox.Append(ui.NewHorizontalSeparator(), false) @@ -86,9 +88,9 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) { vbox.Append(hbox, false) // Add hostname entry box - hostname := makeEntryHbox(vbox, "Hostname:", "testhost", true, "Hostname") - memory := makeEntryHbox(vbox, "Memory:", "512", true, "Memory") - disk := makeEntryHbox(vbox, "Disk:", "20", true, "Disk") + hostname := MakeEntryHbox(box, "Hostname:", "testhost", true, "Hostname") + memory := MakeEntryHbox(box, "Memory:", "512", true, "Memory") + disk := MakeEntryHbox(box, "Disk:", "20", true, "Disk") log.Println("createAddVmBox() hostname, memory, disk =", hostname, memory, disk) From 7d85fd05cd1cbf746d51d72223f6bfb8e0134fde Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 01:20:20 -0700 Subject: [PATCH 03/15] more control panel code removal Signed-off-by: Jeff Carr --- area.go | 29 +++++++++++++++-- gui.go | 8 +++++ mainCloudBox.go | 67 +++++++--------------------------------- splash.go | 79 ----------------------------------------------- structs.go | 4 ++- table.go | 2 ++ tableCallbacks.go | 2 ++ 7 files changed, 53 insertions(+), 138 deletions(-) delete mode 100644 splash.go diff --git a/area.go b/area.go index 1a0b9c9..3582900 100644 --- a/area.go +++ b/area.go @@ -101,7 +101,32 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { log.Println("GOT ENTER") } spew.Dump(ke) - // splashWin.Destroy() - // ui.Quit() return false } + +func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox { + log.Println("ShowTextBox() START") + if (gw == nil) { + log.Println("ShowTextBox() ERROR gw = nil") + return nil + } + log.Println("ShowTextBox() START gw =", gw) + + // create and setup a new GuiBox + var gb *GuiBox + gb = new(GuiBox) + + gb.EntryMap = make(map[string]*GuiEntry) + gb.EntryMap["test"] = nil + + newbox := ui.NewVerticalBox() + newbox.SetPadded(true) + gb.UiBox = newbox + gb.W = gw + gw.BoxMap["Splash"] = gb + + makeSplashArea(gb, newText) + newbox.Append(gb.Area.UiArea, true) + + return gb +} diff --git a/gui.go b/gui.go index 45b61f3..c78439b 100644 --- a/gui.go +++ b/gui.go @@ -209,6 +209,10 @@ func AddButton(b *GuiButton, name string) *ui.Button { return newB } +func AddButtonToBox(box *GuiBox, button *GuiButton) { + box.UiBox.Append(button.B, false) +} + func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, action string, custom func(*GuiButton)) *GuiButton { newUiB := ui.NewButton(name) newUiB.OnClicked(defaultButtonClick) @@ -317,3 +321,7 @@ 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) +} diff --git a/mainCloudBox.go b/mainCloudBox.go index 86a04cd..7971445 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -170,13 +170,13 @@ func GuiInit() { }) } -func StartNewWindow(c *pb.Config, bg bool, action string, text func() *ui.AttributedString) { +func StartNewWindow(c *pb.Config, bg bool, action string, maketab func(*GuiWindow) *GuiBox) { log.Println("InitNewWindow() Create a new window") var newGuiWindow GuiWindow newGuiWindow.Width = int(c.Width) newGuiWindow.Height = int(c.Height) newGuiWindow.Action = action - newGuiWindow.GetText = text + newGuiWindow.MakeTab = maketab Data.Windows = append(Data.Windows, &newGuiWindow) // make(newGuiWindow.BoxMap) @@ -185,13 +185,13 @@ func StartNewWindow(c *pb.Config, bg bool, action string, text func() *ui.Attrib if (bg) { log.Println("ShowWindow() IN NEW GOROUTINE") go ui.Main(func() { - InitWindow(&newGuiWindow) + InitTabWindow(&newGuiWindow) }) time.Sleep(2000 * time.Millisecond) } else { log.Println("ShowWindow() WAITING for ui.Main()") ui.Main(func() { - InitWindow(&newGuiWindow) + InitTabWindow(&newGuiWindow) }) } } @@ -202,8 +202,8 @@ func getSplashText(a string) *ui.AttributedString { return aText } -func InitWindow(gw *GuiWindow) { - log.Println("InitWindow() THIS WINDOW IS NOT YET SHOWN") +func InitTabWindow(gw *GuiWindow) { + log.Println("InitTabWindow() THIS WINDOW IS NOT YET SHOWN") gw.UiWindow = ui.NewWindow("", int(gw.Width), int(gw.Height), true) gw.UiWindow.SetBorderless(false) @@ -216,7 +216,7 @@ func InitWindow(gw *GuiWindow) { Data.AllButtons = append(Data.AllButtons, &newBM) gw.UiWindow.OnClosing(func(*ui.Window) bool { - log.Println("InitWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) + log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) // mouseClick(&newBM) ui.Quit() return true @@ -226,24 +226,12 @@ func InitWindow(gw *GuiWindow) { gw.UiWindow.SetChild(gw.UiTab) gw.UiWindow.SetMargined(true) - log.Println("InitWindow() gw =", gw) - log.Println("InitWindow() gw.Action =", gw.Action) + log.Println("InitTabWindow() gw =", gw) - if (gw.Action == "SPLASH") { - log.Println("InitWindow() TRYING SPLASH") - damnit := "click" + string(Data.Config.Hostname) - var tmp *ui.AttributedString - if (gw.GetText == nil) { - tmp = getSplashText(damnit) - } else { - tmp = gw.GetText() - } - log.Println("InitWindow() TRYING SPLASH tmp =", tmp) - abox := ShowSplashBox(gw, tmp) + abox := gw.MakeTab(gw) - gw.UiTab.Append("WIT Splash", abox.UiBox) - gw.UiTab.SetMargined(0, true) - } + gw.UiTab.Append("WIT Splash", abox.UiBox) + gw.UiTab.SetMargined(0, true) Data.State = "splash" gw.UiWindow.Show() @@ -329,36 +317,3 @@ func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry { return &newEntry } - -/* -// makeEntryBox(box, "hostname:", "blah.foo.org") { -func makeEntryVbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry { - // Start 'Nickname' vertical box - vboxN := ui.NewVerticalBox() - vboxN.SetPadded(true) - vboxN.Append(ui.NewLabel(a), false) - - e := defaultMakeEntry(startValue, edit, action) - - vboxN.Append(e.UiEntry, false) - box.UiBox.Append(vboxN, false) - // End 'Nickname' vertical box - - return e -} - -func makeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry { - // Start 'Nickname' vertical box - hboxN := ui.NewHorizontalBox() - hboxN.SetPadded(true) - hboxN.Append(ui.NewLabel(a), false) - - e := defaultMakeEntry(startValue, edit, action) - hboxN.Append(e.UiEntry, false) - - box.UiBox.Append(hboxN, false) - // End 'Nickname' vertical box - - return e -} -*/ diff --git a/splash.go b/splash.go deleted file mode 100644 index da03f3d..0000000 --- a/splash.go +++ /dev/null @@ -1,79 +0,0 @@ -package gui - -// import "github.com/davecgh/go-spew/spew" -// import "time" -// import "fmt" - -import "os" -import "log" -import "runtime" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -func ShowSplashBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox { - log.Println("ShowSplashBox() START") - log.Println("ShowSplashBox() START gw =", gw) - if (gw == nil) { - log.Println("ShowSplashBox() WE ARE FUCKED BECAUSE WE DON'T KNOW WHAT WINDOW TO DO THIS IN") - os.Exit(0) - return nil - } - var gb *GuiBox - gb = new(GuiBox) - - gb.EntryMap = make(map[string]*GuiEntry) - gb.EntryMap["test"] = nil - - newbox := ui.NewVerticalBox() - newbox.SetPadded(true) - // gw.Box1 = hbox - gb.UiBox = newbox - gb.W = gw - gw.BoxMap["Splash"] = gb - - /* - // initialize the GuiArea{} - gb.Area = new(GuiArea) - gb.Area.Window = gw - gb.Area.UiAttrstr = newText - */ - - makeSplashArea(gb, newText) - - newbox.Append(gb.Area.UiArea, true) - - if runtime.GOOS == "linux" { - newbox.Append(ui.NewLabel("OS: Linux"), false) - } else if runtime.GOOS == "windows" { - newbox.Append(ui.NewLabel("OS: Windows"), false) - } else { - newbox.Append(ui.NewLabel("OS: " + runtime.GOOS), false) - } - - version := "Version: " + Data.Version - newbox.Append(ui.NewLabel(version), false) - - if (Data.Debug) { - if (Data.GitCommit != "") { - tmp := "git rev-list: " + Data.GitCommit - newbox.Append(ui.NewLabel(tmp), false) - } - if (Data.GoVersion != "") { - tmp := "go build version: " + Data.GoVersion - newbox.Append(ui.NewLabel(tmp), false) - } - if (Data.Buildtime != "") { - tmp := "build date: " + Data.Buildtime - newbox.Append(ui.NewLabel(tmp), false) - } - } - - log.Println("ShowSplashBox() START gb =", gb) - - okButton := CreateButton(gb, nil, nil, "OK", "AREA", nil) - newbox.Append(okButton.B, false) - - // os.Exit(0) - return gb -} diff --git a/structs.go b/structs.go index 89057b9..430f136 100644 --- a/structs.go +++ b/structs.go @@ -8,6 +8,8 @@ import _ "github.com/andlabs/ui/winmanifest" import pb "git.wit.com/wit/witProtobuf" +// THIS IS CLEAN + // // All GUI Data Structures and functions that are external // If you need cross platform support, these might only @@ -78,7 +80,7 @@ type GuiWindow struct { // andlabs/ui abstraction mapping UiWindow *ui.Window UiTab *ui.Tab // if this != nil, the window is 'tabbed' - GetText func() *ui.AttributedString + MakeTab func(*GuiWindow) *GuiBox } diff --git a/table.go b/table.go index 4e65b35..c6dbcdf 100644 --- a/table.go +++ b/table.go @@ -9,6 +9,8 @@ import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" +// THIS IS CLEAN + func initRowBTcolor(mh *TableData, intBG int, cell TableColumnData) { humanInt := cell.Index diff --git a/tableCallbacks.go b/tableCallbacks.go index e63c5b3..df9c408 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -14,6 +14,8 @@ import "runtime" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +// THIS IS CLEAN + func (mh *TableData) NumRows(m *ui.TableModel) int { if (Data.Debug) { log.Println("NumRows = mh.RowCount = ", mh.RowCount, "(last Row & Column =", mh.lastRow, mh.lastColumn, ")") From 60d0fa43695b721c58bc21ddf93bed553da2acd7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 01:32:55 -0700 Subject: [PATCH 04/15] keep cleaning Signed-off-by: Jeff Carr --- addAccount.go | 9 +-------- debug.go | 2 ++ mainCloudBox.go | 2 ++ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/addAccount.go b/addAccount.go index 353951a..5843043 100644 --- a/addAccount.go +++ b/addAccount.go @@ -75,14 +75,6 @@ func generateSubdomain(b *GuiButton) { } /* -func addSubdomain(b *GuiButton) { - log.Println("addSubdomain START") - // sub := subdomain.Text() - // log.Println("generateSubdomain subdomain =", sub) - log.Println("addSubdomain END") -} -*/ - func AddAccountBox(gw *GuiWindow) *GuiBox { var gb *GuiBox gb = new(GuiBox) @@ -198,3 +190,4 @@ func AddAccountBox(gw *GuiWindow) *GuiBox { return gb } +*/ diff --git a/debug.go b/debug.go index a0b5600..8e21122 100644 --- a/debug.go +++ b/debug.go @@ -14,6 +14,8 @@ import "github.com/davecgh/go-spew/spew" // import pb "git.wit.com/wit/witProtobuf" +// THIS IS CLEAN + // can not pass any args to this (?) /* func setupCloudUI() { diff --git a/mainCloudBox.go b/mainCloudBox.go index 7971445..5982a27 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -122,6 +122,7 @@ func ShowAccountQuestionTab(gw *GuiWindow) { gw.UiTab.SetMargined(0, true) } +/* func ShowAccountTab(gw *GuiWindow, i int) { log.Println("ShowAccountTab() START") @@ -147,6 +148,7 @@ func ShowAccountTab(gw *GuiWindow, i int) { AddBoxToTab("Create New Account", gw.UiTab, abox.UiBox) } } +*/ func ShowMainTab(gw *GuiWindow) { log.Println("ShowMainTab() gw =", gw) From 0aec23e17293529128aa6b374ffdf84f1a672c46 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 02:13:18 -0700 Subject: [PATCH 05/15] finally able to remove addAccount.go Signed-off-by: Jeff Carr --- addAccount.go | 193 ------------------------------------------------ gui.go | 42 +++++++++++ mainCloudBox.go | 32 +------- 3 files changed, 44 insertions(+), 223 deletions(-) delete mode 100644 addAccount.go diff --git a/addAccount.go b/addAccount.go deleted file mode 100644 index 5843043..0000000 --- a/addAccount.go +++ /dev/null @@ -1,193 +0,0 @@ -package gui - -import "log" -// import "fmt" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -// import "github.com/davecgh/go-spew/spew" -// var subdomain *ui.Entry - -func AddEntry(box *GuiBox, name string) *GuiEntry { - var ge *GuiEntry - ge = new(GuiEntry) - - ue := ui.NewEntry() - ue.SetReadOnly(false) - ue.OnChanged(func(*ui.Entry) { - log.Println("gui.AddEntry() OK. ue.Text() =", ue.Text()) - }) - box.UiBox.Append(ue, false) - - ge.UiEntry = ue - box.EntryMap[name] = ge - - return ge -} - -func AddAccountQuestionBox(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.W = gw - - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - vbox.Append(hbox, false) - - hbox.Append(ui.NewLabel("Enter your Subdomain or"), false) - - button1 := CreateButton(gb, nil, nil, "Generate", "SUBDOMAIN", generateSubdomain) - button1.Box = gb - hbox.Append(button1.B, false) - - AddEntry(gb, "SUBDOMAIN") - // AddEntry(gb, "USERNAME") - - vbox.Append(ui.NewHorizontalSeparator(), false) - - button2 := CreateButton(gb, nil, nil, "Create Subdomain Account", "ADD", nil) - button2.Box = gb - vbox.Append(button2.B, false) - - return gb -} - -func generateSubdomain(b *GuiButton) { - log.Println("generateSubdomain START") - if (b == nil) { - log.Println("generateSubdomain ERROR b == nil") - return - } - // subdomain.SetText("cust00013.wit.dev") - - txt := SetText(b.Box, "SUBDOMAIN", "cust001.testing.com.customers.wprod.wit.com") - log.Println("generateSubdomain subdomain = ", txt) - log.Println("generateSubdomain END") -} - -/* -func AddAccountBox(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 - - hboxAccount := ui.NewHorizontalBox() - hboxAccount.SetPadded(true) - vbox.Append(hboxAccount, false) - - // Start 'Provider' vertical box - vboxC := ui.NewVerticalBox() - vboxC.SetPadded(true) - vboxC.Append(ui.NewLabel("Cloud Provider:"), false) - - cbox := ui.NewCombobox() - cbox.Append("WIT") - cbox.Append("Evocative") - vboxC.Append(cbox, false) - cbox.SetSelected(0) - - cbox.OnSelected(func(*ui.Combobox) { - log.Println("OK. Selected Cloud Provider =", cbox.Selected()) - }) - hboxAccount.Append(vboxC, false) - // End 'Cloud Provider' vertical box - - // Start 'Region' vertical box - vboxR := ui.NewVerticalBox() - vboxR.SetPadded(true) - vboxR.Append(ui.NewLabel("Region:"), false) - - regbox := ui.NewCombobox() - regbox.Append("Any") - regbox.Append("SF") - vboxR.Append(regbox, false) - regbox.SetSelected(0) - - regbox.OnSelected(func(*ui.Combobox) { - log.Println("OK. Selected something =", regbox.Selected()) - }) - hboxAccount.Append(vboxR, false) - // End 'Region' vertical box - - // Start 'Nickname' vertical box - vboxN := ui.NewVerticalBox() - vboxN.SetPadded(true) - vboxN.Append(ui.NewLabel("Account Nickname:"), false) - - Data.EntryNick = ui.NewEntry() - Data.EntryNick.SetReadOnly(false) - - vboxN.Append(Data.EntryNick, false) - - Data.EntryNick.OnChanged(func(*ui.Entry) { - log.Println("OK. nickname =", Data.EntryNick.Text()) - // Data.AccNick = entryNick.Text() - }) - hboxAccount.Append(vboxN, false) - // End 'Nickname' vertical box - - // Start 'Username' vertical box - vboxU := ui.NewVerticalBox() - vboxU.SetPadded(true) - vboxU.Append(ui.NewLabel("Account Username:"), false) - - Data.EntryUser = ui.NewEntry() - Data.EntryUser.SetReadOnly(false) - - vboxU.Append(Data.EntryUser, false) - - Data.EntryUser.OnChanged(func(*ui.Entry) { - log.Println("OK. username =", Data.EntryUser.Text()) - // Data.AccUser = entryUser.Text() - }) - hboxAccount.Append(vboxU, false) - // End 'Username' vertical box - - // Start 'Password' vertical box - vboxP := ui.NewVerticalBox() - vboxP.SetPadded(true) - vboxP.Append(ui.NewLabel("Account Password:"), false) - - Data.EntryPass = ui.NewEntry() - Data.EntryPass.SetReadOnly(false) - - vboxP.Append(Data.EntryPass, false) - - Data.EntryPass.OnChanged(func(*ui.Entry) { - log.Println("OK. password =", Data.EntryPass.Text()) - // Data.AccPass = entryPass.Text() - }) - hboxAccount.Append(vboxP, false) - // End 'Password' vertical box - - vbox.Append(ui.NewHorizontalSeparator(), false) - - hboxButtons := ui.NewHorizontalBox() - hboxButtons.SetPadded(true) - vbox.Append(hboxButtons, false) - - okButton := CreateButton(gb, nil, nil, "Add Account", "ADD", nil) - hboxButtons.Append(okButton.B, false) - - backButton := CreateButton(gb, nil, nil, "Back", "BACK", nil) - hboxButtons.Append(backButton.B, false) - - return gb -} -*/ diff --git a/gui.go b/gui.go index c78439b..f0f3cfb 100644 --- a/gui.go +++ b/gui.go @@ -325,3 +325,45 @@ func MakeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action s 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) + + ue := ui.NewEntry() + ue.SetReadOnly(false) + ue.OnChanged(func(*ui.Entry) { + log.Println("gui.AddEntry() OK. ue.Text() =", ue.Text()) + }) + box.UiBox.Append(ue, false) + + ge.UiEntry = ue + box.EntryMap[name] = ge + + return ge +} + +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.W = gw + + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + vbox.Append(hbox, false) + + return gb +} + +func HorizontalBreak(box *GuiBox) { + tmp := ui.NewHorizontalSeparator() + box.UiBox.Append(tmp, false) +} diff --git a/mainCloudBox.go b/mainCloudBox.go index 5982a27..8f628e6 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -115,41 +115,13 @@ func ShowAccountQuestionTab(gw *GuiWindow) { log.Println("Sleep(200)") time.Sleep(200 * time.Millisecond) - abox := AddAccountQuestionBox(gw) + // abox := AddAccountQuestionBox(gw) + abox := gw.MakeTab(gw) gw.BoxMap["Box2"] = abox - // gw.Box2 = AddAccountQuestionBox(gw) gw.UiTab.InsertAt("New Account?", 0, abox.UiBox) gw.UiTab.SetMargined(0, true) } -/* -func ShowAccountTab(gw *GuiWindow, i int) { - log.Println("ShowAccountTab() START") - - log.Println("Sleep(200)") - time.Sleep(200 * time.Millisecond) - - // Create the things for the Account Tab - abox := AddAccountBox(gw) - - // Set the parents and data structure links - // aTab.me = gw.UiTab - // aTab.parentWindow = Data.Window1.W - // aTab.tabOffset = 0 - - if (i >= 0) { - log.Println("ShowAccountTab() InsertAt i=", i) - gw.UiTab.Delete(0) - gw.UiTab.InsertAt("Add Account", i, abox.UiBox) - gw.UiTab.SetMargined(0, true) - } else { - // TODO: After append try to discover the tab index # - log.Println("ShowAccountTab() Append") - AddBoxToTab("Create New Account", gw.UiTab, abox.UiBox) - } -} -*/ - func ShowMainTab(gw *GuiWindow) { log.Println("ShowMainTab() gw =", gw) log.Println("ShowMainTab() gw.UiTab =", gw.UiTab) From c11e03c4998afbaacbba67fc50ee2dabba8c63f9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 02:41:03 -0700 Subject: [PATCH 06/15] more moving to vm Signed-off-by: Jeff Carr --- debug.go | 2 +- gui.go | 12 +++++++----- mainCloudBox.go | 2 ++ vmBox.go | 19 +++++++++++++------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/debug.go b/debug.go index 8e21122..7ea50b8 100644 --- a/debug.go +++ b/debug.go @@ -14,7 +14,7 @@ import "github.com/davecgh/go-spew/spew" // import pb "git.wit.com/wit/witProtobuf" -// THIS IS CLEAN +// THIS IS NOT CLEAN (but probably doesn't need to be. it's debugging) // can not pass any args to this (?) /* diff --git a/gui.go b/gui.go index f0f3cfb..7090a5f 100644 --- a/gui.go +++ b/gui.go @@ -103,8 +103,8 @@ func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnDa hbox := ui.NewHorizontalBox() hbox.SetPadded(true) - a := CreateButton(gb, account, nil, "Add Virtual Machine", "createAddVmBox", nil) - hbox.Append(a.B, false) +// a := CreateButton(gb, account, nil, "Add Virtual Machine", "createAddVmBox", nil) +// hbox.Append(a.B, false) vbox.Append(hbox, false) @@ -136,11 +136,13 @@ func mouseClick(b *GuiButton) { log.Println("\tgui.mouseClick() START b = nil") } else { log.Println("\tgui.mouseClick() START b.Action =", b.Action) - if (b.Action == "createAddVmBox") { - log.Println("\tgui.mouseClick() createAddVmBox for b =", b) - createAddVmBox(b.GW, b) + /* + if (b.Action == "CreateAddVmBox") { + log.Println("\tgui.mouseClick() CreateAddVmBox for b =", b) + CreateAddVmBox(b.GW, b) return } + */ /* if (b.Action == "WINDOW CLOSE") { b.W.Hide() diff --git a/mainCloudBox.go b/mainCloudBox.go index 8f628e6..2b1b252 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -13,6 +13,8 @@ import pb "git.wit.com/wit/witProtobuf" // import "github.com/davecgh/go-spew/spew" +// THIS IS NOT CLEAN + func makeCloudInfoBox(gw *GuiWindow) *GuiBox { var gb *GuiBox gb = new(GuiBox) diff --git a/vmBox.go b/vmBox.go index bb5bd69..55f78d3 100644 --- a/vmBox.go +++ b/vmBox.go @@ -10,6 +10,8 @@ import pb "git.wit.com/wit/witProtobuf" import "github.com/davecgh/go-spew/spew" +// THIS IS NOT CLEAN + func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) { log.Println("CreateVmBox() START") log.Println("CreateVmBox() vm.Name =", vm.Name) @@ -70,9 +72,8 @@ func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) { AddBoxToTab(vm.Name, gw.UiTab, vbox) } -func createAddVmBox(gw *GuiWindow, b *GuiButton) { - log.Println("createAddVmBox() START") - name := "(" + b.Account.Nick + ")" +func CreateAddVmBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{ + log.Println("CreateAddVmBox() START name =", name) var box *GuiBox box = new(GuiBox) @@ -87,12 +88,19 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) { hbox.SetPadded(true) vbox.Append(hbox, false) + // abox := gw.MakeTab(gw) + + AddBoxToTab(name, gw.UiTab, vbox) + + return box + + /* // Add hostname entry box hostname := MakeEntryHbox(box, "Hostname:", "testhost", true, "Hostname") memory := MakeEntryHbox(box, "Memory:", "512", true, "Memory") disk := MakeEntryHbox(box, "Disk:", "20", true, "Disk") - log.Println("createAddVmBox() hostname, memory, disk =", hostname, memory, disk) + log.Println("CreateAddVmBox() hostname, memory, disk =", hostname, memory, disk) vbox.Append(ui.NewHorizontalSeparator(), false) @@ -111,6 +119,5 @@ func createAddVmBox(gw *GuiWindow, b *GuiButton) { a := CreateButton(box, nil, nil, "Cancel", "CLOSE", nil) hboxButtons.Append(a.B, false) - - AddBoxToTab(name, gw.UiTab, vbox) + */ } From 32d07aaf5fea2719a9f11c7976a58256808ef87b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 02:58:49 -0700 Subject: [PATCH 07/15] more cleaning Signed-off-by: Jeff Carr --- area.go | 4 +- gui.go | 93 ++++++++++++++++++----------------------------- tableCallbacks.go | 4 +- vmBox.go | 50 ------------------------- 4 files changed, 41 insertions(+), 110 deletions(-) diff --git a/area.go b/area.go index 3582900..42ea850 100644 --- a/area.go +++ b/area.go @@ -75,7 +75,9 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { log.Println("GOT MOUSE UP") log.Println("GOT MOUSE UP ah.Button =", ah.Button) log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB) - mouseClick(ah.Button) + if (Data.MouseClick != nil) { + Data.MouseClick(ah.Button) + } } } diff --git a/gui.go b/gui.go index 7090a5f..0906e58 100644 --- a/gui.go +++ b/gui.go @@ -10,7 +10,7 @@ import pb "git.wit.com/wit/witProtobuf" import "github.com/davecgh/go-spew/spew" -// THIS IS CLEAN (all that is left is the 'createAddVmBox') +// THIS IS CLEAN (all that is left is the 'ADD VM') func InitColumns(mh *TableData, parts []TableColumnData) { tmpBTindex := 0 @@ -96,16 +96,12 @@ func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnDa vbox.Append(table, true) gw.UiTab.Append(name, vbox) - // mytab.SetMargined(mytabcount, true) vbox.Append(ui.NewVerticalSeparator(), false) hbox := ui.NewHorizontalBox() hbox.SetPadded(true) -// a := CreateButton(gb, account, nil, "Add Virtual Machine", "createAddVmBox", nil) -// hbox.Append(a.B, false) - vbox.Append(hbox, false) return mh @@ -124,47 +120,6 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { // something specific will fall into this routine // By default, all it runs is the call back to // the main program that is using this library - -// This is one of the routines that is called from the -// defaultButtonClick() below when the button is found -// in the AllButtons %map -// TODO: clean up the text above -// TODO: remove this all together going only to main() -func mouseClick(b *GuiButton) { - log.Println("gui.mouseClick() START") - if (b == nil) { - log.Println("\tgui.mouseClick() START b = nil") - } else { - log.Println("\tgui.mouseClick() START b.Action =", b.Action) - /* - if (b.Action == "CreateAddVmBox") { - log.Println("\tgui.mouseClick() CreateAddVmBox for b =", b) - CreateAddVmBox(b.GW, b) - return - } - */ - /* - if (b.Action == "WINDOW CLOSE") { - b.W.Hide() - // TODO: fix this (seems to crash? maybe because we are in the button here?) - // b.W.Destroy() - return - } - if (b.Action == "ADD") { - log.Println("\tgui.mouseClick() SHOULD ADD VM HERE?") - } - */ - } - - if (Data.MouseClick == nil) { - log.Println("\tgui.mouseClick() Data.MouseClick() IS nil. NOT DOING ANYTHING") - log.Println("\tgui.mouseClick() Your application did not set a MouseClick() callback function") - } else { - log.Println("\tgui.mouseClick() Data.MouseClick() START") - Data.MouseClick(b) - } -} - // // This routine MUST be here as this is how the andlabs/ui works // This is the raw routine passed to every button in andlabs libui / ui @@ -177,21 +132,21 @@ func defaultButtonClick(button *ui.Button) { for key, foo := range Data.AllButtons { if (Data.Debug) { log.Println("defaultButtonClick() Data.AllButtons =", key, foo) - spew.Dump(foo) + // spew.Dump(foo) } if Data.AllButtons[key].B == button { log.Println("\tdefaultButtonClick() BUTTON MATCHED") - // log.Println("\tData.AllButtons[key].Name =", Data.AllButtons[key].Name) log.Println("\tdefaultButtonClick() Data.AllButtons[key].Action =", Data.AllButtons[key].Action) if Data.AllButtons[key].custom != nil { log.Println("\tdefaultButtonClick() DOING CUSTOM FUNCTION") - var tmp *GuiButton - tmp = Data.AllButtons[key] - // spew.Dump(tmp) - Data.AllButtons[key].custom(tmp) + Data.AllButtons[key].custom(Data.AllButtons[key]) return } - mouseClick(Data.AllButtons[key]) + if (Data.MouseClick != nil) { + Data.MouseClick(Data.AllButtons[key]) + } else { + log.Println("\tdefaultButtonClick() IGNORING BUTTON. MouseClick() is nil") + } return } } @@ -199,7 +154,6 @@ func defaultButtonClick(button *ui.Button) { if (Data.Debug) { panic("defaultButtonClick() SHOULD NOT HAVE UNMAPPED BUTTONS") } - mouseClick(nil) } func AddButton(b *GuiButton, name string) *ui.Button { @@ -249,7 +203,9 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton { newGB.FB.OnChanged(func (*ui.FontButton) { log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB) - mouseClick(&newGB) + if (Data.MouseClick != nil) { + Data.MouseClick(&newGB) + } }) return &newGB } @@ -345,6 +301,11 @@ func AddEntry(box *GuiBox, name string) *GuiEntry { return ge } +func HorizontalBreak(box *GuiBox) { + tmp := ui.NewHorizontalSeparator() + box.UiBox.Append(tmp, false) +} + func AddGenericBox(gw *GuiWindow) *GuiBox { var gb *GuiBox gb = new(GuiBox) @@ -365,7 +326,23 @@ func AddGenericBox(gw *GuiWindow) *GuiBox { return gb } -func HorizontalBreak(box *GuiBox) { - tmp := ui.NewHorizontalSeparator() - box.UiBox.Append(tmp, false) +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.W = gw + gw.BoxMap["ADD VM" + name] = box + + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + vbox.Append(hbox, false) + + AddBoxToTab(name, gw.UiTab, vbox) + + return box } diff --git a/tableCallbacks.go b/tableCallbacks.go index df9c408..f71cabc 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -110,7 +110,9 @@ func defaultSetCellValue(mh *TableData, row int, column int) { button := mh.Rows[row].HumanData[humanID].Button if (button != nil) { - mouseClick(button) + if (Data.MouseClick != nil) { + Data.MouseClick(button) + } return } if (Data.Debug) { diff --git a/vmBox.go b/vmBox.go index 55f78d3..bc51f52 100644 --- a/vmBox.go +++ b/vmBox.go @@ -71,53 +71,3 @@ func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) { AddBoxToTab(vm.Name, gw.UiTab, vbox) } - -func CreateAddVmBox(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.W = gw - gw.BoxMap["ADD VM" + name] = box - - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - vbox.Append(hbox, false) - - // abox := gw.MakeTab(gw) - - AddBoxToTab(name, gw.UiTab, vbox) - - return box - - /* - // Add hostname entry box - hostname := MakeEntryHbox(box, "Hostname:", "testhost", true, "Hostname") - memory := MakeEntryHbox(box, "Memory:", "512", true, "Memory") - disk := MakeEntryHbox(box, "Disk:", "20", true, "Disk") - - log.Println("CreateAddVmBox() hostname, memory, disk =", hostname, memory, disk) - - vbox.Append(ui.NewHorizontalSeparator(), false) - - hboxButtons := ui.NewHorizontalBox() - hboxButtons.SetPadded(true) - vbox.Append(hboxButtons, false) - - var newb GuiButton - newb.Action = "CREATE" - newb.VM = b.VM - newb.Account = b.Account - hostname.B = &newb - memory.B = &newb - disk.B = &newb - hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false) - - a := CreateButton(box, nil, nil, "Cancel", "CLOSE", nil) - hboxButtons.Append(a.B, false) - */ -} From a333a551182319865f18c8ac029f4e272ef96df4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 03:24:38 -0700 Subject: [PATCH 08/15] finally able to remove vmBox.go Signed-off-by: Jeff Carr --- gui.go | 29 ++++++++++++++++++++++ vmBox.go | 73 -------------------------------------------------------- 2 files changed, 29 insertions(+), 73 deletions(-) delete mode 100644 vmBox.go diff --git a/gui.go b/gui.go index 0906e58..32d76ae 100644 --- a/gui.go +++ b/gui.go @@ -346,3 +346,32 @@ func CreateGenericBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{ 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.W =", box.W) + box.W = 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 +} diff --git a/vmBox.go b/vmBox.go deleted file mode 100644 index bc51f52..0000000 --- a/vmBox.go +++ /dev/null @@ -1,73 +0,0 @@ -package gui - -import "log" -import "fmt" - -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 NOT CLEAN - -func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) { - log.Println("CreateVmBox() START") - log.Println("CreateVmBox() vm.Name =", vm.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.W =", box.W) - box.W = gw - log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap) - gw.BoxMap[vm.Name] = box - - if (Data.Debug) { - spew.Dump(vm) - } - - hboxAccount := ui.NewHorizontalBox() - hboxAccount.SetPadded(true) - vbox.Append(hboxAccount, false) - - box.UiBox = hboxAccount - - // Add hostname entry box - MakeEntryVbox(box, "hostname:", vm.Hostname, true, "Hostname") - MakeEntryVbox(box, "IPv6:", vm.IPv6, true, "IPv6") - MakeEntryVbox(box, "RAM:", fmt.Sprintf("%d",vm.Memory), true, "Memory") - MakeEntryVbox(box, "CPU:", fmt.Sprintf("%d",vm.Cpus), true, "Cpus") - MakeEntryVbox(box, "Disk (GB):",fmt.Sprintf("%d",vm.Disk), true, "Disk") - MakeEntryVbox(box, "OS Image:", vm.BaseImage, true, "BaseImage") - - vbox.Append(ui.NewHorizontalSeparator(), false) - - hboxButtons := ui.NewHorizontalBox() - hboxButtons.SetPadded(true) - vbox.Append(hboxButtons, false) - - a := CreateButton(box, nil, vm, "Power On", "POWERON", nil) - hboxButtons.Append(a.B, false) - a = CreateButton(box, nil, vm, "Power Off", "POWEROFF", nil) - hboxButtons.Append(a.B, false) - a = CreateButton(box, nil, vm, "Destroy", "DESTROY", nil) - hboxButtons.Append(a.B, false) - a = CreateButton(box, nil, vm, "ping", "PING", runPingClick) - hboxButtons.Append(a.B, false) - a = CreateButton(box, nil, vm, "Console", "XTERM", runTestExecClick) - hboxButtons.Append(a.B, false) - a = CreateButton(box, nil, vm, "Save", "SAVE", nil) - hboxButtons.Append(a.B, false) - a = CreateButton(box, nil, vm, "Done", "DONE", nil) - hboxButtons.Append(a.B, false) - - AddBoxToTab(vm.Name, gw.UiTab, vbox) -} From bd757b60bb3b27a0dc17e0c9cef277a9a6466382 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 03:38:49 -0700 Subject: [PATCH 09/15] only one function left to clean Signed-off-by: Jeff Carr --- mainCloudBox.go | 204 ------------------------------------------------ misc.go | 199 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 204 deletions(-) create mode 100644 misc.go diff --git a/mainCloudBox.go b/mainCloudBox.go index 2b1b252..059f3b3 100644 --- a/mainCloudBox.go +++ b/mainCloudBox.go @@ -1,18 +1,10 @@ package gui import "log" -import "time" -import "regexp" -import "os" -// import "reflect" 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 NOT CLEAN func makeCloudInfoBox(gw *GuiWindow) *GuiBox { @@ -25,19 +17,11 @@ func makeCloudInfoBox(gw *GuiWindow) *GuiBox { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) - // gw.Box1 = hbox gb.UiBox = hbox if (Data.Debug) { log.Println("makeCloudInfoBox() add debugging buttons") - /* - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - hbox.Append(vbox, false) - */ - addDebuggingButtons(gb) - hbox.Append(ui.NewVerticalSeparator(), false) } @@ -105,191 +89,3 @@ func makeCloudInfoBox(gw *GuiWindow) *GuiBox { vbox.Append(agrid, false) return gb } - -func ShowAccountQuestionTab(gw *GuiWindow) { - log.Println("ShowAccountQuestionTab() gw =", gw) - if (gw.UiTab == nil) { - log.Println("ShowAccountQuestionTab() gw.UiTab = nil THIS IS BAD") - os.Exit(-1) - } - gw.UiTab.Delete(0) - - log.Println("Sleep(200)") - time.Sleep(200 * time.Millisecond) - - // abox := AddAccountQuestionBox(gw) - abox := gw.MakeTab(gw) - gw.BoxMap["Box2"] = abox - gw.UiTab.InsertAt("New Account?", 0, abox.UiBox) - gw.UiTab.SetMargined(0, true) -} - -func ShowMainTab(gw *GuiWindow) { - log.Println("ShowMainTab() gw =", gw) - log.Println("ShowMainTab() gw.UiTab =", gw.UiTab) - gw.UiTab.Delete(0) - - log.Println("Sleep(200)") - time.Sleep(200 * time.Millisecond) - - abox := makeCloudInfoBox(gw) - gw.BoxMap["Box3"] = abox - gw.UiTab.InsertAt("Main", 0, abox.UiBox) - gw.UiTab.SetMargined(0, true) -} - -func GuiInit() { - ui.OnShouldQuit(func() bool { - // mouseClick(&newBM) - ui.Quit() - return true - }) -} - -func StartNewWindow(c *pb.Config, bg bool, action string, maketab func(*GuiWindow) *GuiBox) { - log.Println("InitNewWindow() Create a new window") - var newGuiWindow GuiWindow - newGuiWindow.Width = int(c.Width) - newGuiWindow.Height = int(c.Height) - newGuiWindow.Action = action - newGuiWindow.MakeTab = maketab - Data.Windows = append(Data.Windows, &newGuiWindow) - - // make(newGuiWindow.BoxMap) - newGuiWindow.BoxMap = make(map[string]*GuiBox) - - if (bg) { - log.Println("ShowWindow() IN NEW GOROUTINE") - go ui.Main(func() { - InitTabWindow(&newGuiWindow) - }) - time.Sleep(2000 * time.Millisecond) - } else { - log.Println("ShowWindow() WAITING for ui.Main()") - ui.Main(func() { - InitTabWindow(&newGuiWindow) - }) - } -} - -func getSplashText(a string) *ui.AttributedString { - var aText *ui.AttributedString - aText = ui.NewAttributedString(a) - return aText -} - -func InitTabWindow(gw *GuiWindow) { - log.Println("InitTabWindow() THIS WINDOW IS NOT YET SHOWN") - - gw.UiWindow = ui.NewWindow("", int(gw.Width), int(gw.Height), true) - gw.UiWindow.SetBorderless(false) - - // create a 'fake' button entry for the mouse clicks - var newBM GuiButton - newBM.Action = "QUIT" -// newBM.W = gw.UiWindow - newBM.GW = gw - Data.AllButtons = append(Data.AllButtons, &newBM) - - gw.UiWindow.OnClosing(func(*ui.Window) bool { - log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) - // mouseClick(&newBM) - ui.Quit() - return true - }) - - gw.UiTab = ui.NewTab() - gw.UiWindow.SetChild(gw.UiTab) - gw.UiWindow.SetMargined(true) - - log.Println("InitTabWindow() gw =", gw) - - abox := gw.MakeTab(gw) - - gw.UiTab.Append("WIT Splash", abox.UiBox) - gw.UiTab.SetMargined(0, true) - - Data.State = "splash" - gw.UiWindow.Show() -} - -func AddBoxToTab(name string, tab *ui.Tab, box *ui.Box) { - tab.Append(name, box) - tab.SetMargined(0, true) -} - -/* -// string handling examples that might be helpful for normalizeInt() -isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString - -for _, username := range []string{"userone", "user2", "user-three"} { - if !isAlpha(username) { - fmt.Printf("%q is not valid\n", username) - } -} - -const alpha = "abcdefghijklmnopqrstuvwxyz" - -func alphaOnly(s string) bool { - for _, char := range s { - if !strings.Contains(alpha, strings.ToLower(string(char))) { - return false - } - } - return true -} -*/ - -func normalizeInt(s string) string { - // reg, err := regexp.Compile("[^a-zA-Z0-9]+") - reg, err := regexp.Compile("[^0-9]+") - if err != nil { - log.Println("normalizeInt() regexp.Compile() ERROR =", err) - return s - } - clean := reg.ReplaceAllString(s, "") - log.Println("normalizeInt() s =", clean) - return clean -} - -func defaultEntryChange(e *ui.Entry) { - for key, em := range Data.AllEntries { - if (Data.Debug) { - log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em) - } - if Data.AllEntries[key].UiEntry == e { - log.Println("defaultEntryChange() FOUND", - "action =", Data.AllEntries[key].Action, - "Last =", Data.AllEntries[key].Last, - "e.Text() =", e.Text()) - Data.AllEntries[key].Last = e.Text() - if Data.AllEntries[key].Normalize != nil { - fixed := Data.AllEntries[key].Normalize(e.Text()) - e.SetText(fixed) - } - return - } - } - log.Println("defaultEntryChange() ERROR. MISSING ENTRY MAP. e.Text() =", e.Text()) -} - -func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry { - e := ui.NewEntry() - e.SetText(startValue) - if (edit == false) { - e.SetReadOnly(true) - } - e.OnChanged(defaultEntryChange) - - // add the entry field to the global map - var newEntry GuiEntry - newEntry.UiEntry = e - newEntry.Edit = edit - newEntry.Action = action - if (action == "Memory") { - newEntry.Normalize = normalizeInt - } - Data.AllEntries = append(Data.AllEntries, &newEntry) - - return &newEntry -} diff --git a/misc.go b/misc.go new file mode 100644 index 0000000..a226c39 --- /dev/null +++ b/misc.go @@ -0,0 +1,199 @@ +package gui + +import "log" +import "time" +import "regexp" +import "os" + +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 NOT CLEAN (almost?) + +func ShowTab(gw *GuiWindow, tabname string, title string) { + log.Println("ShowTab() gw =", gw) + if (gw.UiTab == nil) { + log.Println("ShowTab() gw.UiTab = nil THIS IS BAD") + os.Exit(-1) + } + gw.UiTab.Delete(0) + + abox := gw.MakeTab(gw) + gw.BoxMap[tabname] = abox + gw.UiTab.InsertAt(title, 0, abox.UiBox) + gw.UiTab.SetMargined(0, true) +} + +func GuiInit() { + ui.OnShouldQuit(func() bool { + // mouseClick(&newBM) + ui.Quit() + return true + }) +} + +func ShowMainTab(gw *GuiWindow) { + log.Println("ShowMainTab() gw =", gw) + log.Println("ShowMainTab() gw.UiTab =", gw.UiTab) + gw.UiTab.Delete(0) + + log.Println("Sleep(200)") + time.Sleep(200 * time.Millisecond) + + abox := makeCloudInfoBox(gw) + gw.BoxMap["Box3"] = abox + gw.UiTab.InsertAt("Main", 0, abox.UiBox) + gw.UiTab.SetMargined(0, true) +} + +func StartNewWindow(c *pb.Config, bg bool, action string, maketab func(*GuiWindow) *GuiBox) { + log.Println("InitNewWindow() Create a new window") + var newGuiWindow GuiWindow + newGuiWindow.Width = int(c.Width) + newGuiWindow.Height = int(c.Height) + newGuiWindow.Action = action + newGuiWindow.MakeTab = maketab + Data.Windows = append(Data.Windows, &newGuiWindow) + + // make(newGuiWindow.BoxMap) + newGuiWindow.BoxMap = make(map[string]*GuiBox) + + if (bg) { + log.Println("ShowWindow() IN NEW GOROUTINE") + go ui.Main(func() { + InitTabWindow(&newGuiWindow) + }) + time.Sleep(2000 * time.Millisecond) + } else { + log.Println("ShowWindow() WAITING for ui.Main()") + ui.Main(func() { + InitTabWindow(&newGuiWindow) + }) + } +} + +func getSplashText(a string) *ui.AttributedString { + var aText *ui.AttributedString + aText = ui.NewAttributedString(a) + return aText +} + +func InitTabWindow(gw *GuiWindow) { + log.Println("InitTabWindow() THIS WINDOW IS NOT YET SHOWN") + + gw.UiWindow = ui.NewWindow("", int(gw.Width), int(gw.Height), true) + gw.UiWindow.SetBorderless(false) + + // create a 'fake' button entry for the mouse clicks + var newBM GuiButton + newBM.Action = "QUIT" +// newBM.W = gw.UiWindow + newBM.GW = gw + Data.AllButtons = append(Data.AllButtons, &newBM) + + gw.UiWindow.OnClosing(func(*ui.Window) bool { + log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) + // mouseClick(&newBM) + ui.Quit() + return true + }) + + gw.UiTab = ui.NewTab() + gw.UiWindow.SetChild(gw.UiTab) + gw.UiWindow.SetMargined(true) + + log.Println("InitTabWindow() gw =", gw) + + abox := gw.MakeTab(gw) + + gw.UiTab.Append("WIT Splash", abox.UiBox) + gw.UiTab.SetMargined(0, true) + + Data.State = "splash" + gw.UiWindow.Show() +} + +func AddBoxToTab(name string, tab *ui.Tab, box *ui.Box) { + tab.Append(name, box) + tab.SetMargined(0, true) +} + +/* +// string handling examples that might be helpful for normalizeInt() +isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString + +for _, username := range []string{"userone", "user2", "user-three"} { + if !isAlpha(username) { + fmt.Printf("%q is not valid\n", username) + } +} + +const alpha = "abcdefghijklmnopqrstuvwxyz" + +func alphaOnly(s string) bool { + for _, char := range s { + if !strings.Contains(alpha, strings.ToLower(string(char))) { + return false + } + } + return true +} +*/ + +func normalizeInt(s string) string { + // reg, err := regexp.Compile("[^a-zA-Z0-9]+") + reg, err := regexp.Compile("[^0-9]+") + if err != nil { + log.Println("normalizeInt() regexp.Compile() ERROR =", err) + return s + } + clean := reg.ReplaceAllString(s, "") + log.Println("normalizeInt() s =", clean) + return clean +} + +func defaultEntryChange(e *ui.Entry) { + for key, em := range Data.AllEntries { + if (Data.Debug) { + log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em) + } + if Data.AllEntries[key].UiEntry == e { + log.Println("defaultEntryChange() FOUND", + "action =", Data.AllEntries[key].Action, + "Last =", Data.AllEntries[key].Last, + "e.Text() =", e.Text()) + Data.AllEntries[key].Last = e.Text() + if Data.AllEntries[key].Normalize != nil { + fixed := Data.AllEntries[key].Normalize(e.Text()) + e.SetText(fixed) + } + return + } + } + log.Println("defaultEntryChange() ERROR. MISSING ENTRY MAP. e.Text() =", e.Text()) +} + +func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry { + e := ui.NewEntry() + e.SetText(startValue) + if (edit == false) { + e.SetReadOnly(true) + } + e.OnChanged(defaultEntryChange) + + // add the entry field to the global map + var newEntry GuiEntry + newEntry.UiEntry = e + newEntry.Edit = edit + newEntry.Action = action + if (action == "Memory") { + newEntry.Normalize = normalizeInt + } + Data.AllEntries = append(Data.AllEntries, &newEntry) + + return &newEntry +} From 2efce7f0cb91f9289e555feab61e522809ffdc1b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 11:45:15 -0700 Subject: [PATCH 10/15] change around the concept of "Window" and "Box" Signed-off-by: Jeff Carr --- gui.go | 35 +++++++++++++++++++ mainCloudBox.go | 91 ------------------------------------------------- misc.go | 41 ++++++++++++++++------ structs.go | 14 ++++++-- 4 files changed, 78 insertions(+), 103 deletions(-) delete mode 100644 mainCloudBox.go diff --git a/gui.go b/gui.go index 32d76ae..d939294 100644 --- a/gui.go +++ b/gui.go @@ -301,11 +301,46 @@ func AddEntry(box *GuiBox, name string) *GuiEntry { return ge } +func HardHorizontalBreak(box *GuiBox) { + log.Println("HardHorizontalBreak START") + gw := box.W + mainbox := gw.mainbox + + tmp := ui.NewHorizontalSeparator() + mainbox.Append(tmp, false) + + hbox := ui.NewVerticalBox() + hbox.SetPadded(true) + box.UiBox = hbox + mainbox.Append(hbox, true) + log.Println("HardHorizontalBreak END") +} + +func HardVerticalBreak(box *GuiBox) { + log.Println("HardVerticalBreak START") + gw := box.W + mainbox := gw.mainbox + + tmp := ui.NewVerticalSeparator() + mainbox.Append(tmp, false) + + hbox := ui.NewVerticalBox() + hbox.SetPadded(true) + box.UiBox = hbox + mainbox.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) diff --git a/mainCloudBox.go b/mainCloudBox.go deleted file mode 100644 index 059f3b3..0000000 --- a/mainCloudBox.go +++ /dev/null @@ -1,91 +0,0 @@ -package gui - -import "log" - -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" - -// THIS IS NOT CLEAN - -func makeCloudInfoBox(gw *GuiWindow) *GuiBox { - var gb *GuiBox - gb = new(GuiBox) - gb.W = gw - - gb.EntryMap = make(map[string]*GuiEntry) - gb.EntryMap["test"] = nil - - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - gb.UiBox = hbox - - if (Data.Debug) { - log.Println("makeCloudInfoBox() add debugging buttons") - addDebuggingButtons(gb) - hbox.Append(ui.NewVerticalSeparator(), false) - } - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - hbox.Append(vbox, true) - - hostnamebox := ui.NewHorizontalBox() - hostnamebox.SetPadded(true) - vbox.Append(hostnamebox, false) - - entryForm := ui.NewForm() - entryForm.SetPadded(true) - hostnamebox.Append(entryForm, true) - - hostnameEntry := ui.NewEntry() - entryForm.Append("hostname:", hostnameEntry, false) - tmp := Data.Hostname + " (" + Data.IPv6 + ")" - hostnameEntry.SetText(tmp) - hostnameEntry.SetReadOnly(true) - - anew := CreateButton(gb, nil, nil, "Edit", "EDIT", nil) - hostnamebox.Append(anew.B, false) - - vbox.Append(ui.NewHorizontalSeparator(), false) - - agrid := ui.NewGrid() - agrid.SetPadded(true) - - agrid.Append(ui.NewLabel("Accounts:"), 0, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - agrid.Append(ui.NewLabel("Domain Name"), 1, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - agrid.Append(ui.NewLabel("Email"), 2, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - - row := 1 - - for key, a := range Data.Config.Accounts { - log.Println("account = ", key, a) - log.Println("Accounts[key] = ", Data.Config.Accounts[key]) - log.Println("account.Nick = ", Data.Config.Accounts[key].Nick) - log.Println("account.Username = ", Data.Config.Accounts[key].Username) - log.Println("account.Token = ", Data.Config.Accounts[key].Token) - - agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Domain), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Email), 2, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - - name := "Login " + Data.Config.Accounts[key].Nick - l := CreateButton(gb, Data.Config.Accounts[key], nil, name, "LOGIN", nil) - agrid.Append(l.B, 3, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - - name = "Show " + Data.Config.Accounts[key].Nick - b := CreateButton(gb, Data.Config.Accounts[key], nil, name, "SHOW", nil) - agrid.Append(b.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - - row += 1 - } - - row += 1 - agrid.Append(ui.NewLabel(""), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - row += 1 - a := CreateButton(gb, nil, nil, "Add Account", "ADD TAB", nil) - agrid.Append(a.B, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - q := CreateButton(gb, nil, nil, "Quit", "QUIT", nil) - agrid.Append(q.B, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill) - - vbox.Append(agrid, false) - return gb -} diff --git a/misc.go b/misc.go index a226c39..bc31844 100644 --- a/misc.go +++ b/misc.go @@ -22,7 +22,7 @@ func ShowTab(gw *GuiWindow, tabname string, title string) { } gw.UiTab.Delete(0) - abox := gw.MakeTab(gw) + abox := gw.MakeWindow(gw) gw.BoxMap[tabname] = abox gw.UiTab.InsertAt(title, 0, abox.UiBox) gw.UiTab.SetMargined(0, true) @@ -36,17 +36,38 @@ func GuiInit() { }) } -func ShowMainTab(gw *GuiWindow) { +func ShowMainTab(gw *GuiWindow) *GuiBox { log.Println("ShowMainTab() gw =", gw) log.Println("ShowMainTab() gw.UiTab =", gw.UiTab) - gw.UiTab.Delete(0) - log.Println("Sleep(200)") - time.Sleep(200 * time.Millisecond) + var box *GuiBox + box = new(GuiBox) + box.W = gw - abox := makeCloudInfoBox(gw) - gw.BoxMap["Box3"] = abox - gw.UiTab.InsertAt("Main", 0, abox.UiBox) + box.EntryMap = make(map[string]*GuiEntry) + box.EntryMap["test"] = nil + + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + box.UiBox = hbox + gw.mainbox = hbox + + if (Data.Debug) { + log.Println("makeCloudInfoBox() add debugging buttons") + addDebuggingButtons(box) + hbox.Append(ui.NewVerticalSeparator(), false) + } + + // box := gw.MakeWindow(gw) + // abox := makeCloudInfoBox(gw, box) + return box +} + +func ShowMainTabShowBox(gw *GuiWindow, box *GuiBox) { + log.Println("gui.ShowMainTabShowBox() box =", box) + // gw.UiTab.Delete(0) + gw.BoxMap["Box3"] = box + gw.UiTab.InsertAt("Main", 0, gw.mainbox) gw.UiTab.SetMargined(0, true) } @@ -56,7 +77,7 @@ func StartNewWindow(c *pb.Config, bg bool, action string, maketab func(*GuiWindo newGuiWindow.Width = int(c.Width) newGuiWindow.Height = int(c.Height) newGuiWindow.Action = action - newGuiWindow.MakeTab = maketab + newGuiWindow.MakeWindow = maketab Data.Windows = append(Data.Windows, &newGuiWindow) // make(newGuiWindow.BoxMap) @@ -108,7 +129,7 @@ func InitTabWindow(gw *GuiWindow) { log.Println("InitTabWindow() gw =", gw) - abox := gw.MakeTab(gw) + abox := gw.MakeWindow(gw) gw.UiTab.Append("WIT Splash", abox.UiBox) gw.UiTab.SetMargined(0, true) diff --git a/structs.go b/structs.go index 430f136..e03145d 100644 --- a/structs.go +++ b/structs.go @@ -73,14 +73,23 @@ type GuiData struct { // type GuiWindow struct { Action string - BoxMap map[string]*GuiBox Width int Height int + mainbox *ui.Box + + // the callback function to make the window contents + MakeWindow func(*GuiWindow) *GuiBox + + // the components of the window + BoxMap map[string]*GuiBox + EntryMap map[string]*GuiEntry + Area *GuiArea + ButtonMap map[*GuiButton][]func (*GuiButton) + // andlabs/ui abstraction mapping UiWindow *ui.Window UiTab *ui.Tab // if this != nil, the window is 'tabbed' - MakeTab func(*GuiWindow) *GuiBox } @@ -122,6 +131,7 @@ type GuiEntry struct { B *GuiButton Box *GuiBox + Account *pb.Account VM *pb.Event_VM From 20a402f10604e515f15fecc2496786a2a39fc983 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 12:43:40 -0700 Subject: [PATCH 11/15] rename fields Signed-off-by: Jeff Carr --- area.go | 4 ++-- gui.go | 21 ++++++++++----------- misc.go | 4 ++-- structs.go | 21 +++++++++++++-------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/area.go b/area.go index 42ea850..dd7d20a 100644 --- a/area.go +++ b/area.go @@ -15,7 +15,7 @@ func makeSplashArea(gb *GuiBox, newText *ui.AttributedString) { var newB *GuiButton newB = CreateFontButton(gb, "AREA") newB.Box = gb - newB.GW = gb.W + newB.GW = gb.Window // initialize the GuiArea{} gb.Area = new(GuiArea) @@ -124,7 +124,7 @@ func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox { newbox := ui.NewVerticalBox() newbox.SetPadded(true) gb.UiBox = newbox - gb.W = gw + gb.Window = gw gw.BoxMap["Splash"] = gb makeSplashArea(gb, newText) diff --git a/gui.go b/gui.go index d939294..42b9297 100644 --- a/gui.go +++ b/gui.go @@ -90,7 +90,7 @@ func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnDa vbox := ui.NewVerticalBox() vbox.SetPadded(true) gb.UiBox = vbox - gb.W = gw + gb.Window = gw gw.BoxMap[name] = gb mh.Box = gb @@ -176,18 +176,17 @@ func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, acti var newB *GuiButton newB = new(GuiButton) newB.B = newUiB - if (box.W == nil) { - log.Println("CreateButton() box.W == nil") + if (box.Window == nil) { + log.Println("CreateButton() box.Window == nil") panic("crap") } - newB.GW = box.W + newB.GW = box.Window newB.Account = a newB.VM = vm newB.Box = box newB.Action = action newB.custom = custom Data.AllButtons = append(Data.AllButtons, newB) - return newB } @@ -303,7 +302,7 @@ func AddEntry(box *GuiBox, name string) *GuiEntry { func HardHorizontalBreak(box *GuiBox) { log.Println("HardHorizontalBreak START") - gw := box.W + gw := box.Window mainbox := gw.mainbox tmp := ui.NewHorizontalSeparator() @@ -318,7 +317,7 @@ func HardHorizontalBreak(box *GuiBox) { func HardVerticalBreak(box *GuiBox) { log.Println("HardVerticalBreak START") - gw := box.W + gw := box.Window mainbox := gw.mainbox tmp := ui.NewVerticalSeparator() @@ -352,7 +351,7 @@ func AddGenericBox(gw *GuiWindow) *GuiBox { vbox.SetPadded(true) // gw.Box1 = vbox gb.UiBox = vbox - gb.W = gw + gb.Window = gw hbox := ui.NewHorizontalBox() hbox.SetPadded(true) @@ -370,7 +369,7 @@ func CreateGenericBox(gw *GuiWindow, b *GuiButton, name string) *GuiBox{ vbox := ui.NewVerticalBox() vbox.SetPadded(true) box.UiBox = vbox - box.W = gw + box.Window = gw gw.BoxMap["ADD VM" + name] = box hbox := ui.NewHorizontalBox() @@ -395,8 +394,8 @@ func CreateBox(gw *GuiWindow, name string) *GuiBox { log.Println("CreateVmBox() vbox =", vbox) log.Println("CreateVmBox() box.UiBox =", box.UiBox) box.UiBox = vbox - log.Println("CreateVmBox() box.W =", box.W) - box.W = gw + log.Println("CreateVmBox() box.Window =", box.Window) + box.Window = gw log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap) gw.BoxMap[name] = box diff --git a/misc.go b/misc.go index bc31844..bfc9a7d 100644 --- a/misc.go +++ b/misc.go @@ -42,7 +42,7 @@ func ShowMainTab(gw *GuiWindow) *GuiBox { var box *GuiBox box = new(GuiBox) - box.W = gw + box.Window = gw box.EntryMap = make(map[string]*GuiEntry) box.EntryMap["test"] = nil @@ -78,10 +78,10 @@ func StartNewWindow(c *pb.Config, bg bool, action string, maketab func(*GuiWindo newGuiWindow.Height = int(c.Height) newGuiWindow.Action = action newGuiWindow.MakeWindow = maketab + newGuiWindow.BoxMap = make(map[string]*GuiBox) Data.Windows = append(Data.Windows, &newGuiWindow) // make(newGuiWindow.BoxMap) - newGuiWindow.BoxMap = make(map[string]*GuiBox) if (bg) { log.Println("ShowWindow() IN NEW GOROUTINE") diff --git a/structs.go b/structs.go index e03145d..6c72ed3 100644 --- a/structs.go +++ b/structs.go @@ -49,24 +49,30 @@ type GuiData struct { // A map of all buttons everywhere on all // windows, all tabs, across all goroutines // This is "GLOBAL" + // + // This has to work this way because of how + // andlabs/ui & andlabs/libui work AllButtons []*GuiButton - ButtonMap map[*GuiButton][]func (*GuiButton) EntryNick *ui.Entry EntryUser *ui.Entry EntryPass *ui.Entry } -// stores information on 'the' window - +// +// stores information on the 'window' +// +// This merges the concept of andlabs/ui *Window and *Tab +// // More than one Window is not supported in a cross platform // sense & may never be. On Windows and MacOS, you have to have // 'tabs'. Even under Linux, more than one Window is currently // unstable // -// This code will keep track of if the windows is 'tabbed' or -// not. You can draw one thing in the window, then destroy -// that, then redraw the window with something else +// This code will make a 'GuiWindow' regardless of if it is +// a stand alone window (which is more or less working on Linux) +// or a 'tab' inside a window (which is all that works on MacOS +// and MSWindows. // // This struct keeps track of what is in the window so you // can destroy and replace it with something else @@ -85,7 +91,6 @@ type GuiWindow struct { BoxMap map[string]*GuiBox EntryMap map[string]*GuiEntry Area *GuiArea - ButtonMap map[*GuiButton][]func (*GuiButton) // andlabs/ui abstraction mapping UiWindow *ui.Window @@ -115,7 +120,7 @@ type GuiButton struct { } type GuiBox struct { - W *GuiWindow + Window *GuiWindow EntryMap map[string]*GuiEntry Area *GuiArea From a941c5a0f1e5a2c81143978f425c7d60344bbe39 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 13:41:45 -0700 Subject: [PATCH 12/15] start handling 'Guiwindow' correctly Signed-off-by: Jeff Carr --- area.go | 17 +++++++++-------- gui.go | 2 +- misc.go | 6 +++++- structs.go | 1 - 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/area.go b/area.go index dd7d20a..7087534 100644 --- a/area.go +++ b/area.go @@ -17,18 +17,19 @@ func makeSplashArea(gb *GuiBox, newText *ui.AttributedString) { newB.Box = gb newB.GW = gb.Window + gw := gb.Window // initialize the GuiArea{} - gb.Area = new(GuiArea) - gb.Area.Button = newB - gb.Area.Box = gb - gb.Area.UiAttrstr = newText - gb.Area.UiArea = ui.NewArea(gb.Area) + gw.Area = new(GuiArea) + gw.Area.Button = newB + gw.Area.Box = gb + gw.Area.UiAttrstr = newText + gw.Area.UiArea = ui.NewArea(gw.Area) if (Data.Debug) { - spew.Dump(gb.Area.UiArea) + spew.Dump(gw.Area.UiArea) log.Println("DEBUGGING", Data.Debug) } else { - log.Println("NOT DEBUGGING AREA mhAH.Button =", gb.Area.Button) + log.Println("NOT DEBUGGING AREA mhAH.Button =", gw.Area.Button) } } @@ -128,7 +129,7 @@ func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox { gw.BoxMap["Splash"] = gb makeSplashArea(gb, newText) - newbox.Append(gb.Area.UiArea, true) + newbox.Append(gw.Area.UiArea, true) return gb } diff --git a/gui.go b/gui.go index 42b9297..f60fee1 100644 --- a/gui.go +++ b/gui.go @@ -197,7 +197,7 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton { newGB.Action = action newGB.FB = ui.NewFontButton() newGB.Box = box - newGB.Area = box.Area + newGB.Area = box.Window.Area Data.AllButtons = append(Data.AllButtons, &newGB) newGB.FB.OnChanged(func (*ui.FontButton) { diff --git a/misc.go b/misc.go index bfc9a7d..6a617e8 100644 --- a/misc.go +++ b/misc.go @@ -36,10 +36,14 @@ func GuiInit() { }) } -func ShowMainTab(gw *GuiWindow) *GuiBox { +func AddMainTab(gw *GuiWindow) *GuiBox { log.Println("ShowMainTab() gw =", gw) log.Println("ShowMainTab() gw.UiTab =", gw.UiTab) + newWindow := new(GuiWindow) + newWindow.UiWindow = gw.UiWindow + Data.Windows = append(Data.Windows, newWindow) + var box *GuiBox box = new(GuiBox) box.Window = gw diff --git a/structs.go b/structs.go index 6c72ed3..6370705 100644 --- a/structs.go +++ b/structs.go @@ -122,7 +122,6 @@ type GuiButton struct { type GuiBox struct { Window *GuiWindow EntryMap map[string]*GuiEntry - Area *GuiArea // andlabs/ui abstraction mapping UiBox *ui.Box From 6a0467f5a88ee518e04da86e381b3731f9bd91b9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 14:10:12 -0700 Subject: [PATCH 13/15] compiles again Signed-off-by: Jeff Carr --- area.go | 4 ++-- gui.go | 40 ++++++++++++++++++++-------------------- misc.go | 54 ++++++++++++++++++++++++++++++++++++++---------------- structs.go | 4 +++- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/area.go b/area.go index 7087534..c841219 100644 --- a/area.go +++ b/area.go @@ -119,8 +119,8 @@ func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString) *GuiBox { var gb *GuiBox gb = new(GuiBox) - gb.EntryMap = make(map[string]*GuiEntry) - gb.EntryMap["test"] = nil +// gw.EntryMap = make(map[string]*GuiEntry) +// gw.EntryMap["test"] = nil newbox := ui.NewVerticalBox() newbox.SetPadded(true) diff --git a/gui.go b/gui.go index f60fee1..4b44c54 100644 --- a/gui.go +++ b/gui.go @@ -84,8 +84,8 @@ func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnDa var gb *GuiBox gb = new(GuiBox) - gb.EntryMap = make(map[string]*GuiEntry) - gb.EntryMap["test"] = nil +// gb.EntryMap = make(map[string]*GuiEntry) +// gb.EntryMap["test"] = nil vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -214,17 +214,17 @@ func GetText(box *GuiBox, name string) string { log.Println("gui.GetText() ERROR box == nil") return "" } - if (box.EntryMap == nil) { - log.Println("gui.GetText() ERROR b.Box.EntryMap == nil") + if (box.Window.EntryMap == nil) { + log.Println("gui.GetText() ERROR b.Box.Window.EntryMap == nil") return "" } - spew.Dump(box.EntryMap) - if (box.EntryMap[name] == nil) { - log.Println("gui.GetText() ERROR box.EntryMap[", name, "] == nil ") + spew.Dump(box.Window.EntryMap) + if (box.Window.EntryMap[name] == nil) { + log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ") return "" } - e := box.EntryMap[name] - log.Println("gui.GetText() box.EntryMap[", name, "] = ", e.UiEntry.Text()) + e := box.Window.EntryMap[name] + log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) log.Println("gui.GetText() END") return e.UiEntry.Text() } @@ -233,17 +233,17 @@ func SetText(box *GuiBox, name string, value string) error { if (box == nil) { return fmt.Errorf("gui.SetText() ERROR box == nil") } - if (box.EntryMap == nil) { - return fmt.Errorf("gui.SetText() ERROR b.Box.EntryMap == nil") + if (box.Window.EntryMap == nil) { + return fmt.Errorf("gui.SetText() ERROR b.Box.Window.EntryMap == nil") } - spew.Dump(box.EntryMap) - if (box.EntryMap[name] == nil) { - return fmt.Errorf("gui.SetText() ERROR box.EntryMap[", name, "] == nil ") + spew.Dump(box.Window.EntryMap) + if (box.Window.EntryMap[name] == nil) { + return fmt.Errorf("gui.SetText() ERROR box.Window.EntryMap[", name, "] == nil ") } - e := box.EntryMap[name] - log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text()) + e := box.Window.EntryMap[name] + log.Println("gui.SetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) e.UiEntry.SetText(value) - log.Println("gui.SetText() box.EntryMap[", name, "] = ", e.UiEntry.Text()) + log.Println("gui.SetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) log.Println("gui.SetText() END") return nil } @@ -295,7 +295,7 @@ func AddEntry(box *GuiBox, name string) *GuiEntry { box.UiBox.Append(ue, false) ge.UiEntry = ue - box.EntryMap[name] = ge + box.Window.EntryMap[name] = ge return ge } @@ -344,8 +344,8 @@ func AddGenericBox(gw *GuiWindow) *GuiBox { var gb *GuiBox gb = new(GuiBox) - gb.EntryMap = make(map[string]*GuiEntry) - gb.EntryMap["test"] = nil +// gb.EntryMap = make(map[string]*GuiEntry) +// gb.EntryMap["test"] = nil vbox := ui.NewVerticalBox() vbox.SetPadded(true) diff --git a/misc.go b/misc.go index 6a617e8..ed6a180 100644 --- a/misc.go +++ b/misc.go @@ -40,16 +40,17 @@ func AddMainTab(gw *GuiWindow) *GuiBox { log.Println("ShowMainTab() gw =", gw) log.Println("ShowMainTab() gw.UiTab =", gw.UiTab) - newWindow := new(GuiWindow) - newWindow.UiWindow = gw.UiWindow - Data.Windows = append(Data.Windows, newWindow) + window := InitGuiWindow(Data.Config, "MAIN", nil, gw.UiWindow, gw.UiTab) +// newWindow := new(GuiWindow) +// newWindow.UiWindow = gw.UiWindow +// Data.Windows = append(Data.Windows, newWindow) var box *GuiBox box = new(GuiBox) - box.Window = gw + box.Window = window - box.EntryMap = make(map[string]*GuiEntry) - box.EntryMap["test"] = nil +// box.EntryMap = make(map[string]*GuiEntry) +// box.EntryMap["test"] = nil hbox := ui.NewHorizontalBox() hbox.SetPadded(true) @@ -75,28 +76,49 @@ func ShowMainTabShowBox(gw *GuiWindow, box *GuiBox) { gw.UiTab.SetMargined(0, true) } -func StartNewWindow(c *pb.Config, bg bool, action string, maketab func(*GuiWindow) *GuiBox) { - log.Println("InitNewWindow() Create a new window") +func InitGuiWindow(c *pb.Config, action string, maketab func(*GuiWindow) *GuiBox, uiW *ui.Window, uiT *ui.Tab) *GuiWindow { + log.Println("InitGuiWindow() START") var newGuiWindow GuiWindow - newGuiWindow.Width = int(c.Width) - newGuiWindow.Height = int(c.Height) - newGuiWindow.Action = action - newGuiWindow.MakeWindow = maketab - newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.Width = int(c.Width) + newGuiWindow.Height = int(c.Height) + newGuiWindow.Action = action + newGuiWindow.MakeWindow = maketab + newGuiWindow.UiWindow = uiW + newGuiWindow.UiTab = uiT + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) + newGuiWindow.EntryMap["test"] = nil Data.Windows = append(Data.Windows, &newGuiWindow) - // make(newGuiWindow.BoxMap) + log.Println("InitGuiWindow() END *GuiWindow =", &newGuiWindow) + return &newGuiWindow +} + + +func StartNewWindow(c *pb.Config, bg bool, action string, maketab func(*GuiWindow) *GuiBox) { + log.Println("InitNewWindow() Create a new window") + window := InitGuiWindow(c, action, maketab, nil, nil) + /* + newGuiWindow.Width = int(c.Width) + newGuiWindow.Height = int(c.Height) + newGuiWindow.Action = action + newGuiWindow.MakeWindow = maketab + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) + newGuiWindow.EntryMap["test"] = nil + Data.Windows = append(Data.Windows, &newGuiWindow) + */ if (bg) { log.Println("ShowWindow() IN NEW GOROUTINE") go ui.Main(func() { - InitTabWindow(&newGuiWindow) + InitTabWindow(window) }) time.Sleep(2000 * time.Millisecond) } else { log.Println("ShowWindow() WAITING for ui.Main()") ui.Main(func() { - InitTabWindow(&newGuiWindow) + InitTabWindow(window) }) } } diff --git a/structs.go b/structs.go index 6370705..5be2162 100644 --- a/structs.go +++ b/structs.go @@ -119,9 +119,11 @@ 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 +// EntryMap map[string]*GuiEntry // andlabs/ui abstraction mapping UiBox *ui.Box From f85cb5c0f0c45d45bb0b49d7df673bf89a6d0692 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 14:16:00 -0700 Subject: [PATCH 14/15] compiles again Signed-off-by: Jeff Carr --- misc.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/misc.go b/misc.go index ed6a180..a685b81 100644 --- a/misc.go +++ b/misc.go @@ -14,18 +14,20 @@ import pb "git.wit.com/wit/witProtobuf" // THIS IS NOT CLEAN (almost?) -func ShowTab(gw *GuiWindow, tabname string, title string) { +func ShowTab(gw *GuiWindow, tabname string, title string) *GuiWindow { log.Println("ShowTab() gw =", gw) if (gw.UiTab == nil) { log.Println("ShowTab() gw.UiTab = nil THIS IS BAD") os.Exit(-1) } - gw.UiTab.Delete(0) + window := InitGuiWindow(Data.Config, tabname, gw.MakeWindow, gw.UiWindow, gw.UiTab) + window.UiTab.Delete(0) - abox := gw.MakeWindow(gw) - gw.BoxMap[tabname] = abox - gw.UiTab.InsertAt(title, 0, abox.UiBox) - gw.UiTab.SetMargined(0, true) + abox := window.MakeWindow(window) + window.BoxMap[tabname] = abox + window.UiTab.InsertAt(title, 0, abox.UiBox) + window.UiTab.SetMargined(0, true) + return window } func GuiInit() { From c9d46e19058068db9082d6f3554c2a2af0498851 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 15:38:47 -0700 Subject: [PATCH 15/15] builds and works again Signed-off-by: Jeff Carr --- gui.go | 21 +++++++++++++++------ misc.go | 40 +++++++++++++++++++++++----------------- structs.go | 2 +- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/gui.go b/gui.go index 4b44c54..49b9ab4 100644 --- a/gui.go +++ b/gui.go @@ -303,30 +303,39 @@ func AddEntry(box *GuiBox, name string) *GuiEntry { func HardHorizontalBreak(box *GuiBox) { log.Println("HardHorizontalBreak START") gw := box.Window - mainbox := gw.mainbox + mainbox := gw.BoxMap["MAIN"] + if (mainbox == nil) { + log.Println("HardHorizontalBreak ERROR MAIN box == nil") + return + } + uibox := mainbox.UiBox tmp := ui.NewHorizontalSeparator() - mainbox.Append(tmp, false) + uibox.Append(tmp, false) hbox := ui.NewVerticalBox() hbox.SetPadded(true) box.UiBox = hbox - mainbox.Append(hbox, true) + uibox.Append(hbox, true) log.Println("HardHorizontalBreak END") } func HardVerticalBreak(box *GuiBox) { log.Println("HardVerticalBreak START") gw := box.Window - mainbox := gw.mainbox + mainbox := gw.BoxMap["MAIN"] + if (mainbox == nil) { + log.Println("HardHorizontalBreak ERROR MAIN box == nil") + return + } tmp := ui.NewVerticalSeparator() - mainbox.Append(tmp, false) + mainbox.UiBox.Append(tmp, false) hbox := ui.NewVerticalBox() hbox.SetPadded(true) box.UiBox = hbox - mainbox.Append(hbox, false) + mainbox.UiBox.Append(hbox, false) log.Println("HardVerticalBreak END") } diff --git a/misc.go b/misc.go index a685b81..18d1f1a 100644 --- a/misc.go +++ b/misc.go @@ -43,26 +43,13 @@ func AddMainTab(gw *GuiWindow) *GuiBox { log.Println("ShowMainTab() gw.UiTab =", gw.UiTab) window := InitGuiWindow(Data.Config, "MAIN", nil, gw.UiWindow, gw.UiTab) -// newWindow := new(GuiWindow) -// newWindow.UiWindow = gw.UiWindow -// Data.Windows = append(Data.Windows, newWindow) - var box *GuiBox - box = new(GuiBox) - box.Window = window - -// box.EntryMap = make(map[string]*GuiEntry) -// box.EntryMap["test"] = nil - - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - box.UiBox = hbox - gw.mainbox = hbox + box := InitGuiBox(window, nil, ui.NewHorizontalBox(), "MAIN") if (Data.Debug) { log.Println("makeCloudInfoBox() add debugging buttons") addDebuggingButtons(box) - hbox.Append(ui.NewVerticalSeparator(), false) + box.UiBox.Append(ui.NewVerticalSeparator(), false) } // box := gw.MakeWindow(gw) @@ -73,11 +60,30 @@ func AddMainTab(gw *GuiWindow) *GuiBox { func ShowMainTabShowBox(gw *GuiWindow, box *GuiBox) { log.Println("gui.ShowMainTabShowBox() box =", box) // gw.UiTab.Delete(0) - gw.BoxMap["Box3"] = box - gw.UiTab.InsertAt("Main", 0, gw.mainbox) + gw.BoxMap["MAIN3"] = box + // gw.UiTab.InsertAt("Main", 0, box.UiBox) gw.UiTab.SetMargined(0, true) } +func InitGuiBox(gw *GuiWindow, box *GuiBox, uiBox *ui.Box, name string) *GuiBox { + log.Println("InitGuiBox() START") + var newGuiBox GuiBox + newGuiBox.UiBox = uiBox + newGuiBox.Window = gw + uiBox.SetPadded(true) + + if (box != nil) { + log.Println("InitGuiBox() APPEND NEW BOX TO OLD BOX") + box.UiBox.Append(uiBox, false) + } else { + log.Println("InitGuiBox() APPEND NEW BOX TO TAB") + gw.UiTab.Append(name, uiBox) + } + gw.BoxMap[name] = &newGuiBox + log.Println("InitGuiBox() END") + return &newGuiBox +} + func InitGuiWindow(c *pb.Config, action string, maketab func(*GuiWindow) *GuiBox, uiW *ui.Window, uiT *ui.Tab) *GuiWindow { log.Println("InitGuiWindow() START") var newGuiWindow GuiWindow diff --git a/structs.go b/structs.go index 5be2162..b036d83 100644 --- a/structs.go +++ b/structs.go @@ -82,7 +82,7 @@ type GuiWindow struct { Width int Height int - mainbox *ui.Box +// mainbox *ui.Box // the callback function to make the window contents MakeWindow func(*GuiWindow) *GuiBox