159 lines
5.1 KiB
Go
159 lines
5.1 KiB
Go
// based off andlabs/ui/examples/table.go
|
|
|
|
package main
|
|
|
|
import "fmt"
|
|
import "log"
|
|
import "github.com/andlabs/ui"
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
var img [2]*ui.Image
|
|
|
|
type cellData struct {
|
|
index int
|
|
value ui.TableValue
|
|
name string // what type of cell is this?
|
|
event func() // what function to call if there is an event on this
|
|
}
|
|
|
|
// hmm. will this stand the test of time?
|
|
type rowData struct {
|
|
name string // what kind of row is this?
|
|
status string // status of the row?
|
|
/*
|
|
// These may or may not be implementable
|
|
click func() // what function to call if the user clicks on it
|
|
doubleclick func() // what function to call if the user double clicks on it
|
|
*/
|
|
cells [20]cellData
|
|
}
|
|
|
|
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) {
|
|
img[0] = ui.NewImage(16, 16)
|
|
img[1] = ui.NewImage(16, 16)
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
|
|
|
for i := 0; i < mh.rowcount; i++ {
|
|
log.Println("i=",i)
|
|
|
|
// 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"
|
|
} else {
|
|
mh.rows[i].cells[0].value = ui.TableColor{0.1, 0.1, 0.1, .1}
|
|
mh.rows[i].cells[0].name = "BG"
|
|
}
|
|
}
|
|
}
|
|
|
|
func initButtonColumn(mh *tableData, 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 *tableData, stringID int, colorID int, junk string, color ui.TableColor) {
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
|
|
|
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"
|
|
|
|
// text color for Column ?
|
|
mh.rows[i].cells[colorID].value = color
|
|
mh.rows[i].cells[colorID].name = "COLOR"
|
|
}
|
|
}
|
|
|
|
func initTextColumn(mh *tableData, 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 appendTextColorColumn(mh *tableData, table *ui.Table, stringID int, colorID int, columnName string) {
|
|
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable,
|
|
&ui.TableTextColumnOptionalParams{
|
|
ColorModelColumn: colorID,
|
|
});
|
|
}
|
|
|
|
func appendTextColumn(mh *tableData, table *ui.Table, stringID int, columnName string) {
|
|
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
|
|
}
|
|
if (mh.rows[row].cells[column].name == "BUTTON") {
|
|
log.Println("FOUND THE BUTTON!!!!!!! Button was pressed START", row, column)
|
|
}
|
|
return
|
|
}
|