From 036f25e15947efa79452e2af3b4fb1d3ec2e3c98 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 17 Jul 2018 17:56:37 -0500 Subject: [PATCH] More lcd_strlen updates --- Marlin/ultralcd_impl_DOGM.h | 2 +- Marlin/ultralcd_impl_HD44780.h | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h index 2b89a28d2f..ad1cc96d56 100644 --- a/Marlin/ultralcd_impl_DOGM.h +++ b/Marlin/ultralcd_impl_DOGM.h @@ -603,7 +603,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor if (filename_scroll_hash != name_hash) { // If the hash changed... filename_scroll_hash = name_hash; // Save the new hash - filename_scroll_max = MAX(0, lcd_strlen(longFilename) - maxlen); // Update the scroll limit + filename_scroll_max = MAX(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit filename_scroll_pos = 0; // Reset scroll to the start lcd_status_update_delay = 8; // Don't scroll right away } diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h index 7081b21986..e45bc3fd6a 100644 --- a/Marlin/ultralcd_impl_HD44780.h +++ b/Marlin/ultralcd_impl_HD44780.h @@ -531,7 +531,7 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) { } static void logo_lines(const char* const extra) { - int16_t indent = (LCD_WIDTH - 8 - lcd_strlen_P(extra)) / 2; + int16_t indent = (LCD_WIDTH - 8 - utf8_strlen_P(extra)) / 2; lcd.setCursor(indent, 0); lcd.print('\x00'); lcd_printPGM(PSTR( "------" )); lcd.write('\x01'); lcd.setCursor(indent, 1); lcd_printPGM(PSTR("|Marlin|")); lcd_printPGM(extra); lcd.setCursor(indent, 2); lcd.write('\x02'); lcd_printPGM(PSTR( "------" )); lcd.write('\x03'); @@ -546,7 +546,7 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) { #define CENTER_OR_SCROLL(STRING,DELAY) \ lcd_erase_line(3); \ if (strlen(STRING) <= LCD_WIDTH) { \ - lcd.setCursor((LCD_WIDTH - lcd_strlen_P(PSTR(STRING))) / 2, 3); \ + lcd.setCursor((LCD_WIDTH - utf8_strlen_P(PSTR(STRING))) / 2, 3); \ lcd_printPGM_utf(PSTR(STRING)); \ safe_delay(DELAY); \ } \ @@ -1019,8 +1019,8 @@ static void lcd_implementation_status_screen() { int8_t n = LCD_WIDTH; lcd.setCursor(0, row); if (center && !valstr) { - while (--pad >= 0) { lcd.write(' '); n--; } int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2; + while (--pad >= 0) { lcd.write(' '); n--; } } while (n > 0 && (c = pgm_read_byte(pstr))) { n -= charset_mapper(c); @@ -1048,9 +1048,9 @@ static void lcd_implementation_status_screen() { static void lcd_implementation_drawmenu_setting_edit_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) { char c; + uint8_t n = LCD_WIDTH - 2 - utf8_strlen(data); lcd.setCursor(0, row); lcd.print(sel ? pre_char : ' '); - uint8_t n = LCD_WIDTH - 2 - utf8_strlen(data); while ((c = pgm_read_byte(pstr)) && n > 0) { n -= charset_mapper(c); pstr++; @@ -1061,9 +1061,9 @@ static void lcd_implementation_status_screen() { } static void lcd_implementation_drawmenu_setting_edit_generic_P(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) { char c; + uint8_t n = LCD_WIDTH - 2 - utf8_strlen_P(data); lcd.setCursor(0, row); lcd.print(sel ? pre_char : ' '); - uint8_t n = LCD_WIDTH - 2 - utf8_strlen_P(data); while ((c = pgm_read_byte(pstr)) && n > 0) { n -= charset_mapper(c); pstr++; @@ -1081,10 +1081,10 @@ static void lcd_implementation_status_screen() { lcd_printPGM_utf(pstr); if (value != NULL) { lcd.write(':'); - lcd.setCursor((LCD_WIDTH - 1) - (lcd_strlen(value) + 1), valrow); // Right-justified, padded by spaces + const uint8_t valrow = (utf8_strlen_P(pstr) + 1 + utf8_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit + lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), valrow); // Right-justified, padded by spaces lcd.write(' '); // overwrite char if value gets shorter lcd_print(value); - const uint8_t valrow = (utf8_strlen_P(pstr) + 1 + utf8_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit } } @@ -1105,7 +1105,7 @@ static void lcd_implementation_status_screen() { name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor if (filename_scroll_hash != name_hash) { // If the hash changed... filename_scroll_hash = name_hash; // Save the new hash - filename_scroll_max = MAX(0, lcd_strlen(longFilename) - n); // Update the scroll limit + filename_scroll_max = MAX(0, utf8_strlen(longFilename) - n); // Update the scroll limit filename_scroll_pos = 0; // Reset scroll to the start lcd_status_update_delay = 8; // Don't scroll right away }