Convenience function for creating a horizontal box.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 659
This commit is contained in:
Simon Howard 2006-09-24 13:07:30 +00:00
parent 681c7bee78
commit c083656d0e
2 changed files with 71 additions and 0 deletions

View file

@ -568,6 +568,74 @@ txt_table_t *TXT_NewTable(int columns)
return table;
}
// Create a horizontal table from a list of widgets.
txt_table_t *TXT_NewHorizBox(TXT_UNCAST_ARG(first_widget), ...)
{
TXT_CAST_ARG(txt_widget_t, first_widget);
txt_table_t *result;
va_list args;
int num_args;
// First, find the number of arguments to determine the width of
// the box.
va_start(args, TXT_UNCAST_ARG_NAME(first_widget));
num_args = 1;
for (;;)
{
txt_widget_t *widget;
widget = va_arg(args, txt_widget_t *);
if (widget == NULL)
{
// End of list
break;
}
else
{
++num_args;
}
}
va_end(args);
// Create the table.
result = TXT_NewTable(num_args);
TXT_AddWidget(result, first_widget);
// Go through the list again and add each widget.
va_start(args, TXT_UNCAST_ARG_NAME(first_widget));
for (;;)
{
txt_widget_t *widget;
widget = va_arg(args, txt_widget_t *);
if (widget == NULL)
{
// End of list
break;
}
else
{
TXT_AddWidget(result, widget);
}
}
va_end(args);
return result;
}
// Selects a given widget in a table, recursively searching any tables
// within this table. Returns 1 if successful, 0 if unsuccessful.
@ -634,5 +702,7 @@ void TXT_SetColumnWidths(TXT_UNCAST_ARG(table), ...)
strut = (txt_strut_t *) table->widgets[i];
strut->width = width;
}
va_end(args);
}

View file

@ -47,6 +47,7 @@ struct txt_table_s
};
txt_table_t *TXT_NewTable(int columns);
txt_table_t *TXT_NewHorizBox(TXT_UNCAST_ARG(first_widget), ...);
void TXT_InitTable(txt_table_t *table, int columns);
void TXT_AddWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget));
int TXT_SelectWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget));