From 3a5668eeb63a3deae8861dd9a7f176bb773df898 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 29 May 2006 19:22:51 +0000 Subject: Add strut class to allow table column width to be forced. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 539 --- src/net_gui.c | 7 ++++--- textscreen/Makefile.am | 1 + textscreen/txt_strut.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ textscreen/txt_strut.h | 47 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 textscreen/txt_strut.c create mode 100644 textscreen/txt_strut.h diff --git a/src/net_gui.c b/src/net_gui.c index 7e03d232..21000aa2 100644 --- a/src/net_gui.c +++ b/src/net_gui.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_gui.c 534 2006-05-26 19:15:33Z fraggle $ +// $Id: net_gui.c 539 2006-05-29 19:22:51Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -94,6 +94,7 @@ #include "txt_desktop.h" #include "txt_label.h" +#include "txt_strut.h" #include "txt_table.h" #include "txt_window.h" @@ -130,8 +131,8 @@ static void BuildGUI(void) // Add spacers TXT_AddWidget(table, NULL); - TXT_AddWidget(table, TXT_NewLabel(" ")); - TXT_AddWidget(table, TXT_NewLabel(" ")); + TXT_AddWidget(table, TXT_NewStrut(25)); + TXT_AddWidget(table, TXT_NewStrut(17)); // Player labels diff --git a/textscreen/Makefile.am b/textscreen/Makefile.am index 12a876b0..15eb526c 100644 --- a/textscreen/Makefile.am +++ b/textscreen/Makefile.am @@ -18,6 +18,7 @@ libtextscreen_a_SOURCES = \ txt_label.c txt_label.h \ txt_radiobutton.c txt_radiobutton.h \ txt_separator.c txt_separator.h \ + txt_strut.c txt_strut.h \ txt_table.c txt_table.h \ txt_widget.c txt_widget.h \ txt_window.c txt_window.h \ diff --git a/textscreen/txt_strut.c b/textscreen/txt_strut.c new file mode 100644 index 00000000..47e80130 --- /dev/null +++ b/textscreen/txt_strut.c @@ -0,0 +1,55 @@ + +#include +#include + +#include "doomkeys.h" + +#include "txt_strut.h" +#include "txt_io.h" +#include "txt_main.h" +#include "txt_window.h" + +static void TXT_StrutSizeCalc(TXT_UNCAST_ARG(strut), int *w, int *h) +{ + TXT_CAST_ARG(txt_strut_t, strut); + + // Minimum width is the string length + two spaces for padding + + *w = strut->width; + *h = 0; +} + +static void TXT_StrutDrawer(TXT_UNCAST_ARG(strut), int w, int selected) +{ + // Nothing is drawn for a strut. +} + +static void TXT_StrutDestructor(TXT_UNCAST_ARG(strut)) +{ +} + +static int TXT_StrutKeyPress(TXT_UNCAST_ARG(strut), int key) +{ +} + +txt_widget_class_t txt_strut_class = +{ + TXT_StrutSizeCalc, + TXT_StrutDrawer, + TXT_StrutKeyPress, + TXT_StrutDestructor, +}; + +txt_strut_t *TXT_NewStrut(int width) +{ + txt_strut_t *strut; + + strut = malloc(sizeof(txt_strut_t)); + + TXT_InitWidget(strut, &txt_strut_class); + strut->widget.selectable = 0; + strut->width = width; + + return strut; +} + diff --git a/textscreen/txt_strut.h b/textscreen/txt_strut.h new file mode 100644 index 00000000..5bf7b7e7 --- /dev/null +++ b/textscreen/txt_strut.h @@ -0,0 +1,47 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id$ +// +// Copyright(C) 1993-1996 Id Software, Inc. +// Copyright(C) 2006 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// + +#ifndef TXT_STRUT_H +#define TXT_STRUT_H + +typedef struct txt_strut_s txt_strut_t; + +#include "txt_widget.h" + +// +// A strut is used to force a table to a minimum width. It is not +// visible but it takes up space. +// + +struct txt_strut_s +{ + txt_widget_t widget; + int width; +}; + +txt_strut_t *TXT_NewStrut(int width); + +#endif /* #ifndef TXT_STRUT_H */ + + -- cgit v1.2.3