From 5536e659aefedc0f8fba3d7368b743ade3c39c37 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 2 Jun 2019 19:49:17 -0700 Subject: [PATCH] see if an interface can store the outside values also finally fixed the splash area logic Signed-off-by: Jeff Carr --- area.go | 20 +++++++++++++++----- box.go | 3 --- button.go | 21 +++++++++++++++++++++ entry.go | 1 - gui.go | 23 ++++++----------------- structs.go | 17 +++++------------ table.go | 1 - 7 files changed, 47 insertions(+), 39 deletions(-) diff --git a/area.go b/area.go index 49e4b20..aee0803 100644 --- a/area.go +++ b/area.go @@ -14,7 +14,6 @@ func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiB newB = CreateFontButton(gb, "AREA") newB.Box = gb newB.Custom = custom -// newB.GW = gb.Window gw := gb.Window // initialize the GuiArea{} @@ -116,10 +115,21 @@ func ShowTextBox(gw *GuiWindow, newText *ui.AttributedString, custom func(*GuiBu } log.Println("ShowTextBox() START gw =", gw) - box := InitGuiBox(gw, nil, ui.NewVerticalBox(), "SplashArea3") + var newbox *GuiBox + newbox = new(GuiBox) + newbox.Window = gw + newbox.Name = "Hbox1" + hbox := ui.NewVerticalBox() + newbox.UiBox = hbox - makeGenericArea(box, newText, custom) - box.UiBox.Append(box.Window.Area.UiArea, true) + // TODO: allow padded & axis here + hbox.SetPadded(true) - return box + add(gw.BoxMap["MAINBOX"], newbox) + // box := InitGuiBox(gw, nil, ui.NewVerticalBox(), "SplashArea3") + + makeGenericArea(newbox, newText, custom) + newbox.UiBox.Append(newbox.Window.Area.UiArea, true) + + return newbox } diff --git a/box.go b/box.go index 9cffdf5..0164b95 100644 --- a/box.go +++ b/box.go @@ -5,9 +5,6 @@ import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -// import pb "git.wit.com/wit/witProtobuf" -// import "github.com/davecgh/go-spew/spew" - // add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX' // add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box // add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX' diff --git a/button.go b/button.go index 087d768..0e23991 100644 --- a/button.go +++ b/button.go @@ -73,6 +73,27 @@ func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, acti return newB } +func NewCreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { + newUiB := ui.NewButton(name) + newUiB.OnClicked(defaultButtonClick) + + var newB *GuiButton + newB = new(GuiButton) + newB.B = newUiB + if (box.Window == nil) { + log.Println("CreateButton() box.Window == nil") + panic("crap") + } + newB.Box = box + newB.Custom = custom + newB.Values = values + + Data.AllButtons = append(Data.AllButtons, newB) + + box.UiBox.Append(newB.B, false) + return newB +} + func CreateFontButton(box *GuiBox, action string) *GuiButton { // create a 'fake' button entry for the mouse clicks var newGB GuiButton diff --git a/entry.go b/entry.go index 550896b..75c7f28 100644 --- a/entry.go +++ b/entry.go @@ -6,7 +6,6 @@ import "fmt" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" import "github.com/davecgh/go-spew/spew" -// import pb "git.wit.com/wit/witProtobuf" // THIS IS CLEAN (except the 'Memory' normalization example) diff --git a/gui.go b/gui.go index f48a3f4..84f5c21 100644 --- a/gui.go +++ b/gui.go @@ -3,25 +3,20 @@ package gui import "log" import "time" import "regexp" -// import "os" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -// import "github.com/davecgh/go-spew/spew" - const Xaxis = 0 const Yaxis = 1 func GuiInit() { ui.OnShouldQuit(func() bool { - // mouseClick(&newBM) ui.Quit() return true }) } -// func InitGuiWindow(c *pb.Config, action string, maketab func(*GuiWindow) *GuiBox, uiW *ui.Window, uiT *ui.Tab) *GuiWindow { func InitGuiWindow(action string, gw *GuiWindow) *GuiWindow { log.Println("InitGuiWindow() START") var newGuiWindow GuiWindow @@ -45,6 +40,7 @@ func StartNewWindow(bg bool, action string, callback func(*GuiWindow) *GuiBox) { log.Println("StartNewWindow() Create a new window") var junk GuiWindow junk.MakeWindow = callback + junk.Action = action window := InitGuiWindow(action, &junk) if (bg) { log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") @@ -63,19 +59,11 @@ func StartNewWindow(bg bool, action string, callback func(*GuiWindow) *GuiBox) { } func InitTabWindow(gw *GuiWindow) { - log.Println("InitTabWindow() THIS WINDOW IS NOT YET SHOWN") + log.Println("InitTabWindow() START. THIS WINDOW IS NOT YET SHOWN") - gw.UiWindow = ui.NewWindow("", int(gw.Width), int(gw.Height), true) + gw.UiWindow = ui.NewWindow("InitTabWindow()", 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.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) ui.Quit() @@ -86,9 +74,10 @@ func InitTabWindow(gw *GuiWindow) { gw.UiWindow.SetChild(gw.UiTab) gw.UiWindow.SetMargined(true) - log.Println("InitTabWindow() gw =", gw) - gw.MakeWindow(gw) + box := gw.MakeWindow(gw) + log.Println("InitTabWindow() END box =", box) + log.Println("InitTabWindow() END gw =", gw) gw.UiWindow.Show() } diff --git a/structs.go b/structs.go index d57e8a0..b2d55f3 100644 --- a/structs.go +++ b/structs.go @@ -95,14 +95,15 @@ type GuiBox struct { // call this 'GuiMouseClick' type GuiButton struct { Name string // field for human readable name - Action string // what type of button Box *GuiBox // what box the button click was in - Account *pb.Account // associated with what account? - VM *pb.Event_VM // associated with which VM? - // a callback function for the main application Custom func (*GuiButton) + Values interface {} + + Action string // what type of button + Account *pb.Account // associated with what account? + VM *pb.Event_VM // associated with which VM? // andlabs/ui abstraction mapping B *ui.Button @@ -119,9 +120,6 @@ type GuiEntry struct { B *GuiButton Box *GuiBox - Account *pb.Account - VM *pb.Event_VM - // andlabs/ui abstraction mapping UiEntry *ui.Entry } @@ -170,7 +168,6 @@ type TableData struct { Cells [20]CellData Human [20]HumanMap - Account *pb.Account // what account this table is for Box *GuiBox lastRow int @@ -198,7 +195,6 @@ type HumanCellData struct { TextID int Color color.RGBA ColorID int - VM *pb.Event_VM Button *GuiButton } @@ -232,9 +228,6 @@ type RowData struct { doubleclick func() // what function to call if the user double clicks on it */ HumanData [20]HumanCellData - - // The VM from the protobuf - VM *pb.Event_VM } // diff --git a/table.go b/table.go index d3e5f20..b4e73c1 100644 --- a/table.go +++ b/table.go @@ -97,7 +97,6 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } } -// func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData, account *pb.Account) *TableData { func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { mh := new(TableData)