merge code to create a table into gui.go

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-08 12:00:49 -07:00
parent 37fefba92f
commit c5e590985e
2 changed files with 37 additions and 50 deletions

35
gui.go
View File

@ -239,9 +239,38 @@ func setupUI() {
mainwin.Show()
}
func addTableTab(name string, rows int, row1name string) {
table, mh, model := makeTable(name, rows, row1name)
log.Println(table, mh, model)
func addTableTab(name string, rowcount int, row1name string) {
mh := new(tableData)
mh.rowcount = rowcount
mh.rows = make([]rowData, mh.rowcount)
// This is the standard callback function from libUI when the user does something
mh.libUIevent = defaultSetCellValue
tmpBTindex := 0
initBTcolor (mh, 0)
initTextColorColumn(mh, 1, 2, "really fun", ui.TableColor{0.9, 0, 0, 1})
initButtonColumn (mh, 3, "but3ton")
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")
model := ui.NewTableModel(mh)
table := ui.NewTable(
&ui.TableParams{
Model: model,
RowBackgroundColorModelColumn: tmpBTindex,
})
appendTextColumn (mh, table, 1, "jwc1col")
table.AppendButtonColumn("button3", 3, ui.TableModelColumnAlwaysEditable)
appendTextColorColumn (mh, table, 4, 5, "testcolor")
appendTextColorColumn (mh, table, 6, 7, "appendTest")
appendTextColumn (mh, table, 8, "jwc8col")
table.AppendButtonColumn("button9", 9, ui.TableModelColumnAlwaysEditable)
tabcount += 1
maintab.Append(name, table)

View File

@ -29,15 +29,13 @@ type rowData struct {
}
type tableData struct {
name string // I forgot where this goes
rowcount int // This is the number of 'rows' which really means data elements not what the human sees
rowBGcolor int // This is what index stores the row BG color (should always be 0)
rows []rowData // This is all the table data by row
generatedColumnTypes []ui.TableValue // generate this dynamically
libUIevent func(*tableData, *ui.TableModel, int, int, ui.TableValue)
}
func initBTcolor(mh *tableData) {
func initBTcolor(mh *tableData, intBG int) {
img[0] = ui.NewImage(16, 16)
img[1] = ui.NewImage(16, 16)
@ -48,11 +46,11 @@ func initBTcolor(mh *tableData) {
// alternate background of each row light and dark
if (i % 2) == 1 {
mh.rows[i].cells[0].value = ui.TableColor{0.5, 0.5, 0.5, .7}
mh.rows[i].cells[0].name = "BG"
mh.rows[i].cells[intBG].value = ui.TableColor{0.5, 0.5, 0.5, .7}
mh.rows[i].cells[intBG].name = "BG"
} else {
mh.rows[i].cells[0].value = ui.TableColor{0.1, 0.1, 0.1, .1}
mh.rows[i].cells[0].name = "BG"
mh.rows[i].cells[intBG].value = ui.TableColor{0.1, 0.1, 0.1, .1}
mh.rows[i].cells[intBG].name = "BG"
}
}
}
@ -107,46 +105,6 @@ func appendTextColumn(mh *tableData, table *ui.Table, stringID int, columnName s
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable, nil)
}
func makeTable(name string, rowcount int, row1Name string) (*ui.Table, *tableData, *ui.TableModel) {
mh := new(tableData)
mh.rowBGcolor = 0 // this is the weird exception. Just always have this as 0
mh.rowcount = rowcount
// This is the standard callback function from libUI when the user does something
mh.libUIevent = defaultSetCellValue
mh.rows = make([]rowData, mh.rowcount)
initBTcolor(mh)
initTextColorColumn(mh, 1, 2, "really fun", ui.TableColor{0.9, 0, 0, 1})
initButtonColumn (mh, 3, "but3ton")
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")
mh.name = name
model := ui.NewTableModel(mh)
table := ui.NewTable(
&ui.TableParams{
Model: model,
RowBackgroundColorModelColumn: mh.rowBGcolor,
})
table.AppendTextColumn (row1Name, 1, ui.TableModelColumnAlwaysEditable, nil)
table.AppendButtonColumn("Details", 3, ui.TableModelColumnAlwaysEditable)
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
}
func defaultSetCellValue(mh *tableData, m *ui.TableModel, row, column int, value ui.TableValue) {
if (mh.rows[row].cells[column].name == "EDIT") {
mh.rows[row].cells[column].value = value