diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8d6ba03a..c6511e80 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,10 +9,6 @@ _add_exec(tester main.c menus.c page1.c - page10.c - page11.c - page12.c - page13.c page2.c page3.c page4.c @@ -24,6 +20,11 @@ _add_exec(tester page7c.c page8.c page9.c + page10.c + page11.c + page12.c + page13.c + page14.c spaced.c ${_TEST_RESOURCES_RC} ) diff --git a/test/main.c b/test/main.c index dea51663..63f21b86 100644 --- a/test/main.c +++ b/test/main.c @@ -48,6 +48,7 @@ int main(int argc, char *argv[]) uiBox *page2, *page3, *page4, *page5; uiBox *page6, *page7, *page8, *page9, *page10; uiBox *page11, *page12, *page13; + uiTab *page14; uiTab *outerTab; uiTab *innerTab; int nomenus = 0; @@ -144,6 +145,9 @@ int main(int argc, char *argv[]) page13 = makePage13(); uiTabAppend(innerTab, "Page 13", uiControl(page13)); + page14 = makePage14(); + uiTabAppend(innerTab, "Page 14", uiControl(page14)); + if (startspaced) setSpaced(1); diff --git a/test/page14.c b/test/page14.c new file mode 100644 index 00000000..babb9467 --- /dev/null +++ b/test/page14.c @@ -0,0 +1,82 @@ +// 9 june 2016 +#include "test.h" + +enum { + red, + green, + blue, + yellow, +}; + +static const struct { + double r; + double g; + double b; +} colors[] = { + { 1, 0, 0 }, + { 0, 0.5, 0 }, + { 0, 0, 1 }, + { 1, 1, 0 }, +}; + +static uiControl *testControl(const char *label, int color) +{ + uiColorButton *b; + + b = uiNewColorButton(); + uiColorButtonSetColor(b, colors[color].r, colors[color].g, colors[color].b, 1.0); + return uiControl(b); +} + +static uiControl *simpleGrid(void) +{ + uiGrid *g; + uiControl *t4; + + g = newGrid(); + + uiGridAppend(g, testControl("1", red), + 0, 0, 1, 1, + 0, uiAlignFill, 0, uiAlignFill); + uiGridAppend(g, testControl("2", green), + 1, 0, 1, 1, + 0, uiAlignFill, 0, uiAlignFill); + uiGridAppend(g, testControl("3", blue), + 2, 0, 1, 1, + 0, uiAlignFill, 0, uiAlignFill); + t4 = testControl("4", green); + uiGridAppend(g, t4, + 0, 1, 1, 1, + 0, uiAreaFill, 1, uiAreaFill); + uiGridInsertAt(g, testControl("5", blue), + t4, uiAtTrailing, 2, 1, + 0, uiAreaFill, 0, uiAreaFill); + uiGridAppend(g, testControl("6", yellow), + -1, 0, 1, 2, + 1, uiAreaFill, 0, uiAreaFill); + + return uiControl(g); +} + +static const struct { + const char *name; + uiControl *(*f)(void); +} pages[] = { + { "Simple Grid", simpleGrid }, // from GTK+ test/testgrid.c + { NULL, NULL }, +} + +uiTab *makePage14(void) +{ + uiTab *page14; + int i; + + page14 = newTab(); + + for (i = 0; pages[i].name != NULL; i++) + uiTabAppend(page14, + pages[i].name, + (*(pages[i].f))()); + + return page14; +} diff --git a/test/spaced.c b/test/spaced.c index 7eb34fab..a54a0089 100644 --- a/test/spaced.c +++ b/test/spaced.c @@ -32,6 +32,7 @@ enum types { tab, group, form, + grid, }; void setSpaced(int spaced) @@ -60,6 +61,9 @@ void setSpaced(int spaced) case form: uiFormSetPadded(uiForm(p), spaced); break; + case grid: + uiGridSetPadded(uiGrid(p), spaced); + break; } } } @@ -93,6 +97,7 @@ void querySpaced(char out[12]) // more than enough m++; break; // TODO form + // TODO grid } } @@ -161,3 +166,12 @@ uiForm *newForm(void) append(f, form); return f; } + +uiGrid *newGrid(void) +{ + uiGrid *g; + + g = uiNewGrid(); + append(g, grid); + return g; +} diff --git a/test/test.h b/test/test.h index b59879b9..2afe3e39 100644 --- a/test/test.h +++ b/test/test.h @@ -23,6 +23,7 @@ extern uiBox *newVerticalBox(void); extern uiTab *newTab(void); extern uiGroup *newGroup(const char *); extern uiForm *newForm(void); +extern uiGrid *newGrid(void); // menus.c extern uiMenuItem *shouldQuitItem; @@ -81,3 +82,6 @@ extern uiBox *makePage12(void); // page13.c extern uiBox *makePage13(void); + +// page14.c +extern uiTab *makePage14(void); diff --git a/ui.h b/ui.h index 00c5481b..20d23eee 100644 --- a/ui.h +++ b/ui.h @@ -627,6 +627,28 @@ _UI_EXTERN int uiFormPadded(uiForm *f); _UI_EXTERN void uiFormSetPadded(uiForm *f, int padded); _UI_EXTERN uiForm *uiNewForm(void); +_UI_ENUM(uiAlign) { + uiAlignFill, + uiAlignStart, + uiAlignCenter, + uiAlignEnd, +}; + +_UI_ENUM(uiAt) { + uiAtLeading, + uiAtTop, + uiAtTrailing, + uiAtBottom, +}; + +typedef struct uiGrid uiGrid; +#define uiGrid(this) ((uiGrid *) (this)) +_UI_EXTERN void uiGridAppend(uiGrid *g, uiControl *c, intmax_t left, intmax_t top, intmax_t xspan, intmax_t yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign); +_UI_EXTERN void uiGridInsertAt(uiGrid *g, uiControl *c, uiControl *existing, uiAt at, intmax_t xspan, intmax_t yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign); +_UI_EXTERN int uiGridPadded(uiGrid *g); +_UI_EXTERN void uiGridSetPadded(uiGrid *g, int padded); +_UI_EXTERN uiGrid *uiNewGrid(void); + #ifdef __cplusplus } #endif