add some more tests

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-08 08:11:25 -07:00
parent 63fd4607dc
commit a23144e9a8
1 changed files with 47 additions and 40 deletions

View File

@ -39,15 +39,10 @@ type modelHandler struct {
libUIevent func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
}
func initValues(mh *modelHandler) {
func initBTcolor(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.rowcount; i++ {
@ -61,7 +56,17 @@ func initValues(mh *modelHandler) {
mh.rows[i].cells[0].value = ui.TableColor{0.1, 0.1, 0.1, .1}
mh.rows[i].cells[0].name = "BG"
}
}
}
func initValues(mh *modelHandler) {
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.rowcount; i++ {
// text for Column 0
mh.rows[i].cells[1].value = ui.TableString(fmt.Sprintf("fun %d", i))
mh.rows[i].cells[1].name = "EDIT"
@ -73,32 +78,20 @@ func initValues(mh *modelHandler) {
// set the button text for Column 1
mh.rows[i].cells[3].value = ui.TableString(fmt.Sprintf("awesome %d", i))
mh.rows[i].cells[3].name = "BUTTON"
/*
// text for Column 2
mh.rows[i].cells[4].value = ui.TableString(fmt.Sprintf("color %d", i))
mh.rows[i].cells[4].name = "EDIT"
// text color for Column 2
mh.rows[i].cells[5].value = ui.TableColor{0.9, 0, 0, 1}
mh.rows[i].cells[5].name = "COLOR"
// text for Column 3
mh.rows[i].cells[6].value = ui.TableString(fmt.Sprintf("imgcolor %d", i))
// image for Column 3
mh.rows[i].cells[7].value = ui.TableImage{img[0]}
mh.rows[i].cells[7].name = "IMAGE"
// text color for Column 3
mh.rows[i].cells[8].value = ui.TableColor{0.9, 0, 0, 1}
mh.rows[i].cells[8].name = "COLOR"
*/
}
}
func initColorColumn(mh *modelHandler, stringID int, colorID int, junk string, color ui.TableColor) {
func initButtonColumn(mh *modelHandler, buttonID int, junk string) {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
for i := 0; i < mh.rowcount; i++ {
// set the button text for Column ?
mh.rows[i].cells[buttonID].value = ui.TableString(fmt.Sprintf("%s %d", junk, i))
mh.rows[i].cells[buttonID].name = "BUTTON"
}
}
func initTextColorColumn(mh *modelHandler, stringID int, colorID int, junk string, color ui.TableColor) {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
@ -113,9 +106,18 @@ func initColorColumn(mh *modelHandler, stringID int, colorID int, junk string, c
mh.rows[i].cells[colorID].value = color
mh.rows[i].cells[colorID].name = "COLOR"
}
}
// this causes a segfault?
// mh.rowcount = mh.rowcount + 2
func initTextColumn(mh *modelHandler, stringID int, junk string) {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
for i := 0; i < mh.rowcount; i++ {
log.Println("i=",i)
// text for Column ?
mh.rows[i].cells[stringID].value = ui.TableString(fmt.Sprintf("%s %d", junk, i))
mh.rows[i].cells[stringID].name = "EDIT"
}
}
func newModelHandler(rowcount int) *modelHandler {
@ -129,26 +131,29 @@ func newModelHandler(rowcount int) *modelHandler {
mh.rows = make([]rowData, mh.rowcount)
initBTcolor(mh)
initValues(mh)
color := ui.TableColor{0.0, 0.9, 0.4, 1}
initColorColumn(mh, 4, 5, "jwc45blah", color)
color = ui.TableColor{0.3, 0.1, 0.9, 1}
initColorColumn(mh, 6, 7, "jwc67blah", color)
initTextColorColumn(mh, 4, 5, "jwc45blah", ui.TableColor{0.0, 0.9, 0.4, 1})
initTextColorColumn(mh, 6, 7, "jwc67blah", ui.TableColor{0.3, 0.1, 0.9, 1})
initTextColumn(mh, 8, "jwc8blah")
// initButtonColumn(mh, 9, "but9ton")
log.Println("Called newModelHandler() with mh=", mh)
spew.Dump(mh)
return mh
}
func appendColorColumn(mh *modelHandler, table *ui.Table, stringID int, colorID int, columnName string) {
func appendTextColorColumn(mh *modelHandler, table *ui.Table, stringID int, colorID int, columnName string) {
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable,
&ui.TableTextColumnOptionalParams{
ColorModelColumn: colorID,
});
}
func appendTextColumn(mh *modelHandler, table *ui.Table, stringID int, columnName string) {
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable, nil)
}
func makeTable(name string, rowcount int, row1Name string) (*ui.Table, *modelHandler, *ui.TableModel) {
mh := newModelHandler(rowcount)
mh.name = name
@ -163,8 +168,10 @@ func makeTable(name string, rowcount int, row1Name string) (*ui.Table, *modelHan
table.AppendTextColumn(row1Name, 1, ui.TableModelColumnAlwaysEditable, nil)
table.AppendButtonColumn("Details", 3, ui.TableModelColumnAlwaysEditable)
appendColorColumn(mh, table, 4, 5, "testcolor")
appendColorColumn(mh, table, 6, 7, "appendTest")
appendTextColorColumn(mh, table, 4, 5, "testcolor")
appendTextColorColumn(mh, table, 6, 7, "appendTest")
appendTextColumn(mh, table, 8, "jwc8col")
// table.AppendButtonColumn("button9", 9, ui.TableModelColumnAlwaysEditable)
return table, mh, model
}