summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--textscreen/txt_label.c18
-rw-r--r--textscreen/txt_label.h1
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 */