Started uiGrid.

This commit is contained in:
Pietro Gagliardi 2016-06-09 17:15:59 -04:00
parent 04b83a2680
commit 075eae15e5
6 changed files with 131 additions and 4 deletions

View File

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

View File

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

82
test/page14.c Normal file
View File

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

View File

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

View File

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

22
ui.h
View File

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