summaryrefslogtreecommitdiff
path: root/tableCallbacks.go
blob: 28ddd8b44e710664901feb2f2e1c215506349c40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package gui

//
// 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"
import "fmt"
import "image/color"
import "runtime"

import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"

func (mh *TableData) NumRows(m *ui.TableModel) int {
	if (Data.Debug) {
		log.Println("NumRows = mh.RowCount = ", mh.RowCount)
	}
	return mh.RowCount
}

// 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 {
	if (Data.Debug) {
		log.Println("ColumnTypes = ", mh.generatedColumnTypes)
	}
	return mh.generatedColumnTypes
}

func libuiColorToGOlangColor(rgba color.RGBA) ui.TableColor {
	/* a hack to see if colors work differently on macos or windows 
	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{}
	}
	*/
	return ui.TableColor{float64(rgba.R) / 256, float64(rgba.G) / 256, float64(rgba.B) / 256, float64(rgba.A) / 256}
}

// 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
func (mh *TableData) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
	if (Data.Debug) {
		log.Println("CellValue() row, column =", row, column)
	}
	humanID := mh.Cells[column].HumanID
	if (column == mh.Human[humanID].TextID) {
		return ui.TableString(mh.Rows[row].HumanData[humanID].Text)
	}
	if (column == mh.Human[humanID].ColorID) {
		if (column == 0) {
			// ignore BG color on windows for now
			if (runtime.GOOS == "windows") {
				log.Println("CellValue() is BG COLOR row, column =", row, column)
				return nil
			}
			bgcolor := libuiColorToGOlangColor(mh.Rows[row].HumanData[humanID].Color)
			if (Data.Debug) {
				log.Println("CellValue() BGCOLOR =", bgcolor)
			}
			return bgcolor
		}
		return libuiColorToGOlangColor(mh.Rows[row].HumanData[humanID].Color)
	}
	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()")
	return ui.TableString("")
}

func (mh *TableData) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
	log.Println("SetCellValue() START row=", row, "column=", column, "value=", value)

	defaultSetCellValue(mh, row, column)

	log.Println("mh.Cells[column].HumanID =", mh.Cells[column].HumanID)
	// log.Println("mh.Rows[row].Cells[column].HumanID =", mh.Rows[row].Cells[column].HumanID)

	humanID := mh.Cells[column].HumanID
	log.Println("mh.Human[humanID].ColorID =", mh.Human[humanID].ColorID)
	log.Println("mh.Human[humanID].TextID =",  mh.Human[humanID].TextID)

	log.Println("SetCellValue() END")
}

func defaultSetCellValue(mh *TableData, row int, column int) {
	if (mh.Cells[column].Name == "BUTTON") {
		humanID := mh.Cells[column].HumanID
		vmname := mh.Rows[row].HumanData[humanID].Text
		log.Println("vmname =",  vmname)
		log.Println("defaultSetCellValue() FOUND THE BUTTON!!!!!!!   Button was pressed START", row, column)
		Data.CurrentVM = fmt.Sprintf("%s",vmname)
		log.Println("Data.CurrentVM =", Data.CurrentVM)
		if (Data.Debug) {
			go ui.Main(ShowVM)
		} else {
			AddVmConfigureTab(vmname)
		}
	}
}