ah. maybe it's possible to completely abstract this all away

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-08 01:49:09 -07:00
parent fb95e77b50
commit b84d38e33b
2 changed files with 38 additions and 44 deletions

View File

@ -75,14 +75,17 @@ func main() {
log.Println("Sleep for 2 seconds, then try to add new tabs") log.Println("Sleep for 2 seconds, then try to add new tabs")
time.Sleep(2 * 1000 * 1000 * 1000) time.Sleep(2 * 1000 * 1000 * 1000)
rows := 4
for account, _ := range config.StringMap("cloud") { for account, _ := range config.StringMap("cloud") {
port := config.String("cloud." + account + ".port") port := config.String("cloud." + account + ".port")
proto := config.String("cloud." + account + ".proto") proto := config.String("cloud." + account + ".proto")
hostname := config.String("cloud." + account + ".hostname") hostname := config.String("cloud." + account + ".hostname")
fmt.Println(hostname, port, proto) fmt.Println(hostname, port, proto)
addTableTab(account, 4, hostname) addTableTab(account, rows, hostname)
log.Println("Sleep for 30 seconds, then add next table") rows += 4
time.Sleep(30 * 1000 * 1000 * 1000) log.Println("Sleep for 10 seconds, then add next table")
time.Sleep(10 * 1000 * 1000 * 1000)
} }
for { for {

View File

@ -21,16 +21,24 @@ type vmRowData struct {
var img [2]*ui.Image var img [2]*ui.Image
// TODO: make this better // TODO: make this better
type jwcTest struct { type cellTest struct {
part0 ui.TableColor // row background color /*
part1 ui.TableString // column 0 text // part0 ui.TableColor // row background color
part2 ui.TableColor // column 0 text color // part1 ui.TableString // column 0 text
// part2 ui.TableColor // column 0 text color
part3 ui.TableString // column 1 button text part3 ui.TableString // column 1 button text
part4 ui.TableString // column 2 text part4 ui.TableString // column 2 text
part5 ui.TableColor // column 2 text color part5 ui.TableColor // column 2 text color
part6 ui.TableString // column 3 text part6 ui.TableString // column 3 text
part7 ui.TableImage // column 3 Image part7 ui.TableImage // column 3 Image
part8 ui.TableColor // column 3 text color part8 ui.TableColor // column 3 text color
*/
jwc [20]ui.TableValue
}
type cellValue struct {
ref int // libUI reference int
value ui.TableValue // cell Value (TableString, TableColor or TableImage)
} }
type modelHandler struct { type modelHandler struct {
@ -38,7 +46,11 @@ type modelHandler struct {
rows int rows int
bgcolorColumn int bgcolorColumn int
cellValues []jwcTest // new attempt
allRows []cellValue
// old attempt that works
cellValues []cellTest
// These are the needed functions for libUI tables // These are the needed functions for libUI tables
funcColumnTypes func() []ui.TableValue funcColumnTypes func() []ui.TableValue
@ -55,37 +67,36 @@ func initValues(mh *modelHandler) {
// alternate background of each row light and dark // alternate background of each row light and dark
if (i % 2) == 1 { if (i % 2) == 1 {
mh.cellValues[i].part0 = ui.TableColor{0.5, 0.5, 0.5, .7} mh.cellValues[i].jwc[0] = ui.TableColor{0.5, 0.5, 0.5, .7}
} else { } else {
mh.cellValues[i].part0 = ui.TableColor{0.1, 0.1, 0.1, .1} mh.cellValues[i].jwc[0] = ui.TableColor{0.1, 0.1, 0.1, .1}
} }
// text for Column 0 // text for Column 0
mh.cellValues[i].part1 = ui.TableString(fmt.Sprintf("fun %d", i)) mh.cellValues[i].jwc[1] = ui.TableString(fmt.Sprintf("fun %d", i))
// text color for Column 0 // text color for Column 0
mh.cellValues[i].part2 = ui.TableColor{0.9, 0, 0, 1} mh.cellValues[i].jwc[2] = ui.TableColor{0.9, 0, 0, 1}
// set the button text for Column 1 // set the button text for Column 1
mh.cellValues[i].part3 = ui.TableString(fmt.Sprintf("awesome %d", i)) mh.cellValues[i].jwc[3] = ui.TableString(fmt.Sprintf("awesome %d", i))
// text for Column 2 // text for Column 2
mh.cellValues[i].part4 = ui.TableString(fmt.Sprintf("color %d", i)) mh.cellValues[i].jwc[4] = ui.TableString(fmt.Sprintf("color %d", i))
// text color for Column 2 // text color for Column 2
mh.cellValues[i].part5 = ui.TableColor{0.9, 0, 0, 1} mh.cellValues[i].jwc[5] = ui.TableColor{0.9, 0, 0, 1}
// text for Column 3 // text for Column 3
mh.cellValues[i].part6 = ui.TableString(fmt.Sprintf("imgcolor %d", i)) mh.cellValues[i].jwc[6] = ui.TableString(fmt.Sprintf("imgcolor %d", i))
// image for Column 3 // image for Column 3
mh.cellValues[i].part7 = ui.TableImage{img[0]} mh.cellValues[i].jwc[7] = ui.TableImage{img[0]}
// text color for Column 3 // text color for Column 3
mh.cellValues[i].part8 = ui.TableColor{0.9, 0, 0, 1} mh.cellValues[i].jwc[8] = ui.TableColor{0.9, 0, 0, 1}
} }
// os.Exit(-1) // os.Exit(-1)
} }
@ -99,11 +110,11 @@ func newModelHandler(rows int) *modelHandler {
mh.setCellValue = defaultSetCellValue mh.setCellValue = defaultSetCellValue
mh.bgcolorColumn = 0 mh.bgcolorColumn = 0
mh.cellValues = make([]jwcTest, mh.rows) mh.cellValues = make([]cellTest, mh.rows)
initValues(mh) initValues(mh)
log.Println("Called newModelhandler() with mh=", mh) log.Println("Called newModelHandler() with mh=", mh)
spew.Dump(mh) spew.Dump(mh)
return mh return mh
} }
@ -144,6 +155,7 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler
ColorModelColumn: 5, ColorModelColumn: 5,
}); });
/* /*
table.AppendImageTextColumn("testimagecolor", 6, 7, ui.TableModelColumnNeverEditable, table.AppendImageTextColumn("testimagecolor", 6, 7, ui.TableModelColumnNeverEditable,
&ui.TableTextColumnOptionalParams{ &ui.TableTextColumnOptionalParams{
@ -151,32 +163,11 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler
}); });
*/ */
return table, mh, model return table, mh, model
} }
func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue { func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
switch column { return mh.cellValues[row].jwc[column]
case 0:
return mh.cellValues[row].part0
case 1:
return mh.cellValues[row].part1
case 2:
return mh.cellValues[row].part2
case 3:
return mh.cellValues[row].part3
case 4:
return mh.cellValues[row].part4
case 5:
return mh.cellValues[row].part5
case 6:
return mh.cellValues[row].part6
case 7:
return ui.TableImage{img[1]}
case 8:
return mh.cellValues[row].part8
}
return ui.TableString(fmt.Sprintf("jcarrbad %d", row))
} }
func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) { func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) {
@ -184,7 +175,7 @@ func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, va
case 0: case 0:
// mh.cellValues[row].part0 = ui.TableColor(value) // mh.cellValues[row].part0 = ui.TableColor(value)
case 1: case 1:
mh.cellValues[row].part1 = value.(ui.TableString) mh.cellValues[row].jwc[1] = value
case 2: case 2:
// mh.cellValues[row].part2 = ui.TableColor(value) // mh.cellValues[row].part2 = ui.TableColor(value)
case 3: case 3: