ref: c083656d0e9390dabfcd9fc97e118cd9c8082f88
parent: 681c7bee784556181a0e1507fcac553041f5de04
author: Simon Howard <[email protected]>
date: Sun Sep 24 09:07:30 EDT 2006
Convenience function for creating a horizontal box. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 659
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -568,6 +568,74 @@
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 @@
strut = (txt_strut_t *) table->widgets[i];
strut->width = width;
}
+
+ va_end(args);
}
--- a/textscreen/txt_table.h
+++ b/textscreen/txt_table.h
@@ -47,6 +47,7 @@
};
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));