From fa9d4550f011fda7ed42ef684f9acebd3a2d505b Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Jul 2018 15:21:46 +0200 Subject: [PATCH] PFW-448 menu items displaying fix --- Firmware/menu.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 17292930..7b6be855 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -224,7 +224,18 @@ uint8_t menu_item_gcode_P(const char* str, const char* str_gcode) return 0; } -const char menu_fmt_int3[] PROGMEM = "%c%S:\x1b[%hhu;16H%3d"; +const char menu_20x_space[] PROGMEM = " "; +const char menu_fmt_int3[] PROGMEM = "%c%.15S:%s%3d"; +void menu_draw_int3(char chr, const char* str, int16_t val) +{ + int text_len = strlen_P(str); + if (text_len > 15) text_len = 15; + char spaces[21]; + strcpy_P(spaces, menu_20x_space); + spaces[15 - text_len] = 0; + lcd_printf_P(menu_fmt_int3, chr, str, spaces, val); +} + #define _menu_data (*((menu_data_edit_t*)menu_data)) void _menu_edit_int3(void) @@ -234,7 +245,7 @@ void _menu_edit_int3(void) if (lcd_encoder < _menu_data.minEditValue) lcd_encoder = _menu_data.minEditValue; if (lcd_encoder > _menu_data.maxEditValue) lcd_encoder = _menu_data.maxEditValue; lcd_set_cursor(0, 1); - lcd_printf_P(menu_fmt_int3, ' ', _menu_data.editLabel, (uint8_t)1, (int)lcd_encoder); + menu_draw_int3(' ', _menu_data.editLabel, (int)lcd_encoder); } if (LCD_CLICKED) { @@ -250,7 +261,7 @@ uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int if (lcd_draw_update) { lcd_set_cursor(0, menu_row); - lcd_printf_P(menu_fmt_int3, (lcd_encoder == menu_item)?'>':' ', str, menu_row, *pval); + menu_draw_int3((lcd_encoder == menu_item)?'>':' ', str, *pval); } if (menu_clicked && (lcd_encoder == menu_item)) {