summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-06 19:34:17 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-06 19:34:17 (EDT)
commit6d43b932c0af090dc4cb89ce0e494c4cfd3c4f7d (patch)
treee77b455701e8af00032a844ea48762a856eebab9 /src
parent4d2e2ec59b52e1a085313fcb823e7b2393137d1f (diff)
downloadmazefight-6d43b932c0af090dc4cb89ce0e494c4cfd3c4f7d.zip
mazefight-6d43b932c0af090dc4cb89ce0e494c4cfd3c4f7d.tar.gz
mazefight-6d43b932c0af090dc4cb89ce0e494c4cfd3c4f7d.tar.bz2
tk: Handle Backspace and Delete keys in text
Diffstat (limited to 'src')
-rw-r--r--src/tk/text.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tk/text.c b/src/tk/text.c
index 2a77691..1cbeb50 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -64,6 +64,7 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
{
struct mftk_text *t = (struct mftk_text *) w;
int len;
+ int i;
switch (e->type) {
case SDL_KEYDOWN:
@@ -87,6 +88,25 @@ _mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
case SDLK_END:
t->cur = strlen(t->val);
break;
+ case SDLK_BACKSPACE:
+ if (t->cur <= 0) {
+ break;
+ }
+ --t->cur;
+ len = strlen(t->val);
+ for (i = t->cur; i < len; ++i) {
+ t->val[i] = t->val[i + 1];
+ }
+ break;
+ case SDLK_DELETE:
+ len = strlen(t->val);
+ if (t->cur >= len) {
+ break;
+ }
+ for (i = t->cur; i < len; ++i) {
+ t->val[i] = t->val[i + 1];
+ }
+ break;
default:
break;
}