]> git.ipfire.org Git - thirdparty/newt.git/blob - testgrid.c
*** empty log message ***
[thirdparty/newt.git] / testgrid.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <signal.h>
5
6 #include "newt.h"
7
8 int main(void) {
9 newtComponent b1, b2, b3, b4;
10 newtComponent answer, f, t;
11 newtGrid grid, subgrid;
12 char * flowedText;
13 int textWidth, textHeight;
14
15 newtInit();
16 newtCls();
17 newtOpenWindow(2, 2, 40, 15, "first window");
18
19 b1 = newtButton(-1, -1, "Button 1");
20 b2 = newtButton(-1, -1, "Another Button");
21 b3 = newtButton(-1, -1, "But, but");
22 b4 = newtButton(-1, -1, "But what?");
23
24 f = newtForm(NULL, NULL, 0);
25
26 grid = newtCreateGrid(2, 2);
27 newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0,
28 NEWT_ANCHOR_RIGHT, 0);
29 newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
30 newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
31 newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);
32
33 newtGridPlace(grid, 1, 1);
34
35 newtFormAddComponents(f, b1, b2, b3, b4, NULL);
36
37 answer = newtRunForm(f);
38
39 newtFormDestroy(f);
40
41 newtPopWindow();
42
43 flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
44 "columns long, so some wrapping should be "
45 "done. Did you know that the quick, brown "
46 "fox jumped over the lazy dog?\n\n"
47 "In other news, it's pretty important that we "
48 "can properly force a line break.",
49 40, 5, 5, &textWidth, &textHeight);
50 t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
51 newtTextboxSetText(t, flowedText);
52 free(flowedText);
53
54
55 b1 = newtButton(-1, -1, "Okay");
56 b2 = newtButton(-1, -1, "Cancel");
57
58 grid = newtCreateGrid(1, 2);
59 subgrid = newtCreateGrid(2, 1);
60
61 newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
62 newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
63
64 newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
65 newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
66 NEWT_GRID_FLAG_GROWX);
67 newtGridWrappedWindow(grid, "another example");
68
69 f = newtForm(NULL, NULL, 0);
70 newtFormAddComponents(f, b1, t, b2, NULL);
71 answer = newtRunForm(f);
72
73 newtPopWindow();
74
75 newtWinMessage("Simple", "Ok", "This is a simple message window");
76
77 newtFinished();
78
79 return 0;
80 }