From b21ec6cf6b4d6afa8cd7a51c2a710648027c8cde Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 21 Jun 2016 22:22:13 -0400 Subject: [PATCH] Laid the foundation for uiTable: common code and a test. Now to start actually implementing it. --- common/CMakeLists.txt | 1 + common/table.c | 13 +++++++++ test/CMakeLists.txt | 1 + test/main.c | 9 +++++- test/page16.c | 68 +++++++++++++++++++++++++++++++++++++++++++ test/test.h | 3 ++ 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 common/table.c create mode 100644 test/page16.c diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 91d79493..7f704032 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -6,6 +6,7 @@ list(APPEND _LIBUI_SOURCES common/debug.c common/matrix.c common/shouldquit.c + common/table.c common/userbugs.c ) set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) diff --git a/common/table.c b/common/table.c new file mode 100644 index 00000000..01abe36b --- /dev/null +++ b/common/table.c @@ -0,0 +1,13 @@ +// 21 june 2016 +#include "uipriv.h" + +uiTableColumn *uiTableAppendTextColumn(uiTable *t, const char *name, int modelColumn) +{ + uiTableColumn *tc; + uiTableCellPart *part; + + part = uiNewTableTextPart(modelColumn); + tc = uiTableAppendColumn(t, name); + uiTableColumnAppend(tc, part, 1); + return tc; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e4924bb3..596f02ff 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,6 +26,7 @@ _add_exec(tester page13.c page14.c page15.c + page16.c spaced.c ${_TEST_RESOURCES_RC} ) diff --git a/test/main.c b/test/main.c index 43b54ad0..f33f30ab 100644 --- a/test/main.c +++ b/test/main.c @@ -50,6 +50,7 @@ int main(int argc, char *argv[]) uiBox *page11, *page12, *page13; uiTab *page14; uiBox *page15; + uiBox *page16; uiTab *outerTab; uiTab *innerTab; int nomenus = 0; @@ -138,7 +139,7 @@ int main(int argc, char *argv[]) uiTabAppend(innerTab, "Page 10", uiControl(page10)); innerTab = newTab(); - uiTabAppend(outerTab, "Pages 11-?", uiControl(innerTab)); + uiTabAppend(outerTab, "Pages 11-15", uiControl(innerTab)); // page11 = makePage11(); // uiTabAppend(innerTab, "Page 11", uiControl(page11)); @@ -155,6 +156,12 @@ int main(int argc, char *argv[]) page15 = makePage15(w); uiTabAppend(innerTab, "Page 15", uiControl(page15)); + innerTab = newTab(); + uiTabAppend(outerTab, "Pages 16-?", uiControl(innerTab)); + + page16 = makePage16(); + uiTabAppend(innerTab, "Page 16", uiControl(page16)); + if (startspaced) setSpaced(1); diff --git a/test/page16.c b/test/page16.c new file mode 100644 index 00000000..0dd74421 --- /dev/null +++ b/test/page16.c @@ -0,0 +1,68 @@ +// 21 june 2016 +#include "test.h" + +static uiTableModelHandler mh; + +static nt modelNumColumns(uiTableModel *m) +{ + return 3; +} + +static uiTableModelColumnType modelColumnType(uiTableModel *m, int column) +{ + return uiTableModelColumnString; +} + +static int modelNumRows(uiTableModel *m) +{ + return 15; +} + +static void *modelCellValue(uiTableModel *m, int row, int col) +{ + char buf[256]; + + switch (col) { + case 0: + sprintf(buf, "Row %d", row); + break; + case 1: + case 2: + strcpy(buf, "Part"); + break; + } + return uiTableModelStrdup(buf); +} + +static void modelSetCellValue(uiTableModel *m, int row, int col, void *val) +{ + // not implemented yet +} + +uiBox *makePage16(void) +{ + uiBox *page16; + uiTableModel *m; + uiTable *t; + uiTableColumn *tc; + + page16 = newVerticalBox(); + + mh.NumColumns = modelNumColumns; + mh.ColumnType = modelColumnType; + mh.NumRows = modelNumRows; + mh.CellValue = modelCellValue; + mh.SetCellValue = modelSetCellValue; + m = uiNewTableModel(&mh); + + t = uiNewTable(m); + uiBoxAppend(page16, uiControl(t), 1); + + uiTableAppendTextColumn(t, "Column 1", 0); + + tc = uiTableAppendColumn(t, "Column 2"); + uiTableColumnAppend(tc, uiNewTableTextPart(1), 0); + uiTableColumnAppend(tc, uiNewTableTextPart(2), 1); + + return page16; +} diff --git a/test/test.h b/test/test.h index 66b1baa7..427b3561 100644 --- a/test/test.h +++ b/test/test.h @@ -89,3 +89,6 @@ extern uiTab *makePage14(void); // page15.c extern uiBox *makePage15(uiWindow *); + +// page16.c +extern uiBox *makePage16(void);