libui/test/spaced.c

126 lines
1.8 KiB
C
Raw Normal View History

// 22 april 2015
#include "test.h"
struct thing {
void *ptr;
int type;
};
static struct thing *things = NULL;
static uintmax_t len = 0;
static uintmax_t cap = 0;
2015-04-22 16:54:05 -05:00
#define grow 32
static void *append(void *thing, int type)
{
if (len >= cap) {
cap += grow;
2015-04-22 16:54:05 -05:00
things = (struct thing *) realloc(things, cap * sizeof (struct thing));
if (things == NULL)
die("reallocating things array in test/spaced.c append()");
}
things[len].ptr = thing;
things[len].type = type;
len++;
return things[len - 1].ptr;
}
enum types {
window,
box,
tab,
};
void setSpaced(int spaced)
{
uintmax_t i;
void *p;
for (i = 0; i < len; i++) {
p = things[i].ptr;
2015-04-22 16:54:05 -05:00
switch (things[i].type) {
case window:
uiWindowSetMargined(uiWindow(p), spaced);
break;
case box:
uiBoxSetPadded(uiBox(p), spaced);
break;
case tab:
// TODO
break;
}
}
}
void querySpaced(char out[12]) // more than enough
{
int m = 0;
int p = 0;
uintmax_t i;
void *pp;
for (i = 0; i < len; i++) {
pp = things[i].ptr;
switch (things[i].type) {
case window:
m = uiWindowMargined(uiWindow(pp));
break;
case box:
p = uiBoxPadded(uiBox(pp));
break;
}
if (m && p) // cheap attempt at breaking early
break;
}
out[0] = 'm';
out[1] = ' ';
out[2] = '0';
if (m)
out[2] = '1';
out[3] = ' ';
out[4] = 'p';
out[5] = ' ';
out[6] = '0';
if (p)
out[6] = '1';
out[7] = '\0';
}
uiWindow *newWindow(const char *title, int width, int height, int hasMenubar)
{
uiWindow *w;
w = uiNewWindow(title, width, height, hasMenubar);
append(w, window);
return w;
}
uiBox *newHorizontalBox(void)
{
uiBox *b;
b = uiNewHorizontalBox();
append(b, box);
return b;
}
uiBox *newVerticalBox(void)
{
uiBox *b;
b = uiNewVerticalBox();
append(b, box);
return b;
}
uiTab *newTab(void)
{
uiTab *t;
t = uiNewTab();
append(t, tab);
return t;
}