diff options
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; |