From 96348bc86d8dc7bebb108578cdae444b7d560535 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 7 May 2019 18:16:58 -0700 Subject: [PATCH] move more of the table Demo code into it's own file Signed-off-by: Jeff Carr --- table.go | 95 --------------------------------------------- tableDemo.go | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 95 deletions(-) create mode 100644 tableDemo.go diff --git a/table.go b/table.go index e4fad14..56b3156 100644 --- a/table.go +++ b/table.go @@ -54,22 +54,6 @@ func standardColumnTypes() []ui.TableValue { } } -func demoColumnTypes() []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 - } -} - -var img [2]*ui.Image - func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue { switch column { case 0: @@ -83,56 +67,6 @@ func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue { return ui.TableString(fmt.Sprintf("jcarrbad %d", row)) } -func demoCellValue(mh *modelHandler, 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 { - // Red with .1 transparency - // R G B Trans - return ui.TableColor{1, 0, 0, .1} - } - if row == 11 { - return ui.TableColor{0, 0.5, 1, 0.5} - } - return nil - case 2: - return ui.TableString(mh.vms[row].hostname) - case 6: - return ui.TableString("Make Yellow") - } - panic("unreachable in demoCellValue()") -} - func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) { log.Println("SetCallValue() START") spew.Dump(m) @@ -161,35 +95,6 @@ func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui spew.Dump(m) } -func makeDemotable(name string) *ui.Table { - img[0] = ui.NewImage(16, 16) - img[1] = ui.NewImage(16, 16) - - mh := newDemoModelHandler() - mh.name = name - 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("hostname", 2, ui.TableModelColumnAlwaysEditable, nil) - table.AppendCheckboxColumn("Checkboxes", 7, ui.TableModelColumnAlwaysEditable) - table.AppendButtonColumn("Buttons", 6, ui.TableModelColumnAlwaysEditable) - table.AppendProgressBarColumn("Progress Bar", 8) - - return table -} - func newModelHandler(rows int) *modelHandler { mh := new(modelHandler) mh.rows = rows diff --git a/tableDemo.go b/tableDemo.go new file mode 100644 index 0000000..f5bb210 --- /dev/null +++ b/tableDemo.go @@ -0,0 +1,107 @@ +// based off andlabs/ui/examples/table.go + +package main + +import "fmt" +/* +import "log" +import "github.com/davecgh/go-spew/spew" +*/ + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +func demoColumnTypes() []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 + } +} + +var img [2]*ui.Image + +func demoCellValue(mh *modelHandler, 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 { + // Red with .1 transparency + // R G B Trans + return ui.TableColor{1, 0, 0, .1} + } + if row == 11 { + return ui.TableColor{0, 0.5, 1, 0.5} + } + return nil + case 2: + return ui.TableString(mh.vms[row].hostname) + case 6: + return ui.TableString("Make Yellow") + } + panic("unreachable in demoCellValue()") +} + +func makeDemotable(name string) *ui.Table { + img[0] = ui.NewImage(16, 16) + img[1] = ui.NewImage(16, 16) + + mh := newDemoModelHandler() + mh.name = name + 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("hostname", 2, ui.TableModelColumnAlwaysEditable, nil) + table.AppendCheckboxColumn("Checkboxes", 7, ui.TableModelColumnAlwaysEditable) + table.AppendButtonColumn("Buttons", 6, ui.TableModelColumnAlwaysEditable) + table.AppendProgressBarColumn("Progress Bar", 8) + + return table +}