2019-05-08 15:04:18 -05:00
|
|
|
// based off andlabs/ui/examples/table.go
|
|
|
|
|
2019-05-08 15:09:17 -05:00
|
|
|
package gui
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "log"
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-08 17:28:40 -05:00
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-05-08 15:04:18 -05:00
|
|
|
var img [2]*ui.Image
|
|
|
|
|
2019-05-08 18:50:52 -05:00
|
|
|
/*
|
|
|
|
img[0] = ui.NewImage(16, 16)
|
|
|
|
img[1] = ui.NewImage(16, 16)
|
|
|
|
*/
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
type CellData struct {
|
|
|
|
Index int
|
|
|
|
Value ui.TableValue
|
2019-05-12 17:33:33 -05:00
|
|
|
Raw string // shove stuff in here and figure out how to make a ui.TableValue later
|
2019-05-12 17:11:32 -05:00
|
|
|
Name string // what type of cell is this?
|
|
|
|
Event func() // what function to call if there is an event on this
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// hmm. will this stand the test of time?
|
2019-05-12 17:11:32 -05:00
|
|
|
type RowData struct {
|
|
|
|
Name string // what kind of row is this?
|
|
|
|
Status string // status of the row?
|
2019-05-08 15:04:18 -05:00
|
|
|
/*
|
|
|
|
// 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
|
|
|
|
*/
|
2019-05-12 17:11:32 -05:00
|
|
|
Cells [20]CellData
|
2019-05-12 20:05:17 -05:00
|
|
|
Human [20]HumanCellData
|
|
|
|
}
|
|
|
|
|
|
|
|
// hmm. will this stand the test of time?
|
|
|
|
type HumanCellData struct {
|
|
|
|
Name string // what kind of row is this?
|
|
|
|
Text ui.TableString
|
|
|
|
TextID int
|
|
|
|
Color ui.TableColor
|
|
|
|
ColorID int
|
|
|
|
Event func() // what function to call if there is an event on this
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
type TableData struct {
|
|
|
|
RowCount int // This is the number of 'rows' which really means data elements not what the human sees
|
|
|
|
RowWidth int // This is how wide each row is
|
|
|
|
Rows []RowData // This is all the table data by row
|
2019-05-08 15:04:18 -05:00
|
|
|
generatedColumnTypes []ui.TableValue // generate this dynamically
|
2019-05-12 17:11:32 -05:00
|
|
|
libUIevent func(*TableData, *ui.TableModel, int, int, ui.TableValue)
|
|
|
|
cellChangeEvent func(int, int, ui.TableValue)
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 20:05:17 -05:00
|
|
|
/*
|
|
|
|
func initHumanCell(mh *TableData, row int, cell InputData) {
|
|
|
|
humanInt := cell.Index
|
|
|
|
|
|
|
|
intBG := cell.ColorID
|
|
|
|
mh.Rows[row].Human[humanInt].Name = cell.CellType
|
|
|
|
mh.Rows[row].Human[humanInt].Color = cell.Color
|
|
|
|
mh.Rows[row].Human[humanInt].ColorID = intBG
|
|
|
|
mh.Rows[row].Human[humanInt].Text = ui.TableValue{}
|
|
|
|
mh.Rows[row].Human[humanInt].TextID = -1
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func initRowBTcolor(mh *TableData, row int, intBG int, cell InputData) {
|
|
|
|
humanInt := cell.Index
|
|
|
|
|
|
|
|
mh.Rows[row].Human[humanInt].Name = "BG"
|
|
|
|
mh.Rows[row].Human[humanInt].Color = ui.TableColor{0.5, 0.5, 0.5, .7}
|
|
|
|
mh.Rows[row].Human[humanInt].ColorID = intBG
|
|
|
|
// mh.Rows[row].Human[humanInt].Text = ui.TableValue{}
|
|
|
|
mh.Rows[row].Human[humanInt].TextID = -1
|
|
|
|
|
2019-05-08 17:28:40 -05:00
|
|
|
// alternate background of each row light and dark
|
|
|
|
if (row % 2) == 1 {
|
2019-05-12 17:11:32 -05:00
|
|
|
mh.Rows[row].Cells[intBG].Value = ui.TableColor{0.5, 0.5, 0.5, .7}
|
|
|
|
mh.Rows[row].Cells[intBG].Name = "BG"
|
2019-05-08 17:28:40 -05:00
|
|
|
} else {
|
2019-05-12 17:11:32 -05:00
|
|
|
mh.Rows[row].Cells[intBG].Value = ui.TableColor{0.1, 0.1, 0.1, .1}
|
|
|
|
mh.Rows[row].Cells[intBG].Name = "BG"
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-12 20:05:17 -05:00
|
|
|
func initRowButtonColumn(mh *TableData, row int, buttonID int, junk string, cell InputData) {
|
2019-05-08 17:28:40 -05:00
|
|
|
// set the button text for Column ?
|
2019-05-12 17:11:32 -05:00
|
|
|
mh.Rows[row].Cells[buttonID].Value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
|
|
|
mh.Rows[row].Cells[buttonID].Name = "BUTTON"
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 20:05:17 -05:00
|
|
|
func initRowTextColorColumn(mh *TableData, row int, stringID int, colorID int, junk string, color ui.TableColor, cell InputData) {
|
2019-05-08 17:28:40 -05:00
|
|
|
// text for Column ?
|
2019-05-12 17:11:32 -05:00
|
|
|
mh.Rows[row].Cells[stringID].Value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
|
|
|
mh.Rows[row].Cells[stringID].Name = "EDIT"
|
2019-05-08 17:28:40 -05:00
|
|
|
|
|
|
|
// text color for Column ?
|
2019-05-12 17:11:32 -05:00
|
|
|
mh.Rows[row].Cells[colorID].Value = color
|
|
|
|
mh.Rows[row].Cells[colorID].Name = "COLOR"
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 20:05:17 -05:00
|
|
|
func initRowTextColumn(mh *TableData, row int, stringID int, junk string, cell InputData) {
|
2019-05-12 17:11:32 -05:00
|
|
|
mh.Rows[row].Cells[stringID].Value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
|
|
|
mh.Rows[row].Cells[stringID].Name = "EDIT"
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
func appendTextColorColumn(mh *TableData, table *ui.Table, stringID int, colorID int, columnName string) {
|
2019-05-08 15:04:18 -05:00
|
|
|
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable,
|
|
|
|
&ui.TableTextColumnOptionalParams{
|
|
|
|
ColorModelColumn: colorID,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
func appendTextColumn(mh *TableData, table *ui.Table, stringID int, columnName string) {
|
2019-05-08 15:04:18 -05:00
|
|
|
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable, nil)
|
|
|
|
}
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
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
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
2019-05-12 17:11:32 -05:00
|
|
|
if (mh.Rows[row].Cells[column].Name == "BUTTON") {
|
|
|
|
log.Println("FOUND THE BUTTON!!!!!!! Button was pressed START", row, column)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func simpleSetCellValue(mh *TableData, row, column int, value string) {
|
|
|
|
if (mh.Rows[row].Cells[column].Name == "EDIT") {
|
|
|
|
mh.Rows[row].Cells[column].Value = ui.TableString(value)
|
|
|
|
}
|
|
|
|
if (mh.Rows[row].Cells[column].Name == "BUTTON") {
|
2019-05-08 15:04:18 -05:00
|
|
|
log.Println("FOUND THE BUTTON!!!!!!! Button was pressed START", row, column)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|