First (simple) implementation of textbox behavior
This commit is contained in:
parent
46ba0420c3
commit
f1ede211fb
1 changed files with 19 additions and 4 deletions
|
@ -26,9 +26,25 @@ const int TEXT_PADDING = 3;
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD
|
||||||
static void _keyboardEvent(GWidgetObject* gw, GEventKeyboard* pke)
|
static void _keyboardEvent(GWidgetObject* gw, GEventKeyboard* pke)
|
||||||
{
|
{
|
||||||
if (pke->bytecount = 1) {
|
// Create a temporary buffer containing the current size
|
||||||
//gw->text = pke->c[0];
|
unsigned bufSize = strlen(gwinGetText((GHandle)gw))+1;
|
||||||
gwinSetText((GHandle)gw, &(pke->c[0]), TRUE);
|
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);
|
_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;
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue