aboutsummaryrefslogtreecommitdiffstats
path: root/src/gwin
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-08-12 20:22:34 +0200
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-08-12 20:22:34 +0200
commitf1ede211fb341ebd9bf0d31ff3ca4cf7aba43b19 (patch)
tree04a6414b913250722be1c2431f0388030d8a636a /src/gwin
parent46ba0420c342eaed1e4365c7e4cb65c0263bc7eb (diff)
downloaduGFX-f1ede211fb341ebd9bf0d31ff3ca4cf7aba43b19.tar.gz
uGFX-f1ede211fb341ebd9bf0d31ff3ca4cf7aba43b19.tar.bz2
uGFX-f1ede211fb341ebd9bf0d31ff3ca4cf7aba43b19.zip
First (simple) implementation of textbox behavior
Diffstat (limited to 'src/gwin')
-rw-r--r--src/gwin/gwin_textedit.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/gwin/gwin_textedit.c b/src/gwin/gwin_textedit.c
index 4aa41d61..fe15f441 100644
--- a/src/gwin/gwin_textedit.c
+++ b/src/gwin/gwin_textedit.c
@@ -26,9 +26,25 @@ const int TEXT_PADDING = 3;
#if GINPUT_NEED_KEYBOARD
static void _keyboardEvent(GWidgetObject* gw, GEventKeyboard* pke)
{
- if (pke->bytecount = 1) {
- //gw->text = pke->c[0];
- gwinSetText((GHandle)gw, &(pke->c[0]), TRUE);
+ // Create a temporary buffer containing the current size
+ unsigned bufSize = strlen(gwinGetText((GHandle)gw))+1;
+ char buf[bufSize];
+ strncpy(buf, gwinGetText((GHandle)gw), bufSize);
+
+ // Parse the key press
+ if (pke->bytecount == 1) {
+ // Check backspace
+ if (pke->c[0] == GKEY_BACKSPACE) {
+ buf[strlen(buf)-1] = '\0';
+ }
+
+ // Append new character
+ else {
+ strncat(buf, &(pke->c[0]), 1);
+ }
+
+ // Set the new text
+ gwinSetText((GHandle)gw, buf, TRUE);
}
_gwinUpdate(&gw);
@@ -103,7 +119,6 @@ static void gwinTexteditDefaultDraw(GWidgetObject* gw, void* param)
textColor = (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text;
-
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, textColor, gw->pstyle->background, justifyLeft);
}