From 85956b40202f0c25fdf2b56a5f1a1bbe8224a9f1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 6 May 2019 13:50:10 -0700 Subject: [PATCH] due to some sort of magic, two tables like this actually fucking worked without a segfault Signed-off-by: Jeff Carr --- main.go | 8 ++++---- table.go | 58 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 89a4232..4136605 100644 --- a/main.go +++ b/main.go @@ -263,16 +263,16 @@ func setupUI() { mainwin.SetChild(tab) mainwin.SetMargined(true) - tab.Append("v000185.testing.com.customers.wprod.wit.com", maketable()) + tab.Append("v000185.testing.com.customers.wprod.wit.com", makeDemotable()) tab.SetMargined(0, true) - tab.Append("Hypervisors", makeButtonsPage(getPhysicalMachines("h"))) + tab.Append("jcarrtest", makeJcarrtable()) tab.SetMargined(1, true) - tab.Append("VMs", makeNumbersPage()) + tab.Append("List examples", makeNumbersPage()) tab.SetMargined(2, true) - tab.Append("Data Choosers", makeDataChoosersPage()) + tab.Append("Choosers examples", makeDataChoosersPage()) tab.SetMargined(3, true) mainwin.Show() diff --git a/table.go b/table.go index 9f1c853..ca9ba13 100644 --- a/table.go +++ b/table.go @@ -5,6 +5,9 @@ package main import "fmt" import "log" import "github.com/andlabs/ui" +import "github.com/davecgh/go-spew/spew" + +const rows int = 20 type vmRowData struct { hostname string @@ -16,29 +19,29 @@ type vmRowData struct { } type modelHandler struct { - row9Text string yellowRow int - checkStates [15]int - vms [15]vmRowData + checkStates [rows]int + vms [rows]vmRowData } func newModelHandler() *modelHandler { - m := new(modelHandler) - m.row9Text = "You can edit this one" - m.vms[8].hostname = "fire" - m.vms[9].hostname = "librem15.this.is.a.really.long.string.test" - m.yellowRow = -1 - log.Println("Called newModelhandler() with m=", m) - return m + mh := new(modelHandler) + mh.vms[8].hostname = "fire" + mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test" + mh.yellowRow = -1 + log.Println("Called newModelhandler() with mh=", mh) + spew.Dump(mh) + return mh } func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue { + // log.Println("ColumnTypes() with m=", m) return []ui.TableValue{ ui.TableString(""), // column 0 text ui.TableString(""), // column 1 text ui.TableString(""), // column 2 text - ui.TableColor{}, // row background color - ui.TableColor{}, // column 1 text color + ui.TableColor{}, // row background color + ui.TableColor{}, // column 1 text color ui.TableImage{}, // column 1 image ui.TableString(""), // column 4 button text ui.TableInt(0), // column 3 checkbox state @@ -47,12 +50,15 @@ func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue { } func (mh *modelHandler) NumRows(m *ui.TableModel) int { - return 15 + // log.Println("NumRows() with m=", m) + return rows } var img [2]*ui.Image func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue { + // TODO: Figure out why this is being called 1000 times a second (10 times for each row & column) + // log.Println("CallValue() row=", row, "column=", column) switch column { case 0: return ui.TableString(fmt.Sprintf("Row %d", row)) @@ -83,10 +89,12 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal return nil case 3: if row == mh.yellowRow { - return ui.TableColor{1, 1, 0, 1} + return ui.TableColor{1, 1, 0, .1} } if row == 3 { - return ui.TableColor{1, 0, 0, 1} + // Red with .1 transparency + // R G B Trans + return ui.TableColor{1, 0, 0, .1} } if row == 11 { return ui.TableColor{0, 0.5, 1, 0.5} @@ -101,6 +109,8 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal } func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) { + log.Println("SetCallValue() START") + spew.Dump(m) if column == 2 { mh.vms[row].hostname = string(value.(ui.TableString)) } @@ -115,9 +125,11 @@ func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui if column == 7 { // checkboxes mh.checkStates[row] = int(value.(ui.TableInt)) } + log.Println("SetCallValue() END") + spew.Dump(m) } -func maketable() *ui.Table { +func makeDemotable() *ui.Table { img[0] = ui.NewImage(16, 16) img[1] = ui.NewImage(16, 16) @@ -144,3 +156,17 @@ func maketable() *ui.Table { return table } + +func makeJcarrtable() *ui.Table { + mh := newModelHandler() + model := ui.NewTableModel(mh) + + table := ui.NewTable( + &ui.TableParams{ + Model: model, + }) + + table.AppendTextColumn("hostname", 0, ui.TableModelColumnNeverEditable, nil) + + return table +}