]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added newtCenteredWindow() and newtGridWrappedWindow()
authorewt <ewt>
Fri, 12 Sep 1997 02:19:53 +0000 (02:19 +0000)
committerewt <ewt>
Fri, 12 Sep 1997 02:19:53 +0000 (02:19 +0000)
grid.c
newt.c
newt.h
testgrid.c

diff --git a/grid.c b/grid.c
index 3f844503995ea136aa557a7870b97e661c6de890..d5e654cbae5a516282d4b67fbfe0a71c52e4a95e 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -233,3 +233,11 @@ void newtGridGetSize(newtGrid grid, int * width, int * height) {
     *width = grid->width;
     *height = grid->height;
 }
+
+void newtGridWrappedWindow(newtGrid grid, char * title) {
+    int width, height;
+
+    newtGridGetSize(grid, &width, &height);
+    newtCenteredWindow(width + 2, height + 2, title);
+    newtGridPlace(grid, 1, 1);
+}
diff --git a/newt.c b/newt.c
index cb5a3b6a05d2adc777bcef647c1e45a5a3920415..c966e9975d5f6680b3e90d830776e96cb8a3d880 100644 (file)
--- a/newt.c
+++ b/newt.c
@@ -376,6 +376,21 @@ int newtOpenWindow(int left, int top, int width, int height,
     return 0;
 }
 
+int newtCenteredWindow(int width, int height, const char * title) {
+    int top, left;
+
+    top = (SLtt_Screen_Rows - height) / 2;
+
+    /* I don't know why, but this seems to look better */ 
+    if ((SLtt_Screen_Rows % 2) && (top % 2)) top--;
+
+    left = (SLtt_Screen_Cols - width) / 2;
+
+    newtOpenWindow(left, top, width, height, title);
+
+    return 0;
+}
+
 void newtPopWindow(void) {
     int j, row, col;
     int n = 0;    
diff --git a/newt.h b/newt.h
index f7b44350112fb69167ca9515e381d9e2fc963aa1..f0d65c8153cc54c09667be38dfec55f6d2f0042d 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -94,6 +94,7 @@ void newtDelay(int usecs);
 /* top, left are *not* counting the border */
 int newtOpenWindow(int left, int top, int width, int height, 
                          const char * title);
+int newtCenteredWindow(int width, int height, const char * title);
 void newtPopWindow(void);
 void newtSetColors(struct newtColors colors);
 void newtRefresh(void);
@@ -240,6 +241,7 @@ void newtGridSetField(newtGrid grid, int col, int row,
 void newtGridPlace(newtGrid grid, int left, int top);
 void newtGridFree(newtGrid grid, int recurse);
 void newtGridGetSize(newtGrid grid, int * width, int * height);
+void newtGridWrappedWindow(newtGrid grid, char * title);
 
 #ifdef __cplusplus
 } /* End of extern "C" { */
index a36cba37f89a510afd83cb067af65c9a8d1eeebd..fb49eb0ac374249783d51000d040e1c19ad91848 100644 (file)
@@ -38,9 +38,7 @@ int main(void) {
 
     newtPopWindow();
 
-    newtOpenWindow(10, 5, 45, 15, "another example");
-
-    t = newtTextbox(-1, -1, 40, 5, NEWT_FLAG_WRAP);
+    t = newtTextbox(-1, -1, 40, 4, NEWT_FLAG_WRAP);
     newtTextboxSetText(t, "This is a quite a bit of text. It is 40 "
                          "columns long, so some wrapping should be "
                          "done. Did you know that the quick, brown "
@@ -55,10 +53,10 @@ int main(void) {
     newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
     newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
 
-    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 0, 0, 0);
+    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
     newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
                        NEWT_GRID_FLAG_GROWX);
-    newtGridPlace(grid, 1, 1);
+    newtGridWrappedWindow(grid, "another example");
 
     f = newtForm(NULL, NULL, 0);
     newtFormAddComponents(f, b1, t, b2, NULL);