shithub: choc

Download patch

ref: e365e664d767d41ef10a14c22be4964c0f6c8ea1
parent: 5da27e00a50fa64e340f62ad813858b8a9de2260
author: Simon Howard <fraggle@soulsphere.org>
date: Wed Jul 8 22:19:02 EDT 2015

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.

--- 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.
@@ -277,6 +279,20 @@
 {
     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)
     {
--- a/textscreen/txt_table.h
+++ b/textscreen/txt_table.h
@@ -36,6 +36,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.
  *
  * A table is a widget that contains other widgets.  It may have
@@ -71,8 +84,10 @@
 };
 
 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);