From bf9b5bd49d65dae7868d74d5f972510c2585ff7a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 01:20:20 -0700 Subject: more control panel code removal Signed-off-by: Jeff Carr --- structs.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'structs.go') 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 } -- cgit v1.2.3 From 1e51d3252b032fd60566834e17973c134e4ad18c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 11:45:15 -0700 Subject: 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 (limited to 'structs.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 + + 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 +} - abox := makeCloudInfoBox(gw) - gw.BoxMap["Box3"] = abox - gw.UiTab.InsertAt("Main", 0, abox.UiBox) +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 -- cgit v1.2.3 From c5f9c6d96f1ce960fa08ab2c77b348a5bcdf03ea Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 12:43:40 -0700 Subject: 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(-) (limited to 'structs.go') 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 -- cgit v1.2.3 From 7d72ca3561fefd4c89f553448810eee545a47880 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 13:41:45 -0700 Subject: 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(-) (limited to 'structs.go') 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 -- cgit v1.2.3 From a6886866a9c70b9dae58e5811c68e3824ce40a43 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 14:10:12 -0700 Subject: 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(-) (limited to 'structs.go') 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 -- cgit v1.2.3 From 9db539747b33632e758083b6b72e5249f3edeb1e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 1 Jun 2019 15:38:47 -0700 Subject: 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(-) (limited to 'structs.go') 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 -- cgit v1.2.3