make a common column init()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-13 00:46:11 -07:00
parent 5ec1416d20
commit 2ea414bb14
1 changed files with 34 additions and 44 deletions

78
gui.go
View File

@ -43,18 +43,37 @@ func AddNewTab(mytab *ui.Tab, newbox ui.Control, tabOffset int) {
mytab.SetMargined(tabOffset, true) mytab.SetMargined(tabOffset, true)
} }
func initColumnNames(mh *TableData, cellJWC string, junk string) { func InitColumns(mh *TableData, parts []InputData) {
if (cellJWC == "BG") { tmpBTindex := 0
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{}) humanID := 0
} else if (cellJWC == "BUTTON") { for key, foo := range parts {
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString("")) log.Println("key, foo =", key, foo)
} else if (cellJWC == "TEXTCOLOR") { // log.Println("mh.Cells =", mh.Cells)
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString("")) // log.Println("mh.Human =", mh.Human)
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableColor{})
} else if (cellJWC == "TEXT") { parts[key].Index = humanID
mh.generatedColumnTypes = append(mh.generatedColumnTypes, ui.TableString("")) humanID += 1
} else {
panic("I don't know what this is in initColumnNames") 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")
}
} }
} }
@ -64,47 +83,18 @@ func AddTableTab(mytab *ui.Tab, mytabcount int, name string, rowcount int, parts
mh.RowCount = rowcount mh.RowCount = rowcount
mh.Rows = make([]RowData, mh.RowCount) mh.Rows = make([]RowData, mh.RowCount)
tmpBTindex := 0 InitColumns(mh, parts)
humanID := 0
for key, foo := range parts {
log.Println("key, foo =", key, foo)
// log.Println("mh.Cells =", mh.Cells)
// log.Println("mh.Human =", mh.Human)
initColumnNames(mh, foo.CellType, foo.Heading)
parts[key].Index = humanID
humanID += 1
if (foo.CellType == "BG") {
initRowBTcolor (mh, tmpBTindex, parts[key])
tmpBTindex += 1
} else if (foo.CellType == "BUTTON") {
initRowButtonColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
tmpBTindex += 1
} else if (foo.CellType == "TEXTCOLOR") {
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") {
initRowTextColumn (mh, tmpBTindex, parts[key].Heading, parts[key])
tmpBTindex += 1
} else {
panic("I don't know what this is in initColumnNames")
}
}
tmpBTindex = 0
humanID = 0
model := ui.NewTableModel(mh) model := ui.NewTableModel(mh)
table := ui.NewTable( table := ui.NewTable(
&ui.TableParams{ &ui.TableParams{
Model: model, Model: model,
RowBackgroundColorModelColumn: tmpBTindex, RowBackgroundColorModelColumn: 0, // Row Background color is always index zero
}) })
tmpBTindex := 0
for key, foo := range parts { for key, foo := range parts {
log.Println(key, foo) log.Println(key, foo)
initColumnNames(mh, foo.CellType, foo.Heading)
if (foo.CellType == "BG") { if (foo.CellType == "BG") {
} else if (foo.CellType == "BUTTON") { } else if (foo.CellType == "BUTTON") {
tmpBTindex += 1 tmpBTindex += 1