From f1210cea09c85c5c972d691d38b3b59f2cdbb15f Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 25 Sep 2021 13:05:52 -0400 Subject: tk/text: Replace min_char, max_char with callback --- (limited to 'src/tk/text.c') 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; -- cgit v0.9.1