due to some sort of magic, two tables like this actually fucking worked without a segfault

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-06 13:50:10 -07:00
parent cbdf74a764
commit 85956b4020
2 changed files with 46 additions and 20 deletions

View File

@ -263,16 +263,16 @@ func setupUI() {
mainwin.SetChild(tab) mainwin.SetChild(tab)
mainwin.SetMargined(true) 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.SetMargined(0, true)
tab.Append("Hypervisors", makeButtonsPage(getPhysicalMachines("h"))) tab.Append("jcarrtest", makeJcarrtable())
tab.SetMargined(1, true) tab.SetMargined(1, true)
tab.Append("VMs", makeNumbersPage()) tab.Append("List examples", makeNumbersPage())
tab.SetMargined(2, true) tab.SetMargined(2, true)
tab.Append("Data Choosers", makeDataChoosersPage()) tab.Append("Choosers examples", makeDataChoosersPage())
tab.SetMargined(3, true) tab.SetMargined(3, true)
mainwin.Show() mainwin.Show()

View File

@ -5,6 +5,9 @@ package main
import "fmt" import "fmt"
import "log" import "log"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import "github.com/davecgh/go-spew/spew"
const rows int = 20
type vmRowData struct { type vmRowData struct {
hostname string hostname string
@ -16,23 +19,23 @@ type vmRowData struct {
} }
type modelHandler struct { type modelHandler struct {
row9Text string
yellowRow int yellowRow int
checkStates [15]int checkStates [rows]int
vms [15]vmRowData vms [rows]vmRowData
} }
func newModelHandler() *modelHandler { func newModelHandler() *modelHandler {
m := new(modelHandler) mh := new(modelHandler)
m.row9Text = "You can edit this one" mh.vms[8].hostname = "fire"
m.vms[8].hostname = "fire" mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test"
m.vms[9].hostname = "librem15.this.is.a.really.long.string.test" mh.yellowRow = -1
m.yellowRow = -1 log.Println("Called newModelhandler() with mh=", mh)
log.Println("Called newModelhandler() with m=", m) spew.Dump(mh)
return m return mh
} }
func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue { func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
// log.Println("ColumnTypes() with m=", m)
return []ui.TableValue{ return []ui.TableValue{
ui.TableString(""), // column 0 text ui.TableString(""), // column 0 text
ui.TableString(""), // column 1 text ui.TableString(""), // column 1 text
@ -47,12 +50,15 @@ func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
} }
func (mh *modelHandler) NumRows(m *ui.TableModel) int { func (mh *modelHandler) NumRows(m *ui.TableModel) int {
return 15 // log.Println("NumRows() with m=", m)
return rows
} }
var img [2]*ui.Image var img [2]*ui.Image
func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue { 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 { switch column {
case 0: case 0:
return ui.TableString(fmt.Sprintf("Row %d", row)) 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 return nil
case 3: case 3:
if row == mh.yellowRow { if row == mh.yellowRow {
return ui.TableColor{1, 1, 0, 1} return ui.TableColor{1, 1, 0, .1}
} }
if row == 3 { 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 { if row == 11 {
return ui.TableColor{0, 0.5, 1, 0.5} 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) { func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
log.Println("SetCallValue() START")
spew.Dump(m)
if column == 2 { if column == 2 {
mh.vms[row].hostname = string(value.(ui.TableString)) 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 if column == 7 { // checkboxes
mh.checkStates[row] = int(value.(ui.TableInt)) 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[0] = ui.NewImage(16, 16)
img[1] = ui.NewImage(16, 16) img[1] = ui.NewImage(16, 16)
@ -144,3 +156,17 @@ func maketable() *ui.Table {
return 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
}