almost complete 'CLEAN'. yet more code refactoring
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
7e81dd00e0
commit
1274211f20
10
area.go
10
area.go
|
@ -7,16 +7,14 @@ import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
// THIS IS CLEAN
|
|
||||||
|
|
||||||
func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) {
|
func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) {
|
||||||
// make this button just to get the default font (but don't display the button)
|
// make this button just to get the default font (but don't display the button)
|
||||||
// There should be another way to do this (?)
|
// There should be another way to do this (?)
|
||||||
var newB *GuiButton
|
var newB *GuiButton
|
||||||
newB = CreateFontButton(gb, "AREA")
|
newB = CreateFontButton(gb, "AREA")
|
||||||
newB.Box = gb
|
newB.Box = gb
|
||||||
newB.custom = custom
|
newB.Custom = custom
|
||||||
newB.GW = gb.Window
|
// newB.GW = gb.Window
|
||||||
|
|
||||||
gw := gb.Window
|
gw := gb.Window
|
||||||
// initialize the GuiArea{}
|
// initialize the GuiArea{}
|
||||||
|
@ -77,8 +75,8 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||||
log.Println("GOT MOUSE UP")
|
log.Println("GOT MOUSE UP")
|
||||||
log.Println("GOT MOUSE UP ah.Button =", ah.Button)
|
log.Println("GOT MOUSE UP ah.Button =", ah.Button)
|
||||||
log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
|
log.Println("GOT MOUSE UP ah.Button.FB =", ah.Button.FB)
|
||||||
if (ah.Button.custom != nil) {
|
if (ah.Button.Custom != nil) {
|
||||||
ah.Button.custom(ah.Button)
|
ah.Button.Custom(ah.Button)
|
||||||
} else if (Data.MouseClick != nil) {
|
} else if (Data.MouseClick != nil) {
|
||||||
Data.MouseClick(ah.Button)
|
Data.MouseClick(ah.Button)
|
||||||
}
|
}
|
||||||
|
|
25
box.go
25
box.go
|
@ -8,8 +8,6 @@ import _ "github.com/andlabs/ui/winmanifest"
|
||||||
// import pb "git.wit.com/wit/witProtobuf"
|
// import pb "git.wit.com/wit/witProtobuf"
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
// THIS IS CLEAN
|
|
||||||
|
|
||||||
// add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX'
|
// 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["MAINBOX"], newbox, name) // use this to add a box off the main box
|
||||||
// add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX'
|
// add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX'
|
||||||
|
@ -150,26 +148,3 @@ func AddGenericBox(gw *GuiWindow, name string) *GuiBox {
|
||||||
|
|
||||||
return newbox
|
return newbox
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func CreateGenericBox(gw *GuiWindow, name string) *GuiBox {
|
|
||||||
log.Println("CreateAddVmBox() START name =", name)
|
|
||||||
|
|
||||||
var box *GuiBox
|
|
||||||
box = new(GuiBox)
|
|
||||||
|
|
||||||
vbox := ui.NewVerticalBox()
|
|
||||||
vbox.SetPadded(true)
|
|
||||||
box.UiBox = vbox
|
|
||||||
box.Window = gw
|
|
||||||
gw.BoxMap["ADD VM" + name] = box
|
|
||||||
|
|
||||||
hbox := ui.NewHorizontalBox()
|
|
||||||
hbox.SetPadded(true)
|
|
||||||
vbox.Append(hbox, false)
|
|
||||||
|
|
||||||
gw.UiTab.Append(name, vbox)
|
|
||||||
gw.UiTab.SetMargined(0, true)
|
|
||||||
return box
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
41
button.go
41
button.go
|
@ -1,16 +1,11 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import "log"
|
import "log"
|
||||||
|
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
import pb "git.wit.com/wit/witProtobuf"
|
import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
// THIS IS CLEAN
|
|
||||||
|
|
||||||
// This is the default mouse click handler
|
// This is the default mouse click handler
|
||||||
// Every mouse click that hasn't been assigned to
|
// Every mouse click that hasn't been assigned to
|
||||||
// something specific will fall into this routine
|
// something specific will fall into this routine
|
||||||
|
@ -32,23 +27,27 @@ func defaultButtonClick(button *ui.Button) {
|
||||||
}
|
}
|
||||||
if Data.AllButtons[key].B == button {
|
if Data.AllButtons[key].B == button {
|
||||||
log.Println("\tgui.defaultButtonClick() BUTTON MATCHED")
|
log.Println("\tgui.defaultButtonClick() BUTTON MATCHED")
|
||||||
log.Println("\tgui.defaultButtonClick() Data.AllButtons[key].Action =", Data.AllButtons[key].Action)
|
guiButtonClick(Data.AllButtons[key])
|
||||||
if Data.AllButtons[key].custom != nil {
|
return
|
||||||
log.Println("\tgui.defaultButtonClick() DOING CUSTOM FUNCTION")
|
}
|
||||||
Data.AllButtons[key].custom(Data.AllButtons[key])
|
}
|
||||||
|
log.Println("\tgui.defaultButtonClick() ERROR: BUTTON NOT FOUND")
|
||||||
|
if (Data.Debug) {
|
||||||
|
panic("gui.defaultButtonClick() ERROR: UNMAPPED ui.Button")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func guiButtonClick(button *GuiButton) {
|
||||||
|
log.Println("\tgui.guiButtonClick() button.Action =", button.Action)
|
||||||
|
if button.Custom != nil {
|
||||||
|
log.Println("\tgui.guiButtonClick() DOING CUSTOM FUNCTION")
|
||||||
|
button.Custom(button)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (Data.MouseClick != nil) {
|
if (Data.MouseClick != nil) {
|
||||||
Data.MouseClick(Data.AllButtons[key])
|
Data.MouseClick(button)
|
||||||
} else {
|
} else {
|
||||||
log.Println("\tgui.defaultButtonClick() IGNORING BUTTON. MouseClick() is nil")
|
log.Println("\tgui.guiButtonClick() IGNORING BUTTON. MouseClick() is nil")
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Println("\tgui.defaultButtonClick() BUTTON NOT FOUND")
|
|
||||||
if (Data.Debug) {
|
|
||||||
panic("gui.defaultButtonClick() SHOULD NOT HAVE UNMAPPED BUTTONS")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,12 +62,12 @@ func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, acti
|
||||||
log.Println("CreateButton() box.Window == nil")
|
log.Println("CreateButton() box.Window == nil")
|
||||||
panic("crap")
|
panic("crap")
|
||||||
}
|
}
|
||||||
newB.GW = box.Window
|
|
||||||
newB.Account = a
|
newB.Account = a
|
||||||
newB.VM = vm
|
newB.VM = vm
|
||||||
newB.Box = box
|
newB.Box = box
|
||||||
|
// newB.GW = box.Window
|
||||||
newB.Action = action
|
newB.Action = action
|
||||||
newB.custom = custom
|
newB.Custom = custom
|
||||||
Data.AllButtons = append(Data.AllButtons, newB)
|
Data.AllButtons = append(Data.AllButtons, newB)
|
||||||
|
|
||||||
box.UiBox.Append(newB.B, false)
|
box.UiBox.Append(newB.B, false)
|
||||||
|
@ -76,9 +75,9 @@ func CreateButton(box *GuiBox, a *pb.Account, vm *pb.Event_VM, name string, acti
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFontButton(box *GuiBox, action string) *GuiButton {
|
func CreateFontButton(box *GuiBox, action string) *GuiButton {
|
||||||
|
|
||||||
// create a 'fake' button entry for the mouse clicks
|
// create a 'fake' button entry for the mouse clicks
|
||||||
var newGB GuiButton
|
var newGB GuiButton
|
||||||
|
newGB.Name = "FONT"
|
||||||
newGB.Action = action
|
newGB.Action = action
|
||||||
newGB.FB = ui.NewFontButton()
|
newGB.FB = ui.NewFontButton()
|
||||||
newGB.Box = box
|
newGB.Box = box
|
||||||
|
|
1
debug.go
1
debug.go
|
@ -10,7 +10,6 @@ import "fmt"
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
// import pb "git.wit.com/wit/witProtobuf"
|
// import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
// THIS IS NOT CLEAN
|
|
||||||
//
|
//
|
||||||
// this watches the GUI primarily to process protobuf's
|
// this watches the GUI primarily to process protobuf's
|
||||||
// this is pointless or wrong but I use it for debugging
|
// this is pointless or wrong but I use it for debugging
|
||||||
|
|
3
entry.go
3
entry.go
|
@ -8,8 +8,9 @@ import _ "github.com/andlabs/ui/winmanifest"
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
// import pb "git.wit.com/wit/witProtobuf"
|
// import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
|
// THIS IS CLEAN (except the 'Memory' normalization example)
|
||||||
|
|
||||||
// THIS IS CLEAN
|
// functions for handling text entry boxes
|
||||||
|
|
||||||
func NewLabel(box *GuiBox, text string) {
|
func NewLabel(box *GuiBox, text string) {
|
||||||
box.UiBox.Append(ui.NewLabel(text), false)
|
box.UiBox.Append(ui.NewLabel(text), false)
|
||||||
|
|
48
gui.go
48
gui.go
|
@ -12,8 +12,6 @@ import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
// THIS IS NOT CLEAN (except the Memory normalization example)
|
|
||||||
|
|
||||||
const Xaxis = 0
|
const Xaxis = 0
|
||||||
const Yaxis = 1
|
const Yaxis = 1
|
||||||
|
|
||||||
|
@ -73,10 +71,12 @@ func InitTabWindow(gw *GuiWindow) {
|
||||||
gw.UiWindow.SetBorderless(false)
|
gw.UiWindow.SetBorderless(false)
|
||||||
|
|
||||||
// create a 'fake' button entry for the mouse clicks
|
// create a 'fake' button entry for the mouse clicks
|
||||||
|
/*
|
||||||
var newBM GuiButton
|
var newBM GuiButton
|
||||||
newBM.Action = "QUIT"
|
newBM.Action = "QUIT"
|
||||||
newBM.GW = gw
|
newBM.GW = gw
|
||||||
Data.AllButtons = append(Data.AllButtons, &newBM)
|
Data.AllButtons = append(Data.AllButtons, &newBM)
|
||||||
|
*/
|
||||||
|
|
||||||
gw.UiWindow.OnClosing(func(*ui.Window) bool {
|
gw.UiWindow.OnClosing(func(*ui.Window) bool {
|
||||||
log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw)
|
log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw)
|
||||||
|
@ -128,50 +128,6 @@ func normalizeInt(s string) string {
|
||||||
return 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
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) {
|
func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) {
|
||||||
ui.MsgBox(gw.UiWindow, msg1, msg2)
|
ui.MsgBox(gw.UiWindow, msg1, msg2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
import pb "git.wit.com/wit/witProtobuf"
|
import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
// THIS IS CLEAN
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// All GUI Data Structures and functions that are external
|
// All GUI Data Structures and functions that are external
|
||||||
// If you need cross platform support, these might only
|
// If you need cross platform support, these might only
|
||||||
|
@ -110,15 +108,16 @@ type GuiBox struct {
|
||||||
// the user clicks it. You could probably
|
// the user clicks it. You could probably
|
||||||
// call this 'GuiMouseClick'
|
// call this 'GuiMouseClick'
|
||||||
type GuiButton struct {
|
type GuiButton struct {
|
||||||
|
Name string // field for human readable name
|
||||||
Action string // what type of button
|
Action string // what type of button
|
||||||
Box *GuiBox // what box the button click was in
|
Box *GuiBox // what box the button click was in
|
||||||
GW *GuiWindow // what window the button click was in (redundant?)
|
// GW *GuiWindow // what window the button click was in (redundant?)
|
||||||
|
|
||||||
Account *pb.Account // associated with what account?
|
Account *pb.Account // associated with what account?
|
||||||
VM *pb.Event_VM // associated with which VM?
|
VM *pb.Event_VM // associated with which VM?
|
||||||
|
|
||||||
// a callback function for the main application
|
// a callback function for the main application
|
||||||
custom func (*GuiButton)
|
Custom func (*GuiButton)
|
||||||
|
|
||||||
// andlabs/ui abstraction mapping
|
// andlabs/ui abstraction mapping
|
||||||
B *ui.Button
|
B *ui.Button
|
||||||
|
|
2
table.go
2
table.go
|
@ -9,8 +9,6 @@ import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
// THIS IS CLEAN
|
|
||||||
|
|
||||||
func initRowBTcolor(mh *TableData, intBG int, cell TableColumnData) {
|
func initRowBTcolor(mh *TableData, intBG int, cell TableColumnData) {
|
||||||
humanInt := cell.Index
|
humanInt := cell.Index
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ import "runtime"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
// THIS IS CLEAN
|
|
||||||
|
|
||||||
func (mh *TableData) NumRows(m *ui.TableModel) int {
|
func (mh *TableData) NumRows(m *ui.TableModel) int {
|
||||||
if (Data.Debug) {
|
if (Data.Debug) {
|
||||||
log.Println("NumRows = mh.RowCount = ", mh.RowCount, "(last Row & Column =", mh.lastRow, mh.lastColumn, ")")
|
log.Println("NumRows = mh.RowCount = ", mh.RowCount, "(last Row & Column =", mh.lastRow, mh.lastColumn, ")")
|
||||||
|
@ -110,11 +108,10 @@ func defaultSetCellValue(mh *TableData, row int, column int) {
|
||||||
|
|
||||||
button := mh.Rows[row].HumanData[humanID].Button
|
button := mh.Rows[row].HumanData[humanID].Button
|
||||||
if (button != nil) {
|
if (button != nil) {
|
||||||
if (Data.MouseClick != nil) {
|
guiButtonClick(button)
|
||||||
Data.MouseClick(button)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE")
|
||||||
if (Data.Debug) {
|
if (Data.Debug) {
|
||||||
panic("defaultSetCellValue() GOT AN UNKNOWN BUTTON CLICK IN TABLE")
|
panic("defaultSetCellValue() GOT AN UNKNOWN BUTTON CLICK IN TABLE")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue