From 725d9d9a56d9cfdf720a739eae56fb7c38f7696e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 19 Jun 2017 21:53:06 -0500 Subject: [PATCH] Fix and improve LCD value editing display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix: When "100.0" changes to "99.0" the LCD shows "199.0" - Use 2 rows if needed on character LCD, (allowing longer labels… Germany, et. al.) - Known issue: A certain length label combined with a certain value drawing function could, for example, display 99.0 on 1 line, but 100.0 on two lines. Workaround would be to pass a nominal value size argument. --- Marlin/ultralcd_impl_DOGM.h | 17 +++++++++++------ Marlin/ultralcd_impl_HD44780.h | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h index 5ffe11020..b7a000229 100644 --- a/Marlin/ultralcd_impl_DOGM.h +++ b/Marlin/ultralcd_impl_DOGM.h @@ -871,7 +871,7 @@ static void lcd_implementation_status_screen() { #if ENABLED(USE_BIG_EDIT_FONT) uint8_t lcd_width, char_width; if (labellen <= LCD_WIDTH_EDIT - 1) { - if (labellen >= LCD_WIDTH_EDIT - vallen) rows = 2; + if (labellen + vallen + 2 >= LCD_WIDTH_EDIT) rows = 2; lcd_width = LCD_WIDTH_EDIT + 1; char_width = DOG_CHAR_WIDTH_EDIT; lcd_setFont(FONT_MENU_EDIT); @@ -890,16 +890,21 @@ static void lcd_implementation_status_screen() { const uint8_t segmentHeight = u8g.getHeight() / (rows + 1); // 1 / (rows+1) = 1/2 or 1/3 uint8_t baseline = segmentHeight + (DOG_CHAR_HEIGHT_EDIT + 1) / 2; - if (PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline)) { + bool onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline); + if (onpage) { u8g.setPrintPos(0, baseline); lcd_printPGM(pstr); } if (value != NULL) { - baseline += (rows - 1) * segmentHeight; - if (PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline)) { - u8g.print(':'); - u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, baseline); + u8g.print(':'); + if (rows == 2) { + baseline += segmentHeight; + onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline); + } + if (onpage) { + u8g.setPrintPos(((lcd_width - 1) - (vallen + 1)) * char_width, baseline); // Right-justified, leaving padded by spaces + u8g.print(' '); // overwrite char if value gets shorter lcd_print(value); } } diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h index 65ad28165..9ec03f0c8 100644 --- a/Marlin/ultralcd_impl_HD44780.h +++ b/Marlin/ultralcd_impl_HD44780.h @@ -978,7 +978,9 @@ static void lcd_implementation_status_screen() { lcd_printPGM(pstr); if (value != NULL) { lcd.print(':'); - lcd.setCursor(LCD_WIDTH - lcd_strlen(value), 1); + const uint8_t valrow = (lcd_strlen_P(pstr) + 1 + lcd_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit + lcd.setCursor((LCD_WIDTH - 1) - (lcd_strlen(value) + 1), valrow); // Right-justified, padded by spaces + lcd.print(' '); // overwrite char if value gets shorter lcd_print(value); } }