From 6e52e279869bbff2f365ccdce7942b81c360812e Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 27 May 2021 21:46:29 +0300 Subject: [PATCH] Better keyboard input formatting --- ui.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ui.c b/ui.c index 1a71816..0f9bb14 100644 --- a/ui.c +++ b/ui.c @@ -1011,33 +1011,37 @@ menu_is_multiline(const char *label) return n; } +static int period_pos(void) {int j; for (j = 0; j < kp_index && kp_buf[j] != '.'; j++); return j;} + static void draw_numeric_input(const char *buf) { - int i; - int x; - uint16_t xsim = 0b0010010000000000; - + uint16_t i; + uint16_t x = 10 + 10 * FONT_WIDTH + 4; + uint16_t xsim = 0b00100100100100100 >>(2-(period_pos()%3)); + xsim&=~1; ili9341_set_foreground(LCD_INPUT_TEXT_COLOR); ili9341_set_background(LCD_INPUT_BG_COLOR); - for (i = 0, x = 64; i < NUMINPUT_LEN && buf[i]; i++, xsim<<=1) { + for (i = 0; buf[i]; i++) { int c = buf[i]; - if (c == '.') - c = KP_PERIOD; - else if (c == '-') - c = KP_MINUS; + if (c == '.'){c = KP_PERIOD;xsim<<=4;} + else if (c == '-'){c = KP_MINUS; xsim&=~1;} else// if (c >= '0' && c <= '9') c = c - '0'; - + if (c < 0) c = 0; + // Add space before char + int16_t space = xsim&1 ? 2 + 10 : 2; + xsim>>=1; + ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, space, NUM_INPUT_HEIGHT); + x+=space; if (c >= 0) // c is number ili9341_drawfont(c, x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4); - else // erase + else break; - - x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2; + x+=NUM_FONT_GET_WIDTH; } - // erase last - ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, LCD_WIDTH-x-1, NUM_FONT_GET_WIDTH+2+8); + + ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, LCD_WIDTH - 1 - x, NUM_INPUT_HEIGHT); if (buf[0] == 0 && kp_help_text != NULL) { int lines = menu_is_multiline(kp_help_text); ili9341_set_foreground(LCD_INPUT_TEXT_COLOR);