summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2006-09-24 13:07:30 +0000
committerSimon Howard2006-09-24 13:07:30 +0000
commitc083656d0e9390dabfcd9fc97e118cd9c8082f88 (patch)
tree1b442bed6c522894c7e172f516af1fe3b00c9110
parent681c7bee784556181a0e1507fcac553041f5de04 (diff)
downloadchocolate-doom-c083656d0e9390dabfcd9fc97e118cd9c8082f88.tar.gz
chocolate-doom-c083656d0e9390dabfcd9fc97e118cd9c8082f88.tar.bz2
chocolate-doom-c083656d0e9390dabfcd9fc97e118cd9c8082f88.zip
Convenience function for creating a horizontal box.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 659
-rw-r--r--textscreen/txt_table.c70
-rw-r--r--textscreen/txt_table.h1
2 files changed, 71 insertions, 0 deletions
diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c
index e0d34cdb..f6f38e53 100644
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -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);
}
diff --git a/textscreen/txt_table.h b/textscreen/txt_table.h
index 084ade11..2effc85b 100644
--- a/textscreen/txt_table.h
+++ b/textscreen/txt_table.h
@@ -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));