Skip to content

Commit 26ca32a

Browse files
committed
fix numeric input and allow 10-digit input
1 parent 72a0f7e commit 26ca32a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

ui.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,8 @@ draw_numeric_input(const char *buf)
13211321
int i = 0;
13221322
int x = 64;
13231323
int focused = FALSE;
1324-
const uint16_t xsim[] = { 0, 0, 8, 0, 0, 8, 0, 0, 0, 0 };
1325-
for (i = 0; i < 10 && buf[i]; i++) {
1324+
const uint16_t xsim[] = { 8, 0, 0, 8, 0, 0, 8, 0, 0, 0, 0 };
1325+
for (i = 0; i < (NUMERIC_INPUT_DIGITS + 1) && buf[i]; i++) {
13261326
uint16_t fg = 0x0000;
13271327
uint16_t bg = 0xffff;
13281328
int c = buf[i];
@@ -1335,7 +1335,7 @@ draw_numeric_input(const char *buf)
13351335
else
13361336
c = -1;
13371337

1338-
if (uistat.digit == 8-i) {
1338+
if (uistat.digit == NUMERIC_INPUT_DIGITS-i-1) {
13391339
fg = RGB565(128,255,128);
13401340
focused = TRUE;
13411341
if (uistat.digit_mode)
@@ -1355,8 +1355,8 @@ draw_numeric_input(const char *buf)
13551355
x += xsim[i];
13561356
}
13571357
}
1358-
if (i < 10) {
1359-
ili9341_fill(x, 208+4, 20*(10-i), 24, 0xffff);
1358+
if (i <= NUMERIC_INPUT_DIGITS) {
1359+
ili9341_fill(x, 208+4, 20*(NUMERIC_INPUT_DIGITS+1-i), 24, 0xffff);
13601360
}
13611361
}
13621362

@@ -1629,8 +1629,13 @@ void set_numeric_value(void)
16291629
void
16301630
draw_numeric_area(void)
16311631
{
1632-
char buf[10];
1633-
chsnprintf(buf, sizeof buf, "%9ld", uistat.value);
1632+
char buf[NUMERIC_INPUT_DIGITS+1];
1633+
1634+
// if NUMERIC_INPUT_DIGITS is changed, the below format string
1635+
// must be changed as well.
1636+
static_assert(NUMERIC_INPUT_DIGITS == 10);
1637+
chsnprintf(buf, sizeof buf, "%10ld", uistat.value);
1638+
16341639
draw_numeric_input(buf);
16351640
}
16361641

ui.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void ui_process(UIHW::UIEvent evt);
99

1010

1111
#define TOUCH_THRESHOLD 2000
12+
#define NUMERIC_INPUT_DIGITS 10
1213

1314
void touch_cal_exec(void);
1415
void touch_draw_test(void);

0 commit comments

Comments
 (0)