From: ewt Date: Fri, 12 Sep 1997 02:19:53 +0000 (+0000) Subject: added newtCenteredWindow() and newtGridWrappedWindow() X-Git-Tag: r0-12~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f16e164f338bb9f07c3237c069f8130ae801d1d5;p=thirdparty%2Fnewt.git added newtCenteredWindow() and newtGridWrappedWindow() --- diff --git a/grid.c b/grid.c index 3f84450..d5e654c 100644 --- 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 cb5a3b6..c966e99 100644 --- 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 f7b4435..f0d65c8 100644 --- 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" { */ diff --git a/testgrid.c b/testgrid.c index a36cba3..fb49eb0 100644 --- a/testgrid.c +++ b/testgrid.c @@ -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);