2019-05-08 15:09:17 -05:00
|
|
|
package gui
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// These functions are the hooks to the andlabs libui
|
|
|
|
// They eventually feed information to the OS native GUI toolkits
|
|
|
|
// and feed back user interaction with the GUI
|
|
|
|
//
|
|
|
|
|
|
|
|
import "log"
|
2019-05-24 22:54:09 -05:00
|
|
|
// import "fmt"
|
2019-05-21 17:17:50 -05:00
|
|
|
import "image/color"
|
2019-05-23 17:28:09 -05:00
|
|
|
import "runtime"
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
func (mh *TableData) NumRows(m *ui.TableModel) int {
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.Debug) {
|
2019-05-24 11:02:35 -05:00
|
|
|
log.Println("NumRows = mh.RowCount = ", mh.RowCount, "(last Row & Column =", mh.lastRow, mh.lastColumn, ")")
|
2019-05-21 20:42:14 -05:00
|
|
|
}
|
2019-05-12 17:11:32 -05:00
|
|
|
return mh.RowCount
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// FYI: this routine seems to be called around 10 to 100 times a second for each table
|
2019-05-12 17:11:32 -05:00
|
|
|
func (mh *TableData) ColumnTypes(m *ui.TableModel) []ui.TableValue {
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.DebugTable) {
|
2019-05-21 20:25:08 -05:00
|
|
|
log.Println("ColumnTypes = ", mh.generatedColumnTypes)
|
2019-05-21 20:42:14 -05:00
|
|
|
}
|
2019-05-08 15:04:18 -05:00
|
|
|
return mh.generatedColumnTypes
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2019-05-12 17:11:32 -05:00
|
|
|
func (mh *TableData) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.DebugTable) {
|
2019-05-21 20:28:20 -05:00
|
|
|
log.Println("CellValue() row, column =", row, column)
|
2019-05-21 20:42:14 -05:00
|
|
|
}
|
2019-05-24 11:02:35 -05:00
|
|
|
mh.lastRow = row
|
|
|
|
mh.lastColumn = column
|
2019-05-13 01:49:26 -05:00
|
|
|
humanID := mh.Cells[column].HumanID
|
2019-05-13 01:56:53 -05:00
|
|
|
if (column == mh.Human[humanID].TextID) {
|
2019-05-21 16:48:15 -05:00
|
|
|
return ui.TableString(mh.Rows[row].HumanData[humanID].Text)
|
2019-05-12 23:21:13 -05:00
|
|
|
}
|
2019-05-13 01:56:53 -05:00
|
|
|
if (column == mh.Human[humanID].ColorID) {
|
2019-05-23 17:23:26 -05:00
|
|
|
if (column == 0) {
|
2019-05-23 17:28:09 -05:00
|
|
|
// ignore BG color on windows for now
|
2019-05-28 18:39:25 -05:00
|
|
|
if (runtime.GOOS == "windows") {
|
2019-05-28 18:47:24 -05:00
|
|
|
// TODO: fix colors on windows
|
|
|
|
// log.Println("CellValue() WINDOWS is BG COLOR row, column =", row, column)
|
2019-05-28 18:39:25 -05:00
|
|
|
// return nil
|
|
|
|
}
|
2019-05-28 18:47:24 -05:00
|
|
|
|
|
|
|
if (mh.Rows[row].HumanData[humanID].Color == color.RGBA{255, 255, 255, 255}) {
|
|
|
|
log.Println("CellValue() color.RGBA{255, 255, 255, 255} so return nil. row, column =", row, column)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-23 17:32:09 -05:00
|
|
|
bgcolor := libuiColorToGOlangColor(mh.Rows[row].HumanData[humanID].Color)
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.Debug) {
|
2019-05-24 03:17:14 -05:00
|
|
|
log.Println("CellValue() BGCOLOR =", bgcolor)
|
|
|
|
}
|
2019-05-23 17:32:09 -05:00
|
|
|
return bgcolor
|
2019-05-23 17:23:26 -05:00
|
|
|
}
|
2019-05-23 16:02:04 -05:00
|
|
|
return libuiColorToGOlangColor(mh.Rows[row].HumanData[humanID].Color)
|
2019-05-12 23:44:05 -05:00
|
|
|
}
|
2019-05-13 02:30:38 -05:00
|
|
|
log.Println("CellValue() FAILURE")
|
|
|
|
log.Println("CellValue() FAILURE")
|
|
|
|
log.Println("CellValue() row, column = ", row, column)
|
|
|
|
log.Println("CellValue() FAILURE")
|
|
|
|
log.Println("CellValue() FAILURE")
|
|
|
|
log.Println("CellValue() mh.Cells", mh.Cells)
|
|
|
|
log.Println("CellValue() mh.Human", mh.Human)
|
|
|
|
panic("CellValue() not sure what sort of ui.TableValue to return in CellValue()")
|
2019-05-13 01:17:48 -05:00
|
|
|
return ui.TableString("")
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
|
|
|
|
2019-05-12 17:11:32 -05:00
|
|
|
func (mh *TableData) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
2019-05-12 23:01:22 -05:00
|
|
|
log.Println("SetCellValue() START row=", row, "column=", column, "value=", value)
|
|
|
|
|
2019-05-13 01:37:27 -05:00
|
|
|
defaultSetCellValue(mh, row, column)
|
2019-05-12 23:01:22 -05:00
|
|
|
|
2019-05-13 01:49:26 -05:00
|
|
|
log.Println("mh.Cells[column].HumanID =", mh.Cells[column].HumanID)
|
|
|
|
// log.Println("mh.Rows[row].Cells[column].HumanID =", mh.Rows[row].Cells[column].HumanID)
|
2019-05-12 23:01:22 -05:00
|
|
|
|
2019-05-13 01:49:26 -05:00
|
|
|
humanID := mh.Cells[column].HumanID
|
2019-05-13 01:56:53 -05:00
|
|
|
log.Println("mh.Human[humanID].ColorID =", mh.Human[humanID].ColorID)
|
|
|
|
log.Println("mh.Human[humanID].TextID =", mh.Human[humanID].TextID)
|
2019-05-12 23:01:22 -05:00
|
|
|
|
|
|
|
log.Println("SetCellValue() END")
|
2019-05-08 15:04:18 -05:00
|
|
|
}
|
2019-05-13 01:37:27 -05:00
|
|
|
|
|
|
|
func defaultSetCellValue(mh *TableData, row int, column int) {
|
2019-05-13 01:49:26 -05:00
|
|
|
if (mh.Cells[column].Name == "BUTTON") {
|
2019-05-15 13:03:42 -05:00
|
|
|
humanID := mh.Cells[column].HumanID
|
2019-05-26 16:47:30 -05:00
|
|
|
log.Println("defaultSetCellValue() FOUND THE TABLE BUTTON ", row, humanID)
|
|
|
|
|
|
|
|
button := mh.Rows[row].HumanData[humanID].Button
|
|
|
|
if (button != nil) {
|
2019-06-02 17:19:53 -05:00
|
|
|
guiButtonClick(button)
|
2019-05-26 16:47:30 -05:00
|
|
|
return
|
|
|
|
}
|
2019-06-02 17:19:53 -05:00
|
|
|
log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE")
|
2019-06-02 17:49:52 -05:00
|
|
|
if (Config.Debug) {
|
2019-05-26 16:47:30 -05:00
|
|
|
panic("defaultSetCellValue() GOT AN UNKNOWN BUTTON CLICK IN TABLE")
|
2019-05-24 03:17:14 -05:00
|
|
|
}
|
2019-05-13 01:37:27 -05:00
|
|
|
}
|
|
|
|
}
|