diff --git a/main.go b/main.go index 510a557..59f0e0e 100644 --- a/main.go +++ b/main.go @@ -75,14 +75,17 @@ func main() { log.Println("Sleep for 2 seconds, then try to add new tabs") time.Sleep(2 * 1000 * 1000 * 1000) + rows := 4 + for account, _ := range config.StringMap("cloud") { port := config.String("cloud." + account + ".port") proto := config.String("cloud." + account + ".proto") hostname := config.String("cloud." + account + ".hostname") fmt.Println(hostname, port, proto) - addTableTab(account, 4, hostname) - log.Println("Sleep for 30 seconds, then add next table") - time.Sleep(30 * 1000 * 1000 * 1000) + addTableTab(account, rows, hostname) + rows += 4 + log.Println("Sleep for 10 seconds, then add next table") + time.Sleep(10 * 1000 * 1000 * 1000) } for { diff --git a/table.go b/table.go index 49f8373..7da565a 100644 --- a/table.go +++ b/table.go @@ -21,16 +21,24 @@ type vmRowData struct { var img [2]*ui.Image // TODO: make this better -type jwcTest struct { - part0 ui.TableColor // row background color - part1 ui.TableString // column 0 text - part2 ui.TableColor // column 0 text color +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 +} + +type cellValue struct { + ref int // libUI reference int + value ui.TableValue // cell Value (TableString, TableColor or TableImage) } type modelHandler struct { @@ -38,7 +46,11 @@ type modelHandler struct { rows int bgcolorColumn int - cellValues []jwcTest + // new attempt + allRows []cellValue + + // old attempt that works + cellValues []cellTest // These are the needed functions for libUI tables funcColumnTypes func() []ui.TableValue @@ -55,37 +67,36 @@ func initValues(mh *modelHandler) { // alternate background of each row light and dark 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 { - 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 - 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 - 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 - 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 - 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 - 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 - 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 - mh.cellValues[i].part7 = ui.TableImage{img[0]} + mh.cellValues[i].jwc[7] = ui.TableImage{img[0]} // 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) } @@ -99,11 +110,11 @@ func newModelHandler(rows int) *modelHandler { mh.setCellValue = defaultSetCellValue mh.bgcolorColumn = 0 - mh.cellValues = make([]jwcTest, mh.rows) + mh.cellValues = make([]cellTest, mh.rows) initValues(mh) - log.Println("Called newModelhandler() with mh=", mh) + log.Println("Called newModelHandler() with mh=", mh) spew.Dump(mh) return mh } @@ -144,6 +155,7 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler ColorModelColumn: 5, }); + /* table.AppendImageTextColumn("testimagecolor", 6, 7, ui.TableModelColumnNeverEditable, &ui.TableTextColumnOptionalParams{ @@ -151,32 +163,11 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler }); */ - return table, mh, model } func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue { - switch 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)) + return mh.cellValues[row].jwc[column] } 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: // mh.cellValues[row].part0 = ui.TableColor(value) case 1: - mh.cellValues[row].part1 = value.(ui.TableString) + mh.cellValues[row].jwc[1] = value case 2: // mh.cellValues[row].part2 = ui.TableColor(value) case 3: