commit 2ad24f982e76e487e7c7f6543c2236723903a22d
Author: Simon Howard <fraggle@gmail.com>
AuthorDate: Mon May 22 19:23:28 2006 +0000
Commit: Simon Howard <fraggle@gmail.com>
CommitDate: Mon May 22 19:23:28 2006 +0000
Add TXT_SetLabel() function to set the label value.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 511
---
textscreen/txt_label.c | 18 ++++++++++++++----
textscreen/txt_label.h | 1 +
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/textscreen/txt_label.c b/textscreen/txt_label.c
index 356623d9..32610f9e 100644
--- a/textscreen/txt_label.c
+++ b/textscreen/txt_label.c
@@ -48,16 +48,25 @@ txt_widget_class_t txt_label_class =
TXT_LabelDestructor,
};
-static void TXT_SplitLabel(txt_label_t *label)
+void TXT_SetLabel(txt_label_t *label, char *value)
{
char *p;
int y;
+ // Free back the old label
+
+ free(label->label);
+ free(label->lines);
+
+ // Set the new value
+
+ label->label = strdup(value);
+
// Work out how many lines in this label
label->h = 1;
- for (p = label->label; *p != '\0'; ++p)
+ for (p = value; *p != '\0'; ++p)
{
if (*p == '\n')
{
@@ -98,9 +107,10 @@ txt_label_t *TXT_NewLabel(char *text)
TXT_InitWidget(label, &txt_label_class);
label->widget.selectable = 0;
- label->label = strdup(text);
+ label->label = NULL;
+ label->lines = NULL;
- TXT_SplitLabel(label);
+ TXT_SetLabel(label, text);
return label;
}
diff --git a/textscreen/txt_label.h b/textscreen/txt_label.h
index 80be506a..26471634 100644
--- a/textscreen/txt_label.h
+++ b/textscreen/txt_label.h
@@ -38,6 +38,7 @@ struct txt_label_s
};
txt_label_t *TXT_NewLabel(char *label);
+void TXT_SetLabel(txt_label_t *label, char *value);
#endif /* #ifndef TXT_LABEL_H */