ref: 1d2fe63a94c8e0fcacb3482b822018ce1fc288c8
parent: 77ad7dc5f88eafb2d0c502957ae879fab073200d
author: Simon Howard <[email protected]>
date: Wed Jan 25 16:08:53 EST 2017
textscreen: Add TXT_MakeTable(). When creating a table widget is is often convenient to be able to create and populate it in a single function call. It's possible to do this with "horizontal boxes" already but there wasn't a more generic mechanism for making a table. So add one as TXT_MakeTable().
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -906,6 +906,37 @@
return table;
}
+// Alternative to TXT_NewTable() that allows a list of widgets to be
+// provided in its arguments.
+txt_table_t *TXT_MakeTable(int columns, TXT_UNCAST_ARG(first_widget), ...)
+{
+ TXT_CAST_ARG(txt_widget_t, first_widget);
+ txt_table_t *table;
+ va_list args;
+
+ table = TXT_NewTable(columns);
+ TXT_AddWidget(table, first_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)
+ {
+ break;
+ }
+
+ TXT_AddWidget(table, widget);
+ }
+
+ va_end(args);
+
+ return table;
+}
+
// Create a horizontal table from a list of widgets.
txt_table_t *TXT_NewHorizBox(TXT_UNCAST_ARG(first_widget), ...)
--- a/textscreen/txt_table.h
+++ b/textscreen/txt_table.h
@@ -101,6 +101,18 @@
txt_table_t *TXT_NewTable(int columns);
/**
+ * Create a new table and populate it with provided widgets.
+ *
+ * The arguments to this function are variable. Each argument must be a
+ * pointer to a widget, and the list is terminated with a NULL.
+ *
+ * @param columns The number of columns in the new table.
+ * @return Pointer to the new table structure.
+ */
+
+txt_table_t *TXT_MakeTable(int columns, TXT_UNCAST_ARG(first_widget), ...);
+
+/**
* Create a table containing the specified widgets packed horizontally,
* from left to right.
*