From 42ebb5bebb6889de52c04a5eb65837b20b489445 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 25 May 2006 21:27:34 +0000 Subject: Allow NULL to be added to tables to specify a spacer (empty cell). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 530 --- textscreen/txt_table.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'textscreen/txt_table.c') diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c index 4c502c0c..b2055825 100644 --- a/textscreen/txt_table.c +++ b/textscreen/txt_table.c @@ -42,7 +42,10 @@ static void TXT_TableDestructor(TXT_UNCAST_ARG(table)) for (i=0; inum_widgets; ++i) { - TXT_DestroyWidget(table->widgets[i]); + if (table->widgets[i] != NULL) + { + TXT_DestroyWidget(table->widgets[i]); + } } // Free table resources @@ -50,8 +53,6 @@ static void TXT_TableDestructor(TXT_UNCAST_ARG(table)) free(table->widgets); } -// ------------- - static int TableRows(txt_table_t *table) { return (table->num_widgets + table->columns - 1) / table->columns; @@ -65,6 +66,7 @@ static void CalcRowColSizes(txt_table_t *table, int x, y; int rows; int ww, wh; + txt_widget_t *widget; rows = TableRows(table); @@ -79,8 +81,19 @@ static void CalcRowColSizes(txt_table_t *table, if (y * table->columns + x >= table->num_widgets) break; - TXT_CalcWidgetSize(table->widgets[y * table->columns + x], - &ww, &wh); + widget = table->widgets[y * table->columns + x]; + + if (widget != NULL) + { + TXT_CalcWidgetSize(widget, &ww, &wh); + } + else + { + // Empty spacer if widget is NULL + + ww = 0; + wh = 1; + } if (wh > row_heights[y]) row_heights[y] = wh; @@ -134,7 +147,8 @@ void TXT_AddWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget)) last_widget = table->widgets[table->num_widgets - 1]; - if (widget->widget_class == &txt_separator_class + if (widget != NULL && last_widget != NULL + && widget->widget_class == &txt_separator_class && last_widget->widget_class == &txt_separator_class) { // The previous widget added was a separator; replace @@ -168,7 +182,7 @@ static int SelectableWidget(txt_table_t *table, int x, int y) if (i >= 0 && i < table->num_widgets) { widget = table->widgets[i]; - return widget->selectable && widget->visible; + return widget != NULL && widget->selectable && widget->visible; } return 0; @@ -221,7 +235,8 @@ static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key) if (selected >= 0 && selected < table->num_widgets) { - if (TXT_WidgetKeyPress(table->widgets[selected], key)) + if (table->widgets[selected] != NULL + && TXT_WidgetKeyPress(table->widgets[selected], key)) { return 1; } @@ -342,6 +357,7 @@ static void CheckValidSelection(txt_table_t *table) static void TXT_TableDrawer(TXT_UNCAST_ARG(table), int w, int selected) { TXT_CAST_ARG(txt_table_t, table); + txt_widget_t *widget; int *column_widths; int *row_heights; int origin_x, origin_y; @@ -389,10 +405,14 @@ static void TXT_TableDrawer(TXT_UNCAST_ARG(table), int w, int selected) TXT_GotoXY(draw_x, draw_y); - TXT_DrawWidget(table->widgets[y * table->columns + x], - column_widths[x], - selected && x == table->selected_x - && y == table->selected_y); + widget = table->widgets[y * table->columns + x]; + + if (widget != NULL) + { + TXT_DrawWidget(widget, column_widths[x], + selected && x == table->selected_x + && y == table->selected_y); + } draw_x += column_widths[x]; } -- cgit v1.2.3