almost completely able to automate adding columns
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
97d7ad349e
commit
fb89975cdf
45
table.go
45
table.go
|
@ -11,8 +11,23 @@ import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
var img [2]*ui.Image
|
var img [2]*ui.Image
|
||||||
|
|
||||||
type cellTest struct {
|
type cellData struct {
|
||||||
jwc [20]ui.TableValue
|
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 modelHandler struct {
|
type modelHandler struct {
|
||||||
|
@ -20,7 +35,7 @@ type modelHandler struct {
|
||||||
rowcount int
|
rowcount int
|
||||||
rowBGcolor int
|
rowBGcolor int
|
||||||
|
|
||||||
rows []cellTest
|
rows []rowData
|
||||||
|
|
||||||
generatedColumnTypes []ui.TableValue // generate this dynamically
|
generatedColumnTypes []ui.TableValue // generate this dynamically
|
||||||
|
|
||||||
|
@ -43,35 +58,35 @@ func initValues(mh *modelHandler) {
|
||||||
|
|
||||||
// alternate background of each row light and dark
|
// alternate background of each row light and dark
|
||||||
if (i % 2) == 1 {
|
if (i % 2) == 1 {
|
||||||
mh.rows[i].jwc[0] = ui.TableColor{0.5, 0.5, 0.5, .7}
|
mh.rows[i].cells[0].value = ui.TableColor{0.5, 0.5, 0.5, .7}
|
||||||
} else {
|
} else {
|
||||||
mh.rows[i].jwc[0] = ui.TableColor{0.1, 0.1, 0.1, .1}
|
mh.rows[i].cells[0].value = ui.TableColor{0.1, 0.1, 0.1, .1}
|
||||||
}
|
}
|
||||||
|
|
||||||
// text for Column 0
|
// text for Column 0
|
||||||
mh.rows[i].jwc[1] = ui.TableString(fmt.Sprintf("fun %d", i))
|
mh.rows[i].cells[1].value = ui.TableString(fmt.Sprintf("fun %d", i))
|
||||||
|
|
||||||
// text color for Column 0
|
// text color for Column 0
|
||||||
mh.rows[i].jwc[2] = ui.TableColor{0.9, 0, 0, 1}
|
mh.rows[i].cells[2].value = ui.TableColor{0.9, 0, 0, 1}
|
||||||
|
|
||||||
// set the button text for Column 1
|
// set the button text for Column 1
|
||||||
mh.rows[i].jwc[3] = ui.TableString(fmt.Sprintf("awesome %d", i))
|
mh.rows[i].cells[3].value = ui.TableString(fmt.Sprintf("awesome %d", i))
|
||||||
|
|
||||||
|
|
||||||
// text for Column 2
|
// text for Column 2
|
||||||
mh.rows[i].jwc[4] = ui.TableString(fmt.Sprintf("color %d", i))
|
mh.rows[i].cells[4].value = ui.TableString(fmt.Sprintf("color %d", i))
|
||||||
|
|
||||||
// text color for Column 2
|
// text color for Column 2
|
||||||
mh.rows[i].jwc[5] = ui.TableColor{0.9, 0, 0, 1}
|
mh.rows[i].cells[5].value = ui.TableColor{0.9, 0, 0, 1}
|
||||||
|
|
||||||
// text for Column 3
|
// text for Column 3
|
||||||
mh.rows[i].jwc[6] = ui.TableString(fmt.Sprintf("imgcolor %d", i))
|
mh.rows[i].cells[6].value = ui.TableString(fmt.Sprintf("imgcolor %d", i))
|
||||||
|
|
||||||
// image for Column 3
|
// image for Column 3
|
||||||
mh.rows[i].jwc[7] = ui.TableImage{img[0]}
|
mh.rows[i].cells[7].value = ui.TableImage{img[0]}
|
||||||
|
|
||||||
// text color for Column 3
|
// text color for Column 3
|
||||||
mh.rows[i].jwc[8] = ui.TableColor{0.9, 0, 0, 1}
|
mh.rows[i].cells[8].value = ui.TableColor{0.9, 0, 0, 1}
|
||||||
}
|
}
|
||||||
// os.Exit(-1)
|
// os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +101,7 @@ func newModelHandler(rowcount int) *modelHandler {
|
||||||
|
|
||||||
mh.rowBGcolor = 0 // this is the weird exception. Just always have this as 0
|
mh.rowBGcolor = 0 // this is the weird exception. Just always have this as 0
|
||||||
|
|
||||||
mh.rows = make([]cellTest, mh.rowcount)
|
mh.rows = make([]rowData, mh.rowcount)
|
||||||
|
|
||||||
initValues(mh)
|
initValues(mh)
|
||||||
|
|
||||||
|
@ -130,7 +145,7 @@ func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, va
|
||||||
switch column {
|
switch column {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
mh.rows[row].jwc[1] = value
|
mh.rows[row].cells[1].value = value
|
||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
log.Println("Button was pressed START", row, column)
|
log.Println("Button was pressed START", row, column)
|
||||||
|
|
|
@ -24,7 +24,7 @@ func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
|
||||||
// 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 *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
|
func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
|
||||||
return mh.rows[row].jwc[column]
|
return mh.rows[row].cells[column].value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||||
|
|
Loading…
Reference in New Issue