summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-07 17:27:40 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-07 17:51:28 (EDT)
commit3bfc960bce1f9b81a6d43601165de38a6b4e2ad3 (patch)
treeea4108dfe5f9affa1d23bf38ba6dc127d182cc3c
parentb16bd8260a484a7be8df0528225794a54c42767f (diff)
downloadmazefight-3bfc960bce1f9b81a6d43601165de38a6b4e2ad3.zip
mazefight-3bfc960bce1f9b81a6d43601165de38a6b4e2ad3.tar.gz
mazefight-3bfc960bce1f9b81a6d43601165de38a6b4e2ad3.tar.bz2
tk: Add text widget value setter
-rw-r--r--src/tk.h3
-rw-r--r--src/tk/text.c16
2 files changed, 19 insertions, 0 deletions
diff --git a/src/tk.h b/src/tk.h
index d1f690f..cedd57d 100644
--- a/src/tk.h
+++ b/src/tk.h
@@ -81,6 +81,9 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
int (*action)(void *, const char *), int (*submit)(void *),
void *user_data);
+void
+mftk_text_set_value(struct mftk_widget *w, const char *val);
+
struct mftk_widget *
mftk_blank_new(void);
diff --git a/src/tk/text.c b/src/tk/text.c
index 7406b0b..3b95d2a 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -354,3 +354,19 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
return w;
}
+
+void
+mftk_text_set_value(struct mftk_widget *w, const char *val)
+{
+ struct mftk_text *t = (struct mftk_text *) w;
+
+ t->cur = strlen(val);
+ if (t->cur > t->len) {
+ t->cur = t->len;
+ }
+ memcpy(t->val, val, t->cur);
+ t->val[t->cur] = '\0';
+
+ SDL_DestroyTexture(t->texture);
+ t->texture = NULL;
+}