Laid the foundation for uiTable: common code and a test. Now to start actually implementing it.

This commit is contained in:
Pietro Gagliardi 2016-06-21 22:22:13 -04:00
parent aa2e8cf4f5
commit b21ec6cf6b
6 changed files with 94 additions and 1 deletions

View File

@ -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)

13
common/table.c Normal file
View File

@ -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;
}

View File

@ -26,6 +26,7 @@ _add_exec(tester
page13.c
page14.c
page15.c
page16.c
spaced.c
${_TEST_RESOURCES_RC}
)

View File

@ -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);

68
test/page16.c Normal file
View File

@ -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;
}

View File

@ -89,3 +89,6 @@ extern uiTab *makePage14(void);
// page15.c
extern uiBox *makePage15(uiWindow *);
// page16.c
extern uiBox *makePage16(void);