diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-09-25 13:05:52 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-09-25 13:05:52 (EDT) |
commit | f1210cea09c85c5c972d691d38b3b59f2cdbb15f (patch) | |
tree | 3530b56bf41861ef5e62eeb54ebac0c486f7de7f /src/tk | |
parent | 3423586ef2741f797c392fcf70e3f0a61cf0b220 (diff) | |
download | mazefight-f1210cea09c85c5c972d691d38b3b59f2cdbb15f.zip mazefight-f1210cea09c85c5c972d691d38b3b59f2cdbb15f.tar.gz mazefight-f1210cea09c85c5c972d691d38b3b59f2cdbb15f.tar.bz2 |
tk/text: Replace min_char, max_char with callback
Diffstat (limited to 'src/tk')
-rw-r--r-- | src/tk/text.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/tk/text.c b/src/tk/text.c index ccfaf7f..f509c14 100644 --- a/src/tk/text.c +++ b/src/tk/text.c @@ -42,6 +42,7 @@ struct mftk_text { SDL_Color *color; SDL_Texture *texture; int editable; + int (*allowed)(void *, char); int (*action)(void *, const char *); int (*submit)(void *); void *user_data; @@ -144,8 +145,11 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e) for (i = 0, j = 0; i < newlen && e->text.text[j] != '\0'; ++j) { - if (e->text.text[j] < t->min_char) continue; - if (e->text.text[j] > t->max_char) continue; + if (t->allowed != NULL && + t->allowed(t->user_data, + e->text.text[j]) <= 0) { + continue; + } t->val[t->cur + i] = e->text.text[j]; ++i; } @@ -299,6 +303,7 @@ _mftk_text_destroy(struct mftk_widget *w) struct mftk_widget * mftk_text_new(char min_char, char max_char, int len, const char *val, TTF_Font *font, SDL_Color *color, int editable, + int (*allowed)(void *, char), int (*action)(void *, const char *), int (*submit)(void *), void *user_data) { @@ -322,6 +327,7 @@ mftk_text_new(char min_char, char max_char, int len, const char *val, t->color = color; t->texture = NULL; t->editable = editable; + t->allowed = allowed; t->action = action; t->submit = submit; t->user_data = user_data; |