summaryrefslogtreecommitdiffstats
path: root/src/tk/text.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tk/text.c')
-rw-r--r--src/tk/text.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/tk/text.c b/src/tk/text.c
index c624678..6a89b44 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -26,21 +26,23 @@
#include "widget.h"
struct mftk_text {
- struct mftk_widget parent;
- char min_char;
- char max_char;
- int len;
- int cur;
- int y;
- int w;
- int h;
- char *val;
- char *curval;
- TTF_Font *font;
- int line_skip;
- int ascent;
- SDL_Color *color;
- SDL_Texture *texture;
+ struct mftk_widget parent;
+ char min_char;
+ char max_char;
+ int len;
+ int cur;
+ int y;
+ int w;
+ int h;
+ char *val;
+ char *curval;
+ TTF_Font *font;
+ int line_skip;
+ int ascent;
+ SDL_Color *color;
+ SDL_Texture *texture;
+ int (*action)(void *, const char *);
+ void *user_data;
};
static void
@@ -103,7 +105,10 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
}
SDL_DestroyTexture(t->texture);
t->texture = NULL;
- break;
+ if (t->action == NULL) {
+ return 0;
+ }
+ return t->action(t->user_data, t->val);
case SDLK_DELETE:
len = strlen(t->val);
if (t->cur >= len) {
@@ -114,7 +119,10 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
}
SDL_DestroyTexture(t->texture);
t->texture = NULL;
- break;
+ if (t->action == NULL) {
+ return 0;
+ }
+ return t->action(t->user_data, t->val);
default:
break;
}
@@ -139,7 +147,10 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
t->cur += i;
SDL_DestroyTexture(t->texture);
t->texture = NULL;
- break;
+ if (t->action == NULL) {
+ return 0;
+ }
+ return t->action(t->user_data, t->val);
default:
break;
}
@@ -272,7 +283,8 @@ _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)
+ TTF_Font *font, SDL_Color *color,
+ int (*action)(void *, const char *), void *user_data)
{
struct mftk_widget *w;
struct mftk_text *t;
@@ -290,6 +302,8 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
t->ascent = TTF_FontAscent (font);
t->color = color;
t->texture = NULL;
+ t->action = action;
+ t->user_data = user_data;
t->val = calloc(len + 1, sizeof(*t->val));
if (t->val == NULL) {