commit e365e664d767d41ef10a14c22be4964c0f6c8ea1
Author: Simon Howard <fraggle@soulsphere.org>
AuthorDate: Thu Jul 9 02:19:02 2015 -0400
Commit: Simon Howard <fraggle@soulsphere.org>
CommitDate: Thu Jul 9 02:19:02 2015 -0400
textscreen: Add further table conveniences.
Add TXT_TABLE_EMPTY to work around the inability to add a NULL cell
using TXT_AddWidgets(), and TXT_TABLE_EOL to immediately start a new
row, padding appropriately.
---
textscreen/txt_table.c | 20 ++++++++++++++++++--
textscreen/txt_table.h | 19 +++++++++++++++++--
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c
index d9c4f178..b99ecd75 100644
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -26,8 +26,10 @@
#include "txt_strut.h"
#include "txt_table.h"
-const txt_widget_t txt_table_overflow_right = {};
-const txt_widget_t txt_table_overflow_down = {};
+txt_widget_t txt_table_overflow_right = {};
+txt_widget_t txt_table_overflow_down = {};
+txt_widget_t txt_table_eol = {};
+txt_widget_t txt_table_empty = {};
// Returns true if the given widget in the table's widgets[] array refers
// to an actual widget - not NULL, or one of the special overflow pointers.
@@ -278,6 +280,20 @@ void TXT_AddWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget))
TXT_CAST_ARG(txt_table_t, table);
TXT_CAST_ARG(txt_widget_t, widget);
+ // Convenience alias for NULL:
+ if (widget == &txt_table_empty)
+ {
+ widget = NULL;
+ }
+ else if (widget == &txt_table_eol)
+ {
+ while ((table->num_widgets % table->columns) != 0)
+ {
+ TXT_AddWidget(table, &txt_table_overflow_right);
+ }
+ return;
+ }
+
if (table->num_widgets > 0)
{
txt_widget_t *last_widget;
diff --git a/textscreen/txt_table.h b/textscreen/txt_table.h
index 7cfe5004..94e8556d 100644
--- a/textscreen/txt_table.h
+++ b/textscreen/txt_table.h
@@ -35,6 +35,19 @@
#define TXT_TABLE_OVERFLOW_DOWN (&txt_table_overflow_down)
+/**
+ * Magic value that if given to @ref TXT_AddWidget(), will pad out all
+ * columns until the end of line.
+ */
+#define TXT_TABLE_EOL (&txt_table_eol)
+
+/**
+ * Indicates an empty space to @ref TXT_AddWidgets(). Equivalent to
+ * TXT_AddWidget(table, NULL), except that NULL is used by TXT_AddWidgets()
+ * to indicate the end of input.
+ */
+#define TXT_TABLE_EMPTY (&txt_table_empty)
+
/**
* Table widget.
*
@@ -71,8 +84,10 @@ struct txt_table_s
};
extern txt_widget_class_t txt_table_class;
-extern const txt_widget_t txt_table_overflow_right;
-extern const txt_widget_t txt_table_overflow_down;
+extern txt_widget_t txt_table_overflow_right;
+extern txt_widget_t txt_table_overflow_down;
+extern txt_widget_t txt_table_eol;
+extern txt_widget_t txt_table_empty;
void TXT_InitTable(txt_table_t *table, int columns);