From e3618d75594e68a4dca8a900182e30a36746b951 Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 22 Mar 2013 19:18:26 +0000 Subject: [PATCH] [Add] Input widget will scoll if full. --- src/menu.c | 2 +- src/toolkit.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/menu.c b/src/menu.c index c2365f4..084711f 100644 --- a/src/menu.c +++ b/src/menu.c @@ -16,7 +16,7 @@ #define MENU_WIDTH 130 #define MENU_HEIGHT 200 -#define INFO_WIDTH 320 +#define INFO_WIDTH 360 #define INFO_HEIGHT 280 #define OUTFITS_WIDTH 400 diff --git a/src/toolkit.c b/src/toolkit.c index 8ed1b45..bfd14bf 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -921,7 +921,7 @@ static void toolkit_renderInput(Widget* inp, double bx, double by) { gl_printText(&gl_smallFont, inp->w-10., inp->h, x+5. + gl_screen.w/2., ty + gl_screen.h/2., - &cBlack, inp->dat.inp.input); + &cBlack, inp->dat.inp.input+inp->dat.inp.view); // Inner outline. toolkit_drawOutline(x, y, inp->w, inp->h, 0., @@ -933,6 +933,7 @@ static void toolkit_renderInput(Widget* inp, double bx, double by) { // Handle input for input widget. static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) { + int n; SDLMod mods; if(inp->type != WIDGET_INPUT) return 0; @@ -940,8 +941,16 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) { mods = SDL_GetModState(); if(inp->dat.inp.oneline && isascii(key)) { // Backspace -> delete text. - if((type == SDL_KEYDOWN) && (key == '\b') && (inp->dat.inp.pos > 0)) + if((type == SDL_KEYDOWN) && (key == '\b') && (inp->dat.inp.pos > 0)) { inp->dat.inp.input[--inp->dat.inp.pos] = '\0'; + + if(inp->dat.inp.view > 0) { + n = gl_printWidth(&gl_smallFont, + inp->dat.inp.input + inp->dat.inp.view - 1); + if(n+10 < inp->w) + inp->dat.inp.view--; + } + } else if((type == SDL_KEYDOWN) && (inp->dat.inp.pos < inp->dat.inp.max-1)) { if((key == SDLK_RETURN) && !inp->dat.inp.oneline) inp->dat.inp.input[inp->dat.inp.pos++] = '\n'; @@ -957,6 +966,8 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) { // Didn't get a useful key. else return 0; + n = gl_printWidth(&gl_smallFont, inp->dat.inp.input+inp->dat.inp.view); + if(n + 10 > inp->w) inp->dat.inp.view++; return 1; } }