diff --git a/Makefile b/Makefile index 96c30fc..8eb4e7c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -all: +run: + go run *.go + +gaper: # 'gaper' is a simple and smart golang tool that just rebuilds every time you change a file # go get -u github.com/maxcnunes/gaper gaper diff --git a/main.go b/main.go index f283d24..60c9527 100644 --- a/main.go +++ b/main.go @@ -288,17 +288,20 @@ func setupUI() { tab.SetMargined(0, true) tab.Append("Ceph", makeButtonsPage(getPhysicalMachines("d"))) - tab.SetMargined(0, true) - - tab.Append("k8s Pods", makeButtonsPage(getPods(".wit.com"))) - tab.SetMargined(0, true) - - tab.Append("VMs", makeNumbersPage()) tab.SetMargined(1, true) - tab.Append("Data Choosers", makeDataChoosersPage()) + tab.Append("k8s Pods", makeButtonsPage(getPods(".wit.com"))) tab.SetMargined(2, true) + tab.Append("VMs", makeNumbersPage()) + tab.SetMargined(3, true) + + tab.Append("Data Choosers", makeDataChoosersPage()) + tab.SetMargined(4, true) + + tab.Append("Table Test", maketable()) + tab.SetMargined(5, true) + mainwin.Show() } diff --git a/table.go b/table.go new file mode 100644 index 0000000..b696903 --- /dev/null +++ b/table.go @@ -0,0 +1,137 @@ +// 26 august 2018 + +// +build OMIT + +package main + +import "fmt" +import "github.com/andlabs/ui" + +type modelHandler struct { + row9Text string + yellowRow int + checkStates [15]int +} + +func newModelHandler() *modelHandler { + m := new(modelHandler) + m.row9Text = "You can edit this one" + m.yellowRow = -1 + return m +} + +func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue { + return []ui.TableValue{ + ui.TableString(""), // column 0 text + ui.TableString(""), // column 1 text + ui.TableString(""), // column 2 text + ui.TableColor{}, // row background color + ui.TableColor{}, // column 1 text color + ui.TableImage{}, // column 1 image + ui.TableString(""), // column 4 button text + ui.TableInt(0), // column 3 checkbox state + ui.TableInt(0), // column 5 progress + } +} + +func (mh *modelHandler) NumRows(m *ui.TableModel) int { + return 15 +} + +var img [2]*ui.Image + +func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue { + switch column { + case 0: + return ui.TableString(fmt.Sprintf("Row %d", row)) + case 1: + return ui.TableString("Colors!") + case 7: + return ui.TableInt(mh.checkStates[row]) + case 8: + if row == 0 { + return ui.TableInt(0) + } + if row == 13 { + return ui.TableInt(100) + } + if row == 14 { + return ui.TableInt(-1) + } + return ui.TableInt(50) + case 5: + if row < 8 { + return ui.TableImage{img[0]} + } + return ui.TableImage{img[1]} + case 4: + if (row % 2) == 1 { + return ui.TableColor{0.5, 0, 0.75, 1} + } + return nil + case 3: + if row == mh.yellowRow { + return ui.TableColor{1, 1, 0, 1} + } + if row == 3 { + return ui.TableColor{1, 0, 0, 1} + } + if row == 11 { + return ui.TableColor{0, 0.5, 1, 0.5} + } + return nil + case 2: + if row == 9 { + return ui.TableString(mh.row9Text) + } + return ui.TableString("Editing this won't change anything") + case 6: + return ui.TableString("Make Yellow") + } + panic("unreachable") +} + +func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) { + if row == 9 && column == 2 { + mh.row9Text = string(value.(ui.TableString)) + } + if column == 6 { // row background color + prevYellowRow := mh.yellowRow + mh.yellowRow = row + if prevYellowRow != -1 { + m.RowChanged(prevYellowRow) + } + m.RowChanged(mh.yellowRow) + } + if column == 7 { // checkboxes + mh.checkStates[row] = int(value.(ui.TableInt)) + } +} + +func maketable() *ui.Table { + img[0] = ui.NewImage(16, 16) + img[1] = ui.NewImage(16, 16) + + mh := newModelHandler() + model := ui.NewTableModel(mh) + + table := ui.NewTable( + &ui.TableParams{ + Model: model, + RowBackgroundColorModelColumn: 3, + }) + + table.AppendTextColumn("Column 1", 0, ui.TableModelColumnNeverEditable, nil) + + table.AppendImageTextColumn("Column 2", 5, + 1, ui.TableModelColumnNeverEditable, &ui.TableTextColumnOptionalParams{ + ColorModelColumn: 4, + }); + + table.AppendTextColumn("Editable", 2, ui.TableModelColumnAlwaysEditable, nil) + table.AppendCheckboxColumn("Checkboxes", 7, ui.TableModelColumnAlwaysEditable) + table.AppendButtonColumn("Buttons", 6, ui.TableModelColumnAlwaysEditable) + table.AppendProgressBarColumn("Progress Bar", 8) + + return table +}