summaryrefslogtreecommitdiff
path: root/table.go
blob: b33bb9b2828519f8d83b14b82d312d8675ec5e07 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// based off andlabs/ui/examples/table.go

package gui

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

// import "github.com/davecgh/go-spew/spew"

type CellData struct {
	Index		int
	HumanID		int
	Value		ui.TableValue
	Name		string			// what type of cell is 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
	Human		[20]HumanCellData
}

// hmm. will this stand the test of time?
type HumanCellData struct {
	Name		string			// what kind of row is this?
	Text		ui.TableString
	TextID		int
	Color		ui.TableColor
	ColorID		int
//	Event		func()			// what function to call if there is an event on this
}

type TableData struct {
	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
	Rows			[]RowData		// This is all the table data by row
	generatedColumnTypes	[]ui.TableValue		// generate this dynamically
	libUIevent 	 	func(*TableData, *ui.TableModel, int, int, ui.TableValue)
	cellChangeEvent  	func(int, int, ui.TableValue)
}

func initRowBTcolor(mh *TableData, row int, intBG int, cell InputData) {
	humanInt := cell.Index

	// setup mapping from human readable indexes to internal libUI indexes
	mh.Rows[row].Human[humanInt].Name    = "BG"
	mh.Rows[row].Human[humanInt].ColorID = intBG
	mh.Rows[row].Human[humanInt].TextID  = -1

	mh.Rows[row].Cells[intBG].Name       = "BG"
	mh.Rows[row].Cells[intBG].HumanID    = humanInt

	log.Println("HumanID = row, intBG, humanInt", row, intBG, humanInt)

	// alternate background of each row light and dark
	if (row % 2) == 1 {
		mh.Rows[row].Cells[intBG].Value   = ui.TableColor{0.5, 0.5, 0.5, .7}
	} else {
		mh.Rows[row].Cells[intBG].Value   = ui.TableColor{0.1, 0.1, 0.1, .1}
	}
}

func initRowButtonColumn(mh *TableData, row int, buttonID int, junk string, cell InputData) {
	humanInt := cell.Index

	// setup mapping from human readable indexes to internal libUI indexes
	mh.Rows[row].Human[humanInt].Name    = "BUTTON"
	mh.Rows[row].Human[humanInt].ColorID = -1
	mh.Rows[row].Human[humanInt].TextID  = buttonID

	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].HumanID = humanInt

	log.Println("HumanID = row, buttonID, humanInt", row, buttonID, humanInt)
}

func initRowTextColorColumn(mh *TableData, row int, stringID int, colorID int, junk string, color ui.TableColor, cell InputData) {
	humanInt := cell.Index

	// setup mapping from human readable indexes to internal libUI indexes
	mh.Rows[row].Human[humanInt].Name    = "EDIT"
	mh.Rows[row].Human[humanInt].ColorID = colorID
	mh.Rows[row].Human[humanInt].TextID  = stringID

	// text for Column humanInt
	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].HumanID = humanInt

	mh.Rows[row].Cells[colorID].Value    = color
	mh.Rows[row].Cells[colorID].Name     = "COLOR"
	mh.Rows[row].Cells[colorID].HumanID  = humanInt
}

func initRowTextColumn(mh *TableData, row int, stringID int, junk string, cell InputData) {
	humanInt := cell.Index

	// setup mapping from human readable indexes to internal libUI indexes
	mh.Rows[row].Human[humanInt].Name    = "EDIT"
	mh.Rows[row].Human[humanInt].ColorID = -1
	mh.Rows[row].Human[humanInt].TextID  = stringID

	mh.Rows[row].Cells[stringID].Name    = "EDIT"
	mh.Rows[row].Cells[stringID].Value   = ui.TableString(fmt.Sprintf("%s %d", junk, row))
	mh.Rows[row].Cells[stringID].HumanID = humanInt
}

func appendTextColorColumn(mh *TableData, table *ui.Table, stringID int, colorID int, columnName string) {
	table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable,
		&ui.TableTextColumnOptionalParams{
			ColorModelColumn:               colorID,
	});
}

func appendTextColumn(mh *TableData, table *ui.Table, stringID int, columnName string) {
	table.AppendTextColumn(columnName, stringID, ui.TableModelColumnAlwaysEditable, nil)
}

func defaultSetCellValue(mh *TableData, m *ui.TableModel, row, column int, value ui.TableValue) {
	if (mh.Rows[row].Cells[column].Name == "EDIT") {
		mh.Rows[row].Cells[column].Value = value
	}
	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("simpleSetCellValue() FOUND THE BUTTON!!!!!!!  Button was pressed:", row, column)
	}
	return
}