aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/test/main.c
blob: 18774dcda243991cabddd0f67ededbbfb9916a9a (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
178
179
180
// 22 april 2015
#include "test.h"

// TODOs
// - blank page affects menus negatively on Windows

void die(const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	fprintf(stderr, "[test program] ");
	vfprintf(stderr, fmt, ap);
	fprintf(stderr, "\n");
	va_end(ap);
	abort();
}

int onClosing(uiWindow *w, void *data)
{
	printf("in onClosing()\n");
	uiQuit();
	return 1;
}

int onShouldQuit(void *data)
{
	printf("in onShouldQuit()\n");
	if (uiMenuItemChecked(shouldQuitItem)) {
		uiControlDestroy(uiControl(data));
		return 1;
	}
	return 0;
}

uiBox *mainBox;
uiTab *mainTab;

uiBox *(*newhbox)(void);
uiBox *(*newvbox)(void);

int main(int argc, char *argv[])
{
	uiInitOptions o;
	int i;
	const char *err;
	uiWindow *w;
	uiBox *page2, *page3, *page4, *page5;
	uiBox *page6, *page7, *page8, *page9, *page10;
	uiBox *page11, *page12, *page13;
	uiTab *page14;
	uiBox *page15;
	uiBox *page16;
	uiTab *outerTab;
	uiTab *innerTab;
	int nomenus = 0;
	int startspaced = 0;
	int steps = 0;

	newhbox = uiNewHorizontalBox;
	newvbox = uiNewVerticalBox;

	memset(&o, 0, sizeof (uiInitOptions));
	for (i = 1; i < argc; i++)
		if (strcmp(argv[i], "nomenus") == 0)
			nomenus = 1;
		else if (strcmp(argv[i], "startspaced") == 0)
			startspaced = 1;
		else if (strcmp(argv[i], "swaphv") == 0) {
			newhbox = uiNewVerticalBox;
			newvbox = uiNewHorizontalBox;
		} else if (strcmp(argv[i], "steps") == 0)
			steps = 1;
		else {
			fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]);
			return 1;
		}

	err = uiInit(&o);
	if (err != NULL) {
		fprintf(stderr, "error initializing ui: %s\n", err);
		uiFreeInitError(err);
		return 1;
	}

	if (!nomenus)
		initMenus();

	w = newWindow("Main Window", 320, 240, 1);
	uiWindowOnClosing(w, onClosing, NULL);
	printf("main window %p\n", (void *) w);

	uiOnShouldQuit(onShouldQuit, w);

	mainBox = newHorizontalBox();
	uiWindowSetChild(w, uiControl(mainBox));

	outerTab = newTab();
	uiBoxAppend(mainBox, uiControl(outerTab), 1);

	mainTab = newTab();
	uiTabAppend(outerTab, "Pages 1-5", uiControl(mainTab));

	// page 1 uses page 2's uiGroup
	page2 = makePage2();

	makePage1(w);
	uiTabAppend(mainTab, "Page 1", uiControl(page1));

	uiTabAppend(mainTab, "Page 2", uiControl(page2));

	uiTabAppend(mainTab, "Empty Page", uiControl(uiNewHorizontalBox()));

	page3 = makePage3();
	uiTabAppend(mainTab, "Page 3", uiControl(page3));

	page4 = makePage4();
	uiTabAppend(mainTab, "Page 4", uiControl(page4));

	page5 = makePage5(w);
	uiTabAppend(mainTab, "Page 5", uiControl(page5));

	innerTab = newTab();
	uiTabAppend(outerTab, "Pages 6-10", uiControl(innerTab));

	page6 = makePage6();
	uiTabAppend(innerTab, "Page 6", uiControl(page6));

	page7 = makePage7();
	uiTabAppend(innerTab, "Page 7", uiControl(page7));

	page8 = makePage8();
	uiTabAppend(innerTab, "Page 8", uiControl(page8));

	page9 = makePage9();
	uiTabAppend(innerTab, "Page 9", uiControl(page9));

	page10 = makePage10();
	uiTabAppend(innerTab, "Page 10", uiControl(page10));

	innerTab = newTab();
	uiTabAppend(outerTab, "Pages 11-15", uiControl(innerTab));

//	page11 = makePage11();
//	uiTabAppend(innerTab, "Page 11", uiControl(page11));

	page12 = makePage12();
	uiTabAppend(innerTab, "Page 12", uiControl(page12));

	page13 = makePage13();
	uiTabAppend(innerTab, "Page 13", uiControl(page13));

	page14 = makePage14();
	uiTabAppend(innerTab, "Page 14", uiControl(page14));

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

	uiControlShow(uiControl(w));
	if (!steps)
		uiMain();
	else {
		uiMainSteps();
		while (uiMainStep(1))
			;
	}
	printf("after uiMain()\n");
	uiUninit();
	printf("after uiUninit()\n");
	return 0;
}