aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/test/page5.c
blob: 9bc1105a5a9f01a3a12dc915645bbb16f5cc390d (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
// 22 may 2015
#include "test.h"

static uiWindow *parent;

static void openFile(uiButton *b, void *data)
{
	char *fn;

	fn = uiOpenFile(parent);
	if (fn == NULL)
		uiLabelSetText(uiLabel(data), "(cancelled)");
	else {
		uiLabelSetText(uiLabel(data), fn);
		uiFreeText(fn);
	}
}

static void saveFile(uiButton *b, void *data)
{
	char *fn;

	fn = uiSaveFile(parent);
	if (fn == NULL)
		uiLabelSetText(uiLabel(data), "(cancelled)");
	else {
		uiLabelSetText(uiLabel(data), fn);
		uiFreeText(fn);
	}
}

static uiEntry *title, *description;

static void msgBox(uiButton *b, void *data)
{
	char *t, *d;

	t = uiEntryText(title);
	d = uiEntryText(description);
	uiMsgBox(parent, t, d);
	uiFreeText(d);
	uiFreeText(t);
}

static void msgBoxError(uiButton *b, void *data)
{
	char *t, *d;

	t = uiEntryText(title);
	d = uiEntryText(description);
	uiMsgBoxError(parent, t, d);
	uiFreeText(d);
	uiFreeText(t);
}

uiBox *makePage5(uiWindow *pw)
{
	uiBox *page5;
	uiBox *hbox;
	uiButton *button;
	uiLabel *label;

	parent = pw;

	page5 = newVerticalBox();

#define D(n, f) \
	hbox = newHorizontalBox(); \
	button = uiNewButton(n); \
	label = uiNewLabel(""); \
	uiButtonOnClicked(button, f, label); \
	uiBoxAppend(hbox, uiControl(button), 0); \
	uiBoxAppend(hbox, uiControl(label), 0); \
	uiBoxAppend(page5, uiControl(hbox), 0);

	D("Open File", openFile);
	D("Save File", saveFile);

	title = uiNewEntry();
	uiEntrySetText(title, "Title");
	description = uiNewEntry();
	uiEntrySetText(description, "Description");

	hbox = newHorizontalBox();
	button = uiNewButton("Message Box");
	uiButtonOnClicked(button, msgBox, NULL);
	uiBoxAppend(hbox, uiControl(button), 0);
	uiBoxAppend(hbox, uiControl(title), 0);
	uiBoxAppend(page5, uiControl(hbox), 0);

	hbox = newHorizontalBox();
	button = uiNewButton("Error Box");
	uiButtonOnClicked(button, msgBoxError, NULL);
	uiBoxAppend(hbox, uiControl(button), 0);
	uiBoxAppend(hbox, uiControl(description), 0);
	uiBoxAppend(page5, uiControl(hbox), 0);

	return page5;
}