summaryrefslogtreecommitdiff
path: root/textscreen
diff options
context:
space:
mode:
Diffstat (limited to 'textscreen')
-rw-r--r--textscreen/txt_table.c19
-rw-r--r--textscreen/txt_table.h1
2 files changed, 16 insertions, 4 deletions
diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c
index 8b31af24..29798906 100644
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -33,14 +33,18 @@
#include "txt_strut.h"
#include "txt_table.h"
-static void TXT_TableDestructor(TXT_UNCAST_ARG(table))
+// Remove all entries from a table
+
+void TXT_ClearTable(TXT_UNCAST_ARG(table))
{
TXT_CAST_ARG(txt_table_t, table);
int i;
// Free all widgets
+ // Skip over the first (num_columns) widgets in the array, as these
+ // are the column struts used to control column width
- for (i=0; i<table->num_widgets; ++i)
+ for (i=table->columns; i<table->num_widgets; ++i)
{
if (table->widgets[i] != NULL)
{
@@ -48,9 +52,16 @@ static void TXT_TableDestructor(TXT_UNCAST_ARG(table))
}
}
- // Free table resources
+ // Shrink the table to just the column strut widgets
+
+ table->num_widgets = table->columns;
+}
+
+static void TXT_TableDestructor(TXT_UNCAST_ARG(table))
+{
+ TXT_CAST_ARG(txt_table_t, table);
- free(table->widgets);
+ TXT_ClearTable(table);
}
static int TableRows(txt_table_t *table)
diff --git a/textscreen/txt_table.h b/textscreen/txt_table.h
index c3a3c5a8..d42e9adb 100644
--- a/textscreen/txt_table.h
+++ b/textscreen/txt_table.h
@@ -53,6 +53,7 @@ void TXT_AddWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget));
void TXT_AddWidgets(TXT_UNCAST_ARG(table), ...);
int TXT_SelectWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget));
void TXT_SetColumnWidths(TXT_UNCAST_ARG(table), ...);
+void TXT_ClearTable(TXT_UNCAST_ARG(table));
#endif /* #ifndef TXT_TABLE_T */