export all the structs in TableData
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
cf17208da0
commit
800f8db555
26
gui.go
26
gui.go
|
@ -260,7 +260,7 @@ func AddEntriesDemo() {
|
||||||
maintab.SetMargined(tabcount, true)
|
maintab.SetMargined(tabcount, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initColumnNames(mh *tableData, cellJWC string, junk string) {
|
func initColumnNames(mh *TableData, cellJWC string, junk string) {
|
||||||
if (cellJWC == "BG") {
|
if (cellJWC == "BG") {
|
||||||
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
||||||
} else if (cellJWC == "BUTTON") {
|
} else if (cellJWC == "BUTTON") {
|
||||||
|
@ -275,7 +275,7 @@ func initColumnNames(mh *tableData, cellJWC string, junk string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRow(mh *tableData, row int, parts []InputData) {
|
func initRow(mh *TableData, row int, parts []InputData) {
|
||||||
tmpBTindex := 0
|
tmpBTindex := 0
|
||||||
for key, foo := range parts {
|
for key, foo := range parts {
|
||||||
log.Println(key, foo)
|
log.Println(key, foo)
|
||||||
|
@ -305,10 +305,10 @@ type InputData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddSampleTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []InputData) {
|
func AddSampleTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []InputData) {
|
||||||
mh := new(tableData)
|
mh := new(TableData)
|
||||||
|
|
||||||
mh.rowcount = rowcount
|
mh.RowCount = rowcount
|
||||||
mh.rows = make([]rowData, mh.rowcount)
|
mh.Rows = make([]RowData, mh.RowCount)
|
||||||
|
|
||||||
// This is the standard callback function from libUI when the user does something
|
// This is the standard callback function from libUI when the user does something
|
||||||
mh.libUIevent = defaultSetCellValue
|
mh.libUIevent = defaultSetCellValue
|
||||||
|
@ -322,7 +322,7 @@ func AddSampleTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int,
|
||||||
|
|
||||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||||
|
|
||||||
for row := 0; row < mh.rowcount; row++ {
|
for row := 0; row < mh.RowCount; row++ {
|
||||||
initRow(mh, row, parts)
|
initRow(mh, row, parts)
|
||||||
}
|
}
|
||||||
log.Println(mh)
|
log.Println(mh)
|
||||||
|
@ -357,11 +357,11 @@ func AddSampleTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int,
|
||||||
mytab.SetMargined(mytabcount, true)
|
mytab.SetMargined(mytabcount, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []InputData) {
|
func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts []InputData) *TableData {
|
||||||
mh := new(tableData)
|
mh := new(TableData)
|
||||||
|
|
||||||
mh.rowcount = rowcount
|
mh.RowCount = rowcount
|
||||||
mh.rows = make([]rowData, mh.rowcount)
|
mh.Rows = make([]RowData, mh.RowCount)
|
||||||
|
|
||||||
// This is the standard callback function from libUI when the user does something
|
// This is the standard callback function from libUI when the user does something
|
||||||
mh.libUIevent = defaultSetCellValue
|
mh.libUIevent = defaultSetCellValue
|
||||||
|
@ -373,9 +373,7 @@ func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts
|
||||||
initColumnNames(mh, foo.CellType, foo.Heading)
|
initColumnNames(mh, foo.CellType, foo.Heading)
|
||||||
}
|
}
|
||||||
|
|
||||||
// time.Sleep(1 * 1000 * 1000 * 1000)
|
for row := 0; row < mh.RowCount; row++ {
|
||||||
|
|
||||||
for row := 0; row < mh.rowcount; row++ {
|
|
||||||
initRow(mh, row, parts)
|
initRow(mh, row, parts)
|
||||||
}
|
}
|
||||||
log.Println(mh)
|
log.Println(mh)
|
||||||
|
@ -408,6 +406,8 @@ func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts
|
||||||
|
|
||||||
mytab.Append(name, table)
|
mytab.Append(name, table)
|
||||||
mytab.SetMargined(mytabcount, true)
|
mytab.SetMargined(mytabcount, true)
|
||||||
|
|
||||||
|
return mh
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoGUI() {
|
func DoGUI() {
|
||||||
|
|
83
table.go
83
table.go
|
@ -16,81 +16,92 @@ var img [2]*ui.Image
|
||||||
img[1] = ui.NewImage(16, 16)
|
img[1] = ui.NewImage(16, 16)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type cellData struct {
|
type CellData struct {
|
||||||
index int
|
Index int
|
||||||
value ui.TableValue
|
Value ui.TableValue
|
||||||
name string // what type of cell is this?
|
Name string // what type of cell is this?
|
||||||
event func() // what function to call if there is an event on this
|
Event func() // what function to call if there is an event on this
|
||||||
}
|
}
|
||||||
|
|
||||||
// hmm. will this stand the test of time?
|
// hmm. will this stand the test of time?
|
||||||
type rowData struct {
|
type RowData struct {
|
||||||
name string // what kind of row is this?
|
Name string // what kind of row is this?
|
||||||
status string // status of the row?
|
Status string // status of the row?
|
||||||
/*
|
/*
|
||||||
// These may or may not be implementable
|
// These may or may not be implementable
|
||||||
click func() // what function to call if the user clicks on it
|
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
|
doubleclick func() // what function to call if the user double clicks on it
|
||||||
*/
|
*/
|
||||||
cells [20]cellData
|
Cells [20]CellData
|
||||||
}
|
}
|
||||||
|
|
||||||
type tableData struct {
|
type TableData struct {
|
||||||
rowcount int // This is the number of 'rows' which really means data elements not what the human sees
|
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
|
RowWidth int // This is how wide each row is
|
||||||
rows []rowData // This is all the table data by row
|
Rows []RowData // This is all the table data by row
|
||||||
generatedColumnTypes []ui.TableValue // generate this dynamically
|
generatedColumnTypes []ui.TableValue // generate this dynamically
|
||||||
libUIevent func(*tableData, *ui.TableModel, int, int, ui.TableValue)
|
libUIevent func(*TableData, *ui.TableModel, int, int, ui.TableValue)
|
||||||
|
cellChangeEvent func(int, int, ui.TableValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRowBTcolor(mh *tableData, row int, intBG int) {
|
func initRowBTcolor(mh *TableData, row int, intBG int) {
|
||||||
// alternate background of each row light and dark
|
// alternate background of each row light and dark
|
||||||
if (row % 2) == 1 {
|
if (row % 2) == 1 {
|
||||||
mh.rows[row].cells[intBG].value = ui.TableColor{0.5, 0.5, 0.5, .7}
|
mh.Rows[row].Cells[intBG].Value = ui.TableColor{0.5, 0.5, 0.5, .7}
|
||||||
mh.rows[row].cells[intBG].name = "BG"
|
mh.Rows[row].Cells[intBG].Name = "BG"
|
||||||
} else {
|
} else {
|
||||||
mh.rows[row].cells[intBG].value = ui.TableColor{0.1, 0.1, 0.1, .1}
|
mh.Rows[row].Cells[intBG].Value = ui.TableColor{0.1, 0.1, 0.1, .1}
|
||||||
mh.rows[row].cells[intBG].name = "BG"
|
mh.Rows[row].Cells[intBG].Name = "BG"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRowButtonColumn(mh *tableData, row int, buttonID int, junk string) {
|
func initRowButtonColumn(mh *TableData, row int, buttonID int, junk string) {
|
||||||
// set the button text for Column ?
|
// set the button text for Column ?
|
||||||
mh.rows[row].cells[buttonID].value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
mh.Rows[row].Cells[buttonID].Value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
||||||
mh.rows[row].cells[buttonID].name = "BUTTON"
|
mh.Rows[row].Cells[buttonID].Name = "BUTTON"
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRowTextColorColumn(mh *tableData, row int, stringID int, colorID int, junk string, color ui.TableColor) {
|
func initRowTextColorColumn(mh *TableData, row int, stringID int, colorID int, junk string, color ui.TableColor) {
|
||||||
// text for Column ?
|
// text for Column ?
|
||||||
mh.rows[row].cells[stringID].value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
mh.Rows[row].Cells[stringID].Value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
||||||
mh.rows[row].cells[stringID].name = "EDIT"
|
mh.Rows[row].Cells[stringID].Name = "EDIT"
|
||||||
|
|
||||||
// text color for Column ?
|
// text color for Column ?
|
||||||
mh.rows[row].cells[colorID].value = color
|
mh.Rows[row].Cells[colorID].Value = color
|
||||||
mh.rows[row].cells[colorID].name = "COLOR"
|
mh.Rows[row].Cells[colorID].Name = "COLOR"
|
||||||
}
|
}
|
||||||
|
|
||||||
func initRowTextColumn(mh *tableData, row int, stringID int, junk string) {
|
func initRowTextColumn(mh *TableData, row int, stringID int, junk string) {
|
||||||
mh.rows[row].cells[stringID].value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
mh.Rows[row].Cells[stringID].Value = ui.TableString(fmt.Sprintf("%s %d", junk, row))
|
||||||
mh.rows[row].cells[stringID].name = "EDIT"
|
mh.Rows[row].Cells[stringID].Name = "EDIT"
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendTextColorColumn(mh *tableData, table *ui.Table, stringID int, colorID int, columnName string) {
|
func appendTextColorColumn(mh *TableData, table *ui.Table, stringID int, colorID int, columnName string) {
|
||||||
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable,
|
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable,
|
||||||
&ui.TableTextColumnOptionalParams{
|
&ui.TableTextColumnOptionalParams{
|
||||||
ColorModelColumn: colorID,
|
ColorModelColumn: colorID,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendTextColumn(mh *tableData, table *ui.Table, stringID int, columnName string) {
|
func appendTextColumn(mh *TableData, table *ui.Table, stringID int, columnName string) {
|
||||||
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable, nil)
|
table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultSetCellValue(mh *tableData, m *ui.TableModel, row, column int, value ui.TableValue) {
|
func defaultSetCellValue(mh *TableData, m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||||
if (mh.rows[row].cells[column].name == "EDIT") {
|
if (mh.Rows[row].Cells[column].Name == "EDIT") {
|
||||||
mh.rows[row].cells[column].value = value
|
mh.Rows[row].Cells[column].Value = value
|
||||||
}
|
}
|
||||||
if (mh.rows[row].cells[column].name == "BUTTON") {
|
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") {
|
||||||
log.Println("FOUND THE BUTTON!!!!!!! Button was pressed START", row, column)
|
log.Println("FOUND THE BUTTON!!!!!!! Button was pressed START", row, column)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,22 +12,22 @@ import "log"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
func (mh *tableData) NumRows(m *ui.TableModel) int {
|
func (mh *TableData) NumRows(m *ui.TableModel) int {
|
||||||
return mh.rowcount
|
return mh.RowCount
|
||||||
}
|
}
|
||||||
|
|
||||||
// FYI: this routine seems to be called around 10 to 100 times a second for each table
|
// FYI: this routine seems to be called around 10 to 100 times a second for each table
|
||||||
func (mh *tableData) ColumnTypes(m *ui.TableModel) []ui.TableValue {
|
func (mh *TableData) ColumnTypes(m *ui.TableModel) []ui.TableValue {
|
||||||
return mh.generatedColumnTypes
|
return mh.generatedColumnTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Figure out why this is being called 1000 times a second (10 times for each row & column)
|
// TODO: Figure out why this is being called 1000 times a second (10 times for each row & column)
|
||||||
// Nevermind this TODO. Who gives a shit. This is a really smart way to treat the OS toolkits
|
// Nevermind this TODO. Who gives a shit. This is a really smart way to treat the OS toolkits
|
||||||
func (mh *tableData) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
|
func (mh *TableData) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
|
||||||
return mh.rows[row].cells[column].value
|
return mh.Rows[row].Cells[column].Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *tableData) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
func (mh *TableData) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||||
log.Println("SetCallValue() START row=", row, "column=", column, "value=", value)
|
log.Println("SetCallValue() START row=", row, "column=", column, "value=", value)
|
||||||
// spew.Dump(m)
|
// spew.Dump(m)
|
||||||
// spew.Dump(mh)
|
// spew.Dump(mh)
|
||||||
|
@ -37,5 +37,8 @@ func (mh *tableData) SetCellValue(m *ui.TableModel, row, column int, value ui.Ta
|
||||||
}
|
}
|
||||||
// spew.Dump(m)
|
// spew.Dump(m)
|
||||||
mh.libUIevent(mh, m, row, column, value)
|
mh.libUIevent(mh, m, row, column, value)
|
||||||
|
if (mh.cellChangeEvent != nil) {
|
||||||
|
mh.cellChangeEvent(row, column, value)
|
||||||
|
}
|
||||||
log.Println("SetCallValue() END")
|
log.Println("SetCallValue() END")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue