aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/test/spaced.c
blob: 02db99aea71b38456e50c00578aaa1a84d64eccc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// 22 april 2015
#include "test.h"

struct thing {
	void *ptr;
	int type;
};

static struct thing *things = NULL;
static size_t len = 0;
static size_t cap = 0;

#define grow 32

static void *append(void *thing, int type)
{
	if (len >= cap) {
		cap += grow;
		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,
	group,
	form,
	grid,
};

void setSpaced(int spaced)
{
	size_t i;
	void *p;
	size_t j, n;

	for (i = 0; i < len; i++) {
		p = things[i].ptr;
		switch (things[i].type) {
		case window:
			uiWindowSetMargined(uiWindow(p), spaced);
			break;
		case box:
			uiBoxSetPadded(uiBox(p), spaced);
			break;
		case tab:
			n = uiTabNumPages(uiTab(p));
			for (j = 0; j < n; j++)
				uiTabSetMargined(uiTab(p), j, spaced);
			break;
		case group:
			uiGroupSetMargined(uiGroup(p), spaced);
			break;
		case form:
			uiFormSetPadded(uiForm(p), spaced);
			break;
		case grid:
			uiGridSetPadded(uiGrid(p), spaced);
			break;
		}
	}
}

void querySpaced(char out[12])		// more than enough
{
	int m = 0;
	int p = 0;
	size_t i;
	void *pp;
	size_t j, n;

	for (i = 0; i < len; i++) {
		pp = things[i].ptr;
		switch (things[i].type) {
		case window:
			if (uiWindowMargined(uiWindow(pp)))
				m++;
			break;
		case box:
			p = uiBoxPadded(uiBox(pp));
			break;
		case tab:
			n = uiTabNumPages(uiTab(pp));
			for (j = 0; j < n; j++)
				if (uiTabMargined(uiTab(pp), j))
					m++;
			break;
		case group:
			if (uiGroupMargined(uiGroup(pp)))
				m++;
			break;
		// TODO form
		// TODO grid
		}
	}

	out[0] = 'm';
	out[1] = ' ';
	out[2] = '0' + m;
	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 = (*newhbox)();
	append(b, box);
	return b;
}

uiBox *newVerticalBox(void)
{
	uiBox *b;

	b = (*newvbox)();
	append(b, box);
	return b;
}

uiTab *newTab(void)
{
	uiTab *t;

	t = uiNewTab();
	append(t, tab);
	return t;
}

uiGroup *newGroup(const char *text)
{
	uiGroup *g;

	g = uiNewGroup(text);
	append(g, group);
	return g;
}

uiForm *newForm(void)
{
	uiForm *f;

	f = uiNewForm();
	append(f, form);
	return f;
}

uiGrid *newGrid(void)
{
	uiGrid *g;

	g = uiNewGrid();
	append(g, grid);
	return g;
}