summaryrefslogtreecommitdiffstats
path: root/src/tk
diff options
context:
space:
mode:
Diffstat (limited to 'src/tk')
-rw-r--r--src/tk/check.c9
-rw-r--r--src/tk/radio.c11
-rw-r--r--src/tk/text.c7
3 files changed, 20 insertions, 7 deletions
diff --git a/src/tk/check.c b/src/tk/check.c
index 898a21e..b26f7d7 100644
--- a/src/tk/check.c
+++ b/src/tk/check.c
@@ -34,6 +34,7 @@ struct mftk_check {
struct mftk_widget *label;
int steals_focus;
int (*action)(void *, int);
+ int (*submit)(void *);
void *user_data;
};
@@ -101,12 +102,13 @@ _mftk_check_key_event(struct mftk_widget *w, SDL_Event *e)
case SDL_KEYDOWN:
switch (e->key.keysym.sym) {
case SDLK_SPACE:
- case SDLK_RETURN:
c->state = !c->state;
if (c->action == NULL) {
return 0;
}
return c->action(c->user_data,c->state);
+ case SDLK_RETURN:
+ return c->submit(c->user_data);
default:
break;
}
@@ -266,8 +268,8 @@ struct mftk_widget *
mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color,
SDL_Color *mark_color, int state, int label_padding,
TTF_Font *font, const char *text, SDL_Color *text_color,
- int (*action)(void *, int), void *user_data,
- SDL_Renderer *renderer)
+ int (*action)(void *, int), int (*submit)(void *),
+ void *user_data, SDL_Renderer *renderer)
{
struct mftk_widget *w;
struct mftk_check *c;
@@ -291,6 +293,7 @@ mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color,
c->label_padding = label_padding;
c->steals_focus = SDL_TRUE;
c->action = action;
+ c->submit = submit;
c->user_data = user_data;
return w;
diff --git a/src/tk/radio.c b/src/tk/radio.c
index 99e2b8b..79271ee 100644
--- a/src/tk/radio.c
+++ b/src/tk/radio.c
@@ -37,6 +37,7 @@ struct mftk_radio {
int state;
int options;
int (*action)(void *, int);
+ int (*submit)(void *);
void *user_data;
};
@@ -117,6 +118,8 @@ _mftk_radio_key_event(struct mftk_widget *w, SDL_Event *e)
return 0;
}
return r->action(r->user_data,r->state);
+ case SDLK_RETURN:
+ return r->submit(r->user_data);
default:
break;
}
@@ -168,8 +171,9 @@ struct mftk_widget *
mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color,
SDL_Color *mark_color, int label_padding, int item_padding,
TTF_Font *font, SDL_Color *text_color,
- int (*action)(void *, int), void *user_data,
- SDL_Renderer *renderer, int state, int options, ...)
+ int (*action)(void *, int), int (*submit)(void *),
+ void *user_data, SDL_Renderer *renderer, int state, int options,
+ ...)
{
struct mftk_widget *w;
struct mftk_radio *r;
@@ -201,7 +205,7 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color,
r->children[i] = mftk_check_new(butn_width, butn_padding,
butn_color, mark_color, (i == state),
label_padding, font, va_arg(ap, const char *),
- text_color, &_mftk_radio_state_change,
+ text_color, &_mftk_radio_state_change, submit,
&r->states[i], renderer);
if (r->children[i] == NULL) {
for (; i >= 0; --i) {
@@ -234,6 +238,7 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color,
r->state = state;
r->options = options;
r->action = action;
+ r->submit = submit;
r->user_data = user_data;
return w;
diff --git a/src/tk/text.c b/src/tk/text.c
index 4a8196d..027da71 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 (*action)(void *, const char *);
+ int (*submit)(void *);
void *user_data;
};
@@ -123,6 +124,8 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
return 0;
}
return t->action(t->user_data, t->val);
+ case SDLK_RETURN:
+ return t->submit(t->user_data);
default:
break;
}
@@ -287,7 +290,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,
- int (*action)(void *, const char *), void *user_data)
+ int (*action)(void *, const char *), int (*submit)(void *),
+ void *user_data)
{
struct mftk_widget *w;
struct mftk_text *t;
@@ -306,6 +310,7 @@ mftk_text_new(char min_char, char max_char, int len, const char *val,
t->color = color;
t->texture = NULL;
t->action = action;
+ t->submit = submit;
t->user_data = user_data;
t->val = calloc(len + 1, sizeof(*t->val));