2019-05-08 15:04:18 -05:00
|
|
|
// based off andlabs/ui/examples/table.go
|
|
|
|
|
2019-05-08 15:09:17 -05:00
|
|
|
package gui
|
2019-05-08 15:04:18 -05:00
|
|
|
|
|
|
|
import "log"
|
2019-05-21 17:17:50 -05:00
|
|
|
|
2019-05-08 15:04:18 -05:00
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-08 17:28:40 -05:00
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func initRowBTcolor(mh *TableData, intBG int, cell TableColumnData) {
|
2019-05-12 20:05:17 -05:00
|
|
|
humanInt := cell.Index
|
|
|
|
|
2019-05-12 22:25:55 -05:00
|
|
|
// setup mapping from human readable indexes to internal libUI indexes
|
2019-05-13 01:56:53 -05:00
|
|
|
mh.Human[humanInt].Name = "BG"
|
|
|
|
mh.Human[humanInt].ColorID = intBG
|
|
|
|
mh.Human[humanInt].TextID = -1
|
2019-05-12 20:05:17 -05:00
|
|
|
|
2019-05-13 01:49:26 -05:00
|
|
|
mh.Cells[intBG].Name = "BG"
|
|
|
|
mh.Cells[intBG].HumanID = humanInt
|
2019-05-12 22:25:55 -05:00
|
|
|
|
2019-05-13 02:08:59 -05:00
|
|
|
log.Println("intBG, humanInt", intBG, humanInt)
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func initRowButtonColumn(mh *TableData, buttonID int, junk string, cell TableColumnData) {
|
2019-05-12 22:25:55 -05:00
|
|
|
humanInt := cell.Index
|
|
|
|
|
|
|
|
// setup mapping from human readable indexes to internal libUI indexes
|
2019-05-13 01:56:53 -05:00
|
|
|
mh.Human[humanInt].Name = "BUTTON"
|
|
|
|
mh.Human[humanInt].ColorID = -1
|
|
|
|
mh.Human[humanInt].TextID = buttonID
|
2019-05-12 22:25:55 -05:00
|
|
|
|
2019-05-13 01:49:26 -05:00
|
|
|
mh.Cells[buttonID].Name = "BUTTON"
|
|
|
|
mh.Cells[buttonID].HumanID = humanInt
|
2019-05-12 23:01:22 -05:00
|
|
|
|
2019-05-13 02:08:59 -05:00
|
|
|
log.Println("buttonID, humanInt", buttonID, humanInt)
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func initRowTextColorColumn(mh *TableData, stringID int, colorID int, junk string, color ui.TableColor, cell TableColumnData) {
|
2019-05-12 22:25:55 -05:00
|
|
|
humanInt := cell.Index
|
|
|
|
|
|
|
|
// setup mapping from human readable indexes to internal libUI indexes
|
2019-05-13 01:56:53 -05:00
|
|
|
mh.Human[humanInt].Name = "EDIT"
|
|
|
|
mh.Human[humanInt].ColorID = colorID
|
|
|
|
mh.Human[humanInt].TextID = stringID
|
2019-05-12 22:25:55 -05:00
|
|
|
|
|
|
|
// text for Column humanInt
|
2019-05-13 01:49:26 -05:00
|
|
|
mh.Cells[stringID].Name = "EDIT"
|
|
|
|
mh.Cells[stringID].HumanID = humanInt
|
2019-05-08 17:28:40 -05:00
|
|
|
|
2019-05-13 01:49:26 -05:00
|
|
|
mh.Cells[colorID].Name = "COLOR"
|
|
|
|
mh.Cells[colorID].HumanID = humanInt
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 16:39:46 -05:00
|
|
|
func initRowTextColumn(mh *TableData, stringID int, junk string, cell TableColumnData) {
|
2019-05-12 22:25:55 -05:00
|
|
|
humanInt := cell.Index
|
|
|
|
|
|
|
|
// setup mapping from human readable indexes to internal libUI indexes
|
2019-05-13 01:56:53 -05:00
|
|
|
mh.Human[humanInt].Name = "EDIT"
|
|
|
|
mh.Human[humanInt].ColorID = -1
|
|
|
|
mh.Human[humanInt].TextID = stringID
|
2019-05-12 22:25:55 -05:00
|
|
|
|
2019-05-13 01:49:26 -05:00
|
|
|
mh.Cells[stringID].Name = "EDIT"
|
|
|
|
mh.Cells[stringID].HumanID = humanInt
|
2019-05-08 17:28:40 -05:00
|
|
|
}
|
2019-06-02 15:40:44 -05:00
|
|
|
|
|
|
|
func InitColumns(mh *TableData, parts []TableColumnData) {
|
|
|
|
tmpBTindex := 0
|
|
|
|
humanID := 0
|
|
|
|
for key, foo := range parts {
|
|
|
|
log.Println("key, foo =", key, foo)
|
|
|
|
|
|
|
|
parts[key].Index = humanID
|
|
|
|
humanID += 1
|
|
|
|
|
|
|
|
if (foo.CellType == "BG") {
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
|
|
|
initRowBTcolor (mh, tmpBTindex, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
|
|
|
initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
|
|
|
|
initRowTextColorColumn(mh, tmpBTindex, tmpBTindex + 1, parts[key].Heading, ui.TableColor{0.0, 0, 0.9, 1}, parts[key])
|
|
|
|
tmpBTindex += 2
|
|
|
|
} else if (foo.CellType == "TEXT") {
|
|
|
|
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString(""))
|
|
|
|
initRowTextColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData {
|
2021-10-08 07:36:53 -05:00
|
|
|
node := InitWindow(nil, gw, name, Yaxis)
|
2019-06-13 14:08:47 -05:00
|
|
|
|
2021-10-08 07:36:53 -05:00
|
|
|
return AddTableBox(node.box, name, rowcount, parts)
|
2019-06-13 14:28:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData) *TableData {
|
2019-06-02 15:40:44 -05:00
|
|
|
mh := new(TableData)
|
|
|
|
|
|
|
|
mh.RowCount = rowcount
|
|
|
|
mh.Rows = make([]RowData, mh.RowCount)
|
|
|
|
|
|
|
|
InitColumns(mh, parts)
|
|
|
|
|
|
|
|
model := ui.NewTableModel(mh)
|
|
|
|
table := ui.NewTable(
|
|
|
|
&ui.TableParams{
|
|
|
|
Model: model,
|
|
|
|
RowBackgroundColorModelColumn: 0, // Row Background color is always index zero
|
|
|
|
})
|
|
|
|
|
|
|
|
tmpBTindex := 0
|
|
|
|
for key, foo := range parts {
|
|
|
|
log.Println(key, foo)
|
|
|
|
if (foo.CellType == "BG") {
|
|
|
|
} else if (foo.CellType == "BUTTON") {
|
|
|
|
tmpBTindex += 1
|
|
|
|
table.AppendButtonColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable)
|
|
|
|
} else if (foo.CellType == "TEXTCOLOR") {
|
|
|
|
tmpBTindex += 1
|
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable,
|
|
|
|
&ui.TableTextColumnOptionalParams{
|
|
|
|
ColorModelColumn: tmpBTindex + 1,
|
|
|
|
});
|
|
|
|
tmpBTindex += 1
|
|
|
|
} else if (foo.CellType == "TEXT") {
|
|
|
|
tmpBTindex += 1
|
|
|
|
table.AppendTextColumn(foo.Heading, tmpBTindex, ui.TableModelColumnAlwaysEditable, nil)
|
|
|
|
} else {
|
|
|
|
panic("I don't know what this is in initColumnNames")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 14:28:34 -05:00
|
|
|
// is this needed?
|
|
|
|
// gw.BoxMap[name] = box
|
2019-06-13 14:08:47 -05:00
|
|
|
mh.Box = box
|
2019-06-02 15:40:44 -05:00
|
|
|
|
2019-06-13 14:08:47 -05:00
|
|
|
box.UiBox.Append(table, true)
|
2019-06-02 15:40:44 -05:00
|
|
|
|
|
|
|
return mh
|
|
|
|
}
|