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-05-23 15:57:49 -05:00
|
|
|
if (Data.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-05-24 11:02:35 -05:00
|
|
|
if (Data.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
|
|
|
|
}
|
|
|
|
|
2019-05-21 17:17:50 -05:00
|
|
|
func libuiColorToGOlangColor(rgba color.RGBA) ui.TableColor {
|
2019-05-23 16:33:11 -05:00
|
|
|
/* a hack to see if colors work differently on macos or windows
|
2019-05-23 16:02:04 -05:00
|
|
|
if (rgba.R == 72) {
|
|
|
|
log.Println("SETTING COLOR TO NIL")
|
|
|
|
log.Println("SETTING COLOR TO NIL")
|
|
|
|
log.Println("SETTING COLOR TO NIL")
|
|
|
|
return ui.TableColor{}
|
|
|
|
}
|
2019-05-23 16:33:11 -05:00
|
|
|
*/
|
2019-05-21 17:17:50 -05:00
|
|
|
return ui.TableColor{float64(rgba.R) / 256, float64(rgba.G) / 256, float64(rgba.B) / 256, float64(rgba.A) / 256}
|
|
|
|
}
|
|
|
|
|
2019-05-08 15:04:18 -05:00
|
|
|
// 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-05-24 11:02:35 -05:00
|
|
|
if (Data.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:37:46 -05:00
|
|
|
//if (runtime.GOOS == "windows") {
|
|
|
|
// log.Println("CellValue() is BG COLOR row, column =", row, column)
|
|
|
|
// return nil
|
|
|
|
//}
|
2019-05-23 17:32:09 -05:00
|
|
|
bgcolor := libuiColorToGOlangColor(mh.Rows[row].HumanData[humanID].Color)
|
2019-05-24 03:17:14 -05:00
|
|
|
if (Data.Debug) {
|
|
|
|
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) {
|
|
|
|
mouseClick(button)
|
|
|
|
return
|
|
|
|
}
|
2019-05-24 03:17:14 -05:00
|
|
|
if (Data.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
|
|
|
}
|
|
|
|
}
|