god bless golang

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-08 02:53:42 -07:00
parent 59e459799e
commit f5be9dbd1e
2 changed files with 21 additions and 54 deletions

View File

@ -9,30 +9,9 @@ import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew"
type vmRowData struct {
hostname string
size int
IPv6 string
IPv4 string
memory int
disk int
}
var img [2]*ui.Image
// TODO: make this better
type cellTest struct {
/*
// part0 ui.TableColor // row background color
// part1 ui.TableString // column 0 text
// part2 ui.TableColor // column 0 text color
part3 ui.TableString // column 1 button text
part4 ui.TableString // column 2 text
part5 ui.TableColor // column 2 text color
part6 ui.TableString // column 3 text
part7 ui.TableImage // column 3 Image
part8 ui.TableColor // column 3 text color
*/
jwc [20]ui.TableValue
}
@ -44,7 +23,7 @@ type cellValue struct {
type modelHandler struct {
name string
rows int
bgcolorColumn int
rowBGcolor int
// new attempt
allRows []cellValue
@ -52,9 +31,9 @@ type modelHandler struct {
// old attempt that works
cellValues []cellTest
// These are the needed functions for libUI tables
funcColumnTypes func() []ui.TableValue
scanCellValue func(*modelHandler, int, int) ui.TableValue
generatedColumnTypes []ui.TableValue // attempt to generate this dynamically
// This is a needed function for libUI tables (maybe)
setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
}
@ -62,6 +41,13 @@ func initValues(mh *modelHandler) {
img[0] = ui.NewImage(16, 16)
img[1] = ui.NewImage(16, 16)
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString("test"))
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
for i := 0; i < mh.rows; i++ {
log.Println("i=",i)
@ -104,10 +90,11 @@ func newModelHandler(rows int) *modelHandler {
mh := new(modelHandler)
mh.rows = rows
mh.funcColumnTypes = standardColumnTypes
mh.scanCellValue = defaultCellValue
// These are the standard callback functions for libUI
mh.setCellValue = defaultSetCellValue
mh.bgcolorColumn = 0
mh.rowBGcolor = 0 // this is the weird exception. Just always have this as 0
mh.cellValues = make([]cellTest, mh.rows)
@ -118,19 +105,6 @@ func newModelHandler(rows int) *modelHandler {
return mh
}
func standardColumnTypes() []ui.TableValue {
var generated []ui.TableValue // attempt to generate this dynamically
generated = append(generated, ui.TableColor{})
generated = append(generated, ui.TableString(""))
generated = append(generated, ui.TableColor{})
generated = append(generated, ui.TableString("test"))
generated = append(generated, ui.TableString(""))
generated = append(generated, ui.TableColor{})
return generated
}
func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler, *ui.TableModel) {
mh := newModelHandler(rows)
mh.name = name
@ -139,7 +113,7 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler
table := ui.NewTable(
&ui.TableParams{
Model: model,
RowBackgroundColorModelColumn: mh.bgcolorColumn,
RowBackgroundColorModelColumn: mh.rowBGcolor,
})
table.AppendTextColumn(row1Name, 1, ui.TableModelColumnAlwaysEditable, nil)
@ -162,20 +136,13 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler
return table, mh, model
}
func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
return mh.cellValues[row].jwc[column]
}
func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) {
switch column {
case 0:
// mh.cellValues[row].part0 = ui.TableColor(value)
case 1:
mh.cellValues[row].jwc[1] = value
case 2:
// mh.cellValues[row].part2 = ui.TableColor(value)
case 3:
// mh.cellValues[row].part3 = ui.TableString(value)
log.Println("Button was pressed START", row, column)
}
log.Println("ui.TableValue=", value)

View File

@ -15,20 +15,20 @@ func (mh *modelHandler) NumRows(m *ui.TableModel) int {
// FYI: this routine seems to be called around 10 to 100 times a second for each table
func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
return mh.generatedColumnTypes
/*
if (mh.funcColumnTypes == nil) {
log.Println("ColumnTypes NOT DEFINED. This table wasn't setup correctly! mh.funcColmnTypes == nil")
os.Exit(-1)
}
return mh.funcColumnTypes()
*/
}
// TODO: Figure out why this is being called 1000 times a second (10 times for each row & column)
// Nevermind this TODO. Who gives a shit. This is a really smart way to treat the OS toolkits
func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
if (mh.scanCellValue == nil) {
log.Println("CellValue NOT DEFINED. This table wasn't setup correctly! mh.scanCellValue == nil")
os.Exit(-1)
}
return mh.scanCellValue(mh, row, column)
return mh.cellValues[row].jwc[column]
}
func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {