field->padTop = padTop;
field->padBottom = padBottom;
field->anchor = anchor;
+ field->flags = flags;
grid->width = grid->height = -1;
}
+static void distSpace(int extra, int items, int * list) {
+ int all, some, i;
+
+ all = extra / items;
+ some = extra % items;
+ for (i = 0; i < items; i++) {
+ list[i] += all;
+ if (some) {
+ list[i]++;
+ some--;
+ }
+ }
+}
+
static void shuffleGrid(newtGrid grid, int left, int top, int set) {
struct gridField * field;
int row, col;
if (field->type == NEWT_GRID_SUBGRID) {
/* we'll have to redo this later */
if (field->u.grid->height == -1)
- shuffleGrid(field->u.grid, left, top, 0);
+ shuffleGrid(field->u.grid, 0, 0, 0);
j = field->u.grid->height;
} else {
j = field->u.co->height;
j += field->padTop + field->padBottom;
i += j;
- if (j > heights[col]) heights[col] = j;
+ if (j > heights[row]) heights[row] = j;
}
if (i > minHeight) minHeight = i;
if (!set) return;
+ distSpace(grid->width - minWidth, grid->cols, widths);
+ distSpace(grid->height - minHeight, grid->rows, heights);
+
thisTop = top;
for (row = 0; row < grid->rows; row++) {
i = 0;
x = thisLeft + field->padLeft;
remx = widths[col] - field->padLeft - field->padRight;
y = thisTop + field->padTop;
- remy = heights[col] - field->padTop - field->padBottom;
+ remy = heights[row] - field->padTop - field->padBottom;
if (field->type == NEWT_GRID_SUBGRID) {
remx -= field->u.grid->width;
remy -= field->u.co->height;
}
- if (field->anchor & NEWT_ANCHOR_RIGHT)
- x += remx;
- else if (!(field->anchor & NEWT_ANCHOR_LEFT))
- x += (remx / 2);
-
- if (field->anchor & NEWT_ANCHOR_BOTTOM)
- y += remx;
- else if (!(field->anchor & NEWT_ANCHOR_TOP))
- y += (remy / 2);
+ if (!(field->flags & NEWT_GRID_FLAG_GROWX)) {
+ if (field->anchor & NEWT_ANCHOR_RIGHT)
+ x += remx;
+ else if (!(field->anchor & NEWT_ANCHOR_LEFT))
+ x += (remx / 2);
+ }
+ if (!(field->flags & NEWT_GRID_FLAG_GROWY)) {
+ if (field->anchor & NEWT_ANCHOR_BOTTOM)
+ y += remx;
+ else if (!(field->anchor & NEWT_ANCHOR_TOP))
+ y += (remy / 2);
+ }
if (field->type == NEWT_GRID_SUBGRID) {
+ if (field->flags & NEWT_GRID_FLAG_GROWX)
+ field->u.grid->width = widths[col] - field->padLeft
+ - field->padRight;
+ if (field->flags & NEWT_GRID_FLAG_GROWY)
+ field->u.grid->height = heights[col] - field->padTop
+ - field->padBottom;
+
shuffleGrid(field->u.grid, x, y, 1);
} else {
field->u.co->left = x;
}
void newtGridPlace(newtGrid grid, int left, int top) {
- grid->width = grid->height = -1;
shuffleGrid(grid, left, top, 1);
}
free(grid);
}
+void newtGridGetSize(newtGrid grid, int * width, int * height) {
+ if (grid->width == -1 || grid->height == -1) {
+ grid->width = grid->height = -1;
+ shuffleGrid(grid, 0, 0, 1);
+ }
+
+ *width = grid->width;
+ *height = grid->height;
+}
int flags);
void newtGridPlace(newtGrid grid, int left, int top);
void newtGridFree(newtGrid grid, int recurse);
+void newtGridGetSize(newtGrid grid, int * width, int * height);
#ifdef __cplusplus
} /* End of extern "C" { */
int main(void) {
newtComponent b1, b2, b3, b4;
- newtComponent answer, f;
- newtGrid grid;
+ newtComponent answer, f, t;
+ newtGrid grid, subgrid;
newtInit();
newtCls();
newtFormDestroy(f);
newtPopWindow();
+
+ newtOpenWindow(10, 5, 45, 15, "another example");
+
+ t = newtTextbox(-1, -1, 40, 5, 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 "
+ "fox jumped over the lazy dog?");
+
+ b1 = newtButton(-1, -1, "Okay");
+ b2 = newtButton(-1, -1, "Cancel");
+
+ grid = newtCreateGrid(1, 2);
+ subgrid = newtCreateGrid(2, 1);
+
+ 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, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
+ NEWT_GRID_FLAG_GROWX);
+ newtGridPlace(grid, 1, 1);
+
+ f = newtForm(NULL, NULL, 0);
+ newtFormAddComponents(f, b1, t, b2, NULL);
+ answer = newtRunForm(f);
+
newtFinished();
return 0;
newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0);
tb->sb->ops->draw(tb->sb);
}
+
+ SLsmg_set_color(NEWT_COLORSET_TEXTBOX);
for (i = 0; (i + tb->topLine) < tb->numLines && i < c->height; i++) {
newtGotorc(c->top + i, c->left);