From 9f498b8acb48bd08ee85ffb677314ec63cb57eb3 Mon Sep 17 00:00:00 2001 From: thisiskeithb <13375512+thisiskeithb@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:19:26 -0700 Subject: [PATCH 01/19] Fix Endstop Test Menu Remove quotes around axis Min/Max strings and prevent cutting the last character off of filament runout state. --- Marlin/src/lcd/menu/menu_configuration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 4677d63b696c..22bc972046ff 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -105,8 +105,8 @@ void menu_advanced_settings(); #define __STOP_ITEM(F,S) PSTRING_ITEM_F_P(F, TEST(stops, S) ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN), SS_FULL); #define _STOP_ITEM(L,S) __STOP_ITEM(F(L), S) #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) " " STRINGIFY(L), A##I##_##M) - #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,"Min") STOP_ITEM(A,I,MAX,"Max") - #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT") : PSTR("out"), SS_FULL); + #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,Min) STOP_ITEM(A,I,MAX,Max) + #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT ") : PSTR("out "), SS_FULL); static void endstop_test() { if (ui.use_click()) { From 633ea62d945decf1d888711f4d6013bf14905397 Mon Sep 17 00:00:00 2001 From: thisiskeithb <13375512+thisiskeithb@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:46:08 -0700 Subject: [PATCH 02/19] =?UTF-8?q?=F0=9F=8E=A8=20Align=20Endstop=20Test=20I?= =?UTF-8?q?tems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ellensp <530024+ellensp@users.noreply.github.com> --- Marlin/src/lcd/menu/menu_configuration.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 22bc972046ff..0b88de262740 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -104,7 +104,9 @@ void menu_advanced_settings(); #define __STOP_ITEM(F,S) PSTRING_ITEM_F_P(F, TEST(stops, S) ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN), SS_FULL); #define _STOP_ITEM(L,S) __STOP_ITEM(F(L), S) - #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) " " STRINGIFY(L), A##I##_##M) + #define _NEEDS_SPACE(N) TERN0(HAS_##N##_MIN_STATE,1) || TERN0(HAS_##N##_MAX_STATE,1) + #define NEEDS_SPACE _NEEDS_SPACE(X2) || _NEEDS_SPACE(Y2) || _NEEDS_SPACE(Z2) + #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) TERN(I, TERN(NEEDS_SPACE, " ", ""), STRINGIFY(I)) " " STRINGIFY(L), A##I##_##M) #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,Min) STOP_ITEM(A,I,MAX,Max) #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT ") : PSTR("out "), SS_FULL); From eaf663df76f947dd89eed5c6cca6352c44f286a6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 19 Oct 2023 19:48:38 -0500 Subject: [PATCH 03/19] space after index num --- Marlin/src/lcd/menu/menu_configuration.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 0b88de262740..a3e932c77bca 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -104,9 +104,13 @@ void menu_advanced_settings(); #define __STOP_ITEM(F,S) PSTRING_ITEM_F_P(F, TEST(stops, S) ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN), SS_FULL); #define _STOP_ITEM(L,S) __STOP_ITEM(F(L), S) - #define _NEEDS_SPACE(N) TERN0(HAS_##N##_MIN_STATE,1) || TERN0(HAS_##N##_MAX_STATE,1) - #define NEEDS_SPACE _NEEDS_SPACE(X2) || _NEEDS_SPACE(Y2) || _NEEDS_SPACE(Z2) - #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) TERN(I, TERN(NEEDS_SPACE, " ", ""), STRINGIFY(I)) " " STRINGIFY(L), A##I##_##M) + #define _S2_SPACE(N) (HAS_##N##_MIN_STATE || HAS_##N##_MAX_STATE) + #if _S2_SPACE(X2) || _S2_SPACE(Y2) || _S2_SPACE(Z2) + #define S2_SPACE " " + #else + #define S2_SPACE + #endif + #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) S2_SPACE " " STRINGIFY(L), A##I##_##M) #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,Min) STOP_ITEM(A,I,MAX,Max) #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT ") : PSTR("out "), SS_FULL); From 3debdf762a92a0be2cc814d389d1384ed4feaa31 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 19 Oct 2023 20:04:45 -0500 Subject: [PATCH 04/19] space on non-numbered items --- Marlin/src/lcd/menu/menu_configuration.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index a3e932c77bca..fcceaced3854 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -104,13 +104,14 @@ void menu_advanced_settings(); #define __STOP_ITEM(F,S) PSTRING_ITEM_F_P(F, TEST(stops, S) ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN), SS_FULL); #define _STOP_ITEM(L,S) __STOP_ITEM(F(L), S) - #define _S2_SPACE(N) (HAS_##N##_MIN_STATE || HAS_##N##_MAX_STATE) - #if _S2_SPACE(X2) || _S2_SPACE(Y2) || _S2_SPACE(Z2) - #define S2_SPACE " " + #if HAS_X2_STATE || HAS_Y2_STATE || HAS_Z2_STATE + #define _S1_EXP_ ~, + #define _S1_SP_(I) THIRD(I, " ", "") + #define S1_SPACE(I) _S1_SP_(_CAT(_S1_EXP_,I)) #else - #define S2_SPACE + #define S1_SPACE(I) #endif - #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) S2_SPACE " " STRINGIFY(L), A##I##_##M) + #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) S1_SPACE(I) " " STRINGIFY(L), A##I##_##M) #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,Min) STOP_ITEM(A,I,MAX,Max) #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT ") : PSTR("out "), SS_FULL); From 484704ddd6c41e46ce9fdb68a3a479da9df2f4b5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 19 Oct 2023 21:00:33 -0500 Subject: [PATCH 05/19] as string --- Marlin/src/lcd/menu/menu_configuration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index fcceaced3854..d32003b0d2d6 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -111,8 +111,8 @@ void menu_advanced_settings(); #else #define S1_SPACE(I) #endif - #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) S1_SPACE(I) " " STRINGIFY(L), A##I##_##M) - #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,Min) STOP_ITEM(A,I,MAX,Max) + #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) S1_SPACE(I) " " L, A##I##_##M) + #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,"Min") STOP_ITEM(A,I,MAX,"Max") #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT ") : PSTR("out "), SS_FULL); static void endstop_test() { From cc83b8377b3eae98f0ce4427ac02dcc9f8b6ac68 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 13:30:13 -0500 Subject: [PATCH 06/19] outdent, rename --- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 38 ++++++++++------------ Marlin/src/lcd/menu/menu_configuration.cpp | 12 +++---- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index c2671b1b750e..36d3c46af988 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -444,30 +444,28 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Draw a generic menu item void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char, const char post_char) { - if (mark_as_selected(row, sel)) { - uint8_t n = LCD_WIDTH - 1; - n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n); - for (; n; --n) lcd_put_u8str(F(" ")); - lcd_put_lchar(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH), row_y2, post_char); - lcd_put_u8str(F(" ")); - } + if (!mark_as_selected(row, sel)) return; + uint8_t n = LCD_WIDTH - 1; + n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n); + for (; n; --n) lcd_put_u8str(F(" ")); + lcd_put_lchar(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH), row_y2, post_char); + lcd_put_u8str(F(" ")); } // Draw a menu item with an editable value void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) { - if (mark_as_selected(row, sel)) { - const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)), - pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), inStr)); - const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1; - - uint8_t n = LCD_WIDTH - 2 - vallen * prop; - n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n); - if (vallen) { - lcd_put_u8str(F(":")); - for (; n; --n) lcd_put_u8str(F(" ")); - lcd_moveto(LCD_PIXEL_WIDTH - _MAX((MENU_FONT_WIDTH) * vallen, pixelwidth + 2), row_y2); - if (pgm) lcd_put_u8str_P(inStr); else lcd_put_u8str(inStr); - } + if (!mark_as_selected(row, sel)) return; + const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)), + pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), inStr)); + const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1; + + uint8_t n = LCD_WIDTH - 2 - vallen * prop; + n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n); + if (vallen) { + lcd_put_u8str(F(":")); + for (; n; --n) lcd_put_u8str(F(" ")); + lcd_moveto(LCD_PIXEL_WIDTH - _MAX((MENU_FONT_WIDTH) * vallen, pixelwidth + 2), row_y2); + if (pgm) lcd_put_u8str_P(inStr); else lcd_put_u8str(inStr); } } diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index d32003b0d2d6..c5dfe66e7c00 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -78,7 +78,7 @@ void menu_advanced_settings(); #if ENABLED(LCD_PROGRESS_BAR_TEST) - static void progress_bar_test() { + static void screen_progress_bar_test() { static int8_t bar_percent = 0; if (ui.use_click()) { ui.goto_previous_screen(); @@ -93,8 +93,8 @@ void menu_advanced_settings(); lcd_moveto(0, LCD_HEIGHT - 1); ui.draw_progress_bar(bar_percent); } - void _progress_bar_test() { - ui.goto_screen(progress_bar_test); + void _goto_progress_bar_test() { + ui.goto_screen(screen_progress_bar_test); TERN_(HAS_MARLINUI_HD44780, ui.set_custom_characters(CHARSET_INFO)); } @@ -115,7 +115,7 @@ void menu_advanced_settings(); #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,"Min") STOP_ITEM(A,I,MAX,"Max") #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT ") : PSTR("out "), SS_FULL); - static void endstop_test() { + static void screen_endstop_test() { if (ui.use_click()) { ui.goto_previous_screen(); //endstops.enable_globally(false); @@ -155,11 +155,11 @@ void menu_advanced_settings(); BACK_ITEM(MSG_CONFIGURATION); #if ENABLED(LCD_PROGRESS_BAR_TEST) - SUBMENU(MSG_PROGRESS_BAR_TEST, _progress_bar_test); + SUBMENU(MSG_PROGRESS_BAR_TEST, _goto_progress_bar_test); #endif #if ENABLED(LCD_ENDSTOP_TEST) - SUBMENU(MSG_ENDSTOP_TEST, endstop_test); + SUBMENU(MSG_ENDSTOP_TEST, screen_endstop_test); #endif END_MENU(); From 645ec52f07e6ef492382ac965b109979ee5c4f81 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 13:30:53 -0500 Subject: [PATCH 07/19] Pad for expanded label --- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 77 ++++++++++++++-------- Marlin/src/lcd/menu/menu_configuration.cpp | 2 +- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 36d3c46af988..48556121f7e0 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -411,35 +411,60 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Draw a static line of text in the same idiom as a menu item void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) { + if (!mark_as_selected(row, style & SS_INVERT)) return; + + pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed + const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); + int pwide = ftpl ? calculateWidth(ftpl) : 0; + const int owide = pwide; + + //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " vstr=",vstr, " pwide=",pwide); + + // Value length, if any + int vlen = vstr ? utf8_strlen(vstr) : 0; + + bool mv_colon = false; + if (vlen) { + // Move the leading colon from the value to the label below + mv_colon = (*vstr == ':'); + // Shorter value, wider label + if (mv_colon) { vstr++; vlen--; pwide += MENU_FONT_WIDTH; } + // Remove leading spaces from the value and shorten + while (*vstr == ' ') { vstr++; vlen--; } + } - if (mark_as_selected(row, style & SS_INVERT)) { - pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed - - const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); - const int pwide = ftpl ? calculateWidth(ftpl) : 0, - vlen = vstr ? utf8_strlen(vstr) : 0; - int pad = (center || full) ? ((LCD_PIXEL_WIDTH) - pwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0; - - // SS_CENTER: Pad with half of the unused space first - if (center) for (int lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" ")); - - // Draw as much of the label as fits - if (pwide) n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH); - - if (vlen) { - // SS_FULL: Pad with enough space to justify the value - if (full && !center && n > MENU_FONT_WIDTH) { - // Move the leading colon from the value to the label - if (*vstr == ':') { n -= lcd_put_u8str(F(":")); vstr++; } - // Move spaces to the padding - while (*vstr == ' ') { vstr++; pad++; } - // Pad in-between - for (; pad > 0; --pad) n -= lcd_put_u8str(F(" ")); - } - n -= lcd_put_u8str_max(vstr, n); + // Padding for center or full justification + int pad = (center || full) ? ((LCD_PIXEL_WIDTH) - pwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0; + + //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " vstr=",vstr, " pwide=",pwide, " vlen=",vlen, " pad=",pad); + + // SS_CENTER: Pad with half of the unused space first + if (center) for (int lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" ")); + + // Draw as much of the label as fits (without the relocated colon, drawn below) + // The label may be up to 2 chars wider than the assumed width + // which may skew center padding to the right. + if (owide) { + // TODO: Add get_lcd_u8str(...) so this can be done earlier + const int lwide = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH); + n -= lwide; + pad -= (lwide - owide) / (MENU_FONT_WIDTH); + } + + // Value string? + if (vlen) { + // SS_FULL: Pad with enough space to justify the value + if (full && !center && n > MENU_FONT_WIDTH) { + // Draw the leading colon moved from the value to the label + if (mv_colon) n -= lcd_put_u8str(F(":")); + // Pad in-between + for (; pad > 0; --pad) n -= lcd_put_u8str(F(" ")); } - while (n > MENU_FONT_WIDTH) n -= lcd_put_u8str(F(" ")); + // Draw the value string + n -= lcd_put_u8str_max(vstr, n); } + // Always fill out the rest with spaces + while (n > MENU_FONT_WIDTH) n -= lcd_put_u8str(F(" ")); } // Draw a generic menu item diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index c5dfe66e7c00..63b7c527e015 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -113,7 +113,7 @@ void menu_advanced_settings(); #endif #define STOP_ITEM(A,I,M,L) TERN(HAS_##A##I##_##M##_STATE, _STOP_ITEM, _IF_1_ELSE)(STRINGIFY(A) STRINGIFY(I) S1_SPACE(I) " " L, A##I##_##M) #define STOP_MINMAX(A,I) STOP_ITEM(A,I,MIN,"Min") STOP_ITEM(A,I,MAX,"Max") - #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT ") : PSTR("out "), SS_FULL); + #define FIL_ITEM(N) PSTRING_ITEM_N_P(N-1, MSG_FILAMENT_EN, (READ(FIL_RUNOUT##N##_PIN) != FIL_RUNOUT##N##_STATE) ? PSTR("PRESENT") : PSTR("out"), SS_FULL); static void screen_endstop_test() { if (ui.use_click()) { From 1b0e91397dbe0c3aa0af93071484ade90e7ca9a8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 13:37:08 -0500 Subject: [PATCH 08/19] outdent --- Marlin/src/lcd/e3v2/marlinui/ui_common.cpp | 116 ++++++++++----------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp index 27e5b38bd0a3..96eecde15a33 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp @@ -308,91 +308,89 @@ void MarlinUI::draw_status_message(const bool blink) { void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) { // Call mark_as_selected to draw a bigger selection box // and draw the text without a background - if (mark_as_selected(row, (bool)(style & SS_INVERT), true)) { - ui.set_font(DWIN_FONT_MENU); - dwin_font.solid = false; - dwin_font.fg = COLOR_WHITE; + if (!mark_as_selected(row, (bool)(style & SS_INVERT), true)) return; - dwin_string.set(); + ui.set_font(DWIN_FONT_MENU); + dwin_font.solid = false; + dwin_font.fg = COLOR_WHITE; - const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); - const int8_t plen = ftpl ? utf8_strlen(ftpl) : 0, - vlen = vstr ? utf8_strlen(vstr) : 0; - int8_t pad = (center || full) ? (LCD_WIDTH) - 1 - plen - vlen : 0; + dwin_string.set(); - // SS_CENTER: Pad with half of the unused space first - if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) dwin_string.add(' '); + const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); + const int8_t plen = ftpl ? utf8_strlen(ftpl) : 0, + vlen = vstr ? utf8_strlen(vstr) : 0; + int8_t pad = (center || full) ? (LCD_WIDTH) - 1 - plen - vlen : 0; - // Append the templated label string - if (plen) { - dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF); - pad -= dwin_string.length - plen; - } + // SS_CENTER: Pad with half of the unused space first + if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) dwin_string.add(' '); - // SS_FULL: Pad with enough space to justify the value - if (vlen) { - if (full && !center) { - // Move the leading colon from the value to the label - if (*vstr == ':') { dwin_string.add(':'); vstr++; } - // Move spaces to the padding - while (*vstr == ' ') { vstr++; pad++; } - // Pad in-between - for (; pad > 0; --pad) dwin_string.add(' '); - } - // Append the value - dwin_string.add(vstr); + // Append the templated label string + if (plen) { + dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF); + pad -= dwin_string.length - plen; + } + + // SS_FULL: Pad with enough space to justify the value + if (vlen) { + if (full && !center) { + // Move the leading colon from the value to the label + if (*vstr == ':') { dwin_string.add(':'); vstr++; } + // Move spaces to the padding + while (*vstr == ' ') { vstr++; pad++; } + // Pad in-between + for (; pad > 0; --pad) dwin_string.add(' '); } + // Append the value + dwin_string.add(vstr); + } - // SS_CENTER: Pad the rest of the string - if (center) for (int8_t rpad = pad - (pad / 2); rpad > 0; --rpad) dwin_string.add(' '); + // SS_CENTER: Pad the rest of the string + if (center) for (int8_t rpad = pad - (pad / 2); rpad > 0; --rpad) dwin_string.add(' '); - lcd_moveto(1, row); - lcd_put_dwin_string(); - } + lcd_moveto(1, row); + lcd_put_dwin_string(); } // Draw a generic menu item void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char, const char post_char) { - if (mark_as_selected(row, sel)) { - ui.set_font(DWIN_FONT_MENU); - dwin_font.solid = false; - dwin_font.fg = COLOR_WHITE; + if (!mark_as_selected(row, sel)) return; + ui.set_font(DWIN_FONT_MENU); + dwin_font.solid = false; + dwin_font.fg = COLOR_WHITE; - dwin_string.set(ftpl, itemIndex, itemStringC, itemStringF); + dwin_string.set(ftpl, itemIndex, itemStringC, itemStringF); - pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length; - while (--n > 1) dwin_string.add(' '); + pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length; + while (--n > 1) dwin_string.add(' '); - dwin_string.add(post_char); + dwin_string.add(post_char); - lcd_moveto(1, row); - lcd_put_dwin_string(); - } + lcd_moveto(1, row); + lcd_put_dwin_string(); } // // Draw a menu item with an editable value // void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) { - if (mark_as_selected(row, sel)) { - ui.set_font(DWIN_FONT_MENU); - dwin_font.solid = false; - dwin_font.fg = COLOR_WHITE; + if (!mark_as_selected(row, sel)) return; + ui.set_font(DWIN_FONT_MENU); + dwin_font.solid = false; + dwin_font.fg = COLOR_WHITE; - const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(S(inStr))); + const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(S(inStr))); - dwin_string.set(ftpl, itemIndex, itemStringC, itemStringF); - if (vallen) dwin_string.add(':'); + dwin_string.set(ftpl, itemIndex, itemStringC, itemStringF); + if (vallen) dwin_string.add(':'); - lcd_moveto(1, row); - lcd_put_dwin_string(); + lcd_moveto(1, row); + lcd_put_dwin_string(); - if (vallen) { - dwin_font.fg = COLOR_YELLOW; - dwin_string.set(inStr); - lcd_moveto(LCD_WIDTH - vallen - 1, row); - lcd_put_dwin_string(); - } + if (vallen) { + dwin_font.fg = COLOR_YELLOW; + dwin_string.set(inStr); + lcd_moveto(LCD_WIDTH - vallen - 1, row); + lcd_put_dwin_string(); } } From 77be6425968cb6e61a6d63d85bf3dc657745a42f Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 13:52:28 -0500 Subject: [PATCH 09/19] Also E3V2 --- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 4 +-- Marlin/src/lcd/e3v2/marlinui/ui_common.cpp | 31 +++++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 48556121f7e0..1686985afd3a 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -418,11 +418,11 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop int pwide = ftpl ? calculateWidth(ftpl) : 0; const int owide = pwide; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " vstr=",vstr, " pwide=",pwide); - // Value length, if any int vlen = vstr ? utf8_strlen(vstr) : 0; + //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " owide=",owide, " vstr=",vstr, " vlen=",vlen); + bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp index 96eecde15a33..52376a56d660 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp @@ -317,26 +317,43 @@ void MarlinUI::draw_status_message(const bool blink) { dwin_string.set(); const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); - const int8_t plen = ftpl ? utf8_strlen(ftpl) : 0, - vlen = vstr ? utf8_strlen(vstr) : 0; + int8_t plen = ftpl ? utf8_strlen(ftpl) : 0; + const int8_t olen = plen; + + // Value length, if any + int8_t vlen = vstr ? utf8_strlen(vstr) : 0; + + //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " olen=",olen, " vstr=",vstr, " vlen=",vlen); + + bool mv_colon = false; + if (vlen) { + // Move the leading colon from the value to the label below + mv_colon = (*vstr == ':'); + // Shorter value, wider label + if (mv_colon) { vstr++; vlen--; plen++; } + // Remove leading spaces from the value and shorten + while (*vstr == ' ') { vstr++; vlen--; } + } + int8_t pad = (center || full) ? (LCD_WIDTH) - 1 - plen - vlen : 0; + //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " plen=",plen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); + // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) dwin_string.add(' '); - // Append the templated label string if (plen) { + // Append the templated label string dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF); + // Remove padding if the string was expanded pad -= dwin_string.length - plen; } // SS_FULL: Pad with enough space to justify the value if (vlen) { if (full && !center) { - // Move the leading colon from the value to the label - if (*vstr == ':') { dwin_string.add(':'); vstr++; } - // Move spaces to the padding - while (*vstr == ' ') { vstr++; pad++; } + // Append the leading colon moved from the value to the label + if (mv_colon) dwin_string.add(':'); // Pad in-between for (; pad > 0; --pad) dwin_string.add(' '); } From 6a4df7ccbc1600677b7756ed369ab20cd14cbe86 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 14:01:10 -0500 Subject: [PATCH 10/19] =?UTF-8?q?=E2=80=A6and=20char=20lcd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 31 ++++++++++++++++----- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 2 +- Marlin/src/lcd/menu/menu.h | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 3206cb63347c..6c03ea311a7c 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -1165,28 +1165,45 @@ void MarlinUI::draw_status_screen() { #endif // ADVANCED_PAUSE_FEATURE // Draw a static item with no left-right margin required. Centered by default. - void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) { + void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) { lcd_moveto(0, row); int8_t n = LCD_WIDTH; const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); - const int8_t plen = fstr ? utf8_strlen(fstr) : 0, - vlen = vstr ? utf8_strlen(vstr) : 0; + int8_t plen = ftpl ? utf8_strlen(ftpl) : 0; + const int8_t olen = plen; + + // Value length, if any + int8_t vlen = vstr ? utf8_strlen(vstr) : 0; + + //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " olen=",olen, " vstr=",vstr, " vlen=",vlen); + + bool mv_colon = false; + if (vlen) { + // Move the leading colon from the value to the label below + mv_colon = (*vstr == ':'); + // Shorter value, wider label + if (mv_colon) { vstr++; vlen--; plen++; } + // Remove leading spaces from the value and shorten + while (*vstr == ' ') { vstr++; vlen--; } + } + + // Padding for center or full justification int8_t pad = (center || full) ? n - plen - vlen : 0; + //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " plen=",plen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); + // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd_put_u8str(F(" ")); n--; } // Draw as much of the label as fits - if (plen) n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n - vlen); + if (plen) n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n - vlen); if (vlen && n > 0) { // SS_FULL: Pad with enough space to justify the value if (full && !center) { // Move the leading colon from the value to the label - if (*vstr == ':') { n -= lcd_put_u8str(F(":")); vstr++; } - // Move spaces to the padding - while (*vstr == ' ') { vstr++; pad++; } + if (mv_colon) n -= lcd_put_u8str(F(":")); // Pad in-between for (; pad > 0; --pad) { lcd_put_u8str(F(" ")); n--; } } diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 1686985afd3a..50774efa07a5 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -436,7 +436,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Padding for center or full justification int pad = (center || full) ? ((LCD_PIXEL_WIDTH) - pwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0; - //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " vstr=",vstr, " pwide=",pwide, " vlen=",vlen, " pad=",pad); + //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " pwide=",pwide, " vstr=",vstr, " vlen=",vlen, " pad=",pad); // SS_CENTER: Pad with half of the unused space first if (center) for (int lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" ")); diff --git a/Marlin/src/lcd/menu/menu.h b/Marlin/src/lcd/menu/menu.h index d4cbfd7a73d5..9bb785e927e8 100644 --- a/Marlin/src/lcd/menu/menu.h +++ b/Marlin/src/lcd/menu/menu.h @@ -76,7 +76,7 @@ class MenuItemBase { // STATIC_ITEM(LABEL,...) class MenuItem_static : public MenuItemBase { public: - static void draw(const uint8_t row, FSTR_P const fstr, const uint8_t style=SS_DEFAULT, const char *vstr=nullptr); + static void draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style=SS_DEFAULT, const char *vstr=nullptr); }; // BACK_ITEM(LABEL) From abca6e53061c97dc093faabf0f3ed45dd2bc0dc9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 14:20:50 -0500 Subject: [PATCH 11/19] char lcd pad --- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 14 ++++++++++---- Marlin/src/lcd/e3v2/marlinui/ui_common.cpp | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 6c03ea311a7c..c0e073041409 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -1194,10 +1194,16 @@ void MarlinUI::draw_status_screen() { //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " plen=",plen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); // SS_CENTER: Pad with half of the unused space first - if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd_put_u8str(F(" ")); n--; } - - // Draw as much of the label as fits - if (plen) n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n - vlen); + if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad, --pad, --n) lcd_put_u8str(F(" ")); + + // Draw as much of the label as fits (without the relocated colon, drawn below) + // The label may be up to 2 chars wider than the assumed width + // which may skew center padding to the right. + if (olen) { + const int8_t llen = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n - vlen); + n -= llen; + pad -= llen - olen; + } if (vlen && n > 0) { // SS_FULL: Pad with enough space to justify the value diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp index 52376a56d660..94892154b8f1 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp @@ -340,13 +340,13 @@ void MarlinUI::draw_status_message(const bool blink) { //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " plen=",plen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); // SS_CENTER: Pad with half of the unused space first - if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) dwin_string.add(' '); + if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad, --pad) dwin_string.add(' '); if (plen) { // Append the templated label string dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF); // Remove padding if the string was expanded - pad -= dwin_string.length - plen; + pad -= dwin_string.length - olen; } // SS_FULL: Pad with enough space to justify the value @@ -362,7 +362,7 @@ void MarlinUI::draw_status_message(const bool blink) { } // SS_CENTER: Pad the rest of the string - if (center) for (int8_t rpad = pad - (pad / 2); rpad > 0; --rpad) dwin_string.add(' '); + if (center) while (pad--) dwin_string.add(' '); lcd_moveto(1, row); lcd_put_dwin_string(); From 0470b9bfca4ca5e815cc4be982af7c96b0561345 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 16:45:39 -0500 Subject: [PATCH 12/19] label string expansion --- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 22 +++---- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 39 ++++++++---- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 26 ++++---- Marlin/src/lcd/lcdprint.cpp | 66 ++++++++++++++++----- Marlin/src/lcd/lcdprint.h | 33 +++++++++-- 5 files changed, 126 insertions(+), 60 deletions(-) diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index c0e073041409..2db721d126ca 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -1170,40 +1170,36 @@ void MarlinUI::draw_status_screen() { int8_t n = LCD_WIDTH; const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); - int8_t plen = ftpl ? utf8_strlen(ftpl) : 0; - const int8_t olen = plen; // Value length, if any int8_t vlen = vstr ? utf8_strlen(vstr) : 0; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " olen=",olen, " vstr=",vstr, " vlen=",vlen); + // Expanded label string and width in chars + char estr[calculateWidth(ftpl) + 3] = "\0"; + int8_t llen = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; + + //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " llen=",llen, " vstr=",vstr, " vlen=",vlen); bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below mv_colon = (*vstr == ':'); // Shorter value, wider label - if (mv_colon) { vstr++; vlen--; plen++; } + if (mv_colon) { vstr++; vlen--; llen++; } // Remove leading spaces from the value and shorten while (*vstr == ' ') { vstr++; vlen--; } } // Padding for center or full justification - int8_t pad = (center || full) ? n - plen - vlen : 0; + int8_t pad = (center || full) ? n - llen - vlen : 0; - //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " plen=",plen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); + //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " llen=",llen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad, --pad, --n) lcd_put_u8str(F(" ")); // Draw as much of the label as fits (without the relocated colon, drawn below) - // The label may be up to 2 chars wider than the assumed width - // which may skew center padding to the right. - if (olen) { - const int8_t llen = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n - vlen); - n -= llen; - pad -= llen - olen; - } + if (llen) n -= lcd_put_u8str_max(estr, n - vlen); if (vlen && n > 0) { // SS_FULL: Pad with enough space to justify the value diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 2d621d74cf2e..9bce4d9c33a9 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -969,29 +969,44 @@ void MarlinUI::draw_status_screen() { #endif // Draw a static item with no left-right margin required. Centered by default. - void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) { + void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) { if (!PanelDetected) return; lcd_moveto(0, row); uint8_t n = LCD_WIDTH; const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); - const int8_t plen = fstr ? utf8_strlen(fstr) : 0, - vlen = vstr ? utf8_strlen(vstr) : 0; - int8_t pad = (center || full) ? n - plen - vlen : 0; + + // Value length, if any + int8_t vlen = vstr ? utf8_strlen(vstr) : 0; + + char estr[utf8_strlen(ftpl) + 3] = "\0"; + int8_t lwide = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; + + int8_t pad = (center || full) ? n - lwide - vlen : 0; + + //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " lwide=",lwide, " vstr=",vstr, " vlen=",vlen); + + bool mv_colon = false; + if (vlen) { + // Move the leading colon from the value to the label below + mv_colon = (*vstr == ':'); + // Shorter value, wider label + if (mv_colon) { vstr++; vlen--; lwide += MENU_FONT_WIDTH; } + // Remove leading spaces from the value and shorten + while (*vstr == ' ') { vstr++; vlen--; } + } // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd.write(' '); n--; } // Draw as much of the label as fits - if (plen) n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n - vlen); + if (lwide) n -= lcd_put_u8str_max(estr, n - vlen); if (vlen && n > 0) { // SS_FULL: Pad with enough space to justify the value if (full && !center) { // Move the leading colon from the value to the label - if (*vstr == ':') { lcd.write(':'); vstr++; n--; } - // Move spaces to the padding - while (*vstr == ' ') { vstr++; pad++; } + if (mv_colon) { lcd.write(':'); n--; } // Pad in-between for (; pad > 0; --pad) { lcd.write(' '); n--; } } @@ -1004,25 +1019,25 @@ void MarlinUI::draw_status_screen() { } // Draw a generic menu item with pre_char (if selected) and post_char - void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char pre_char, const char post_char) { + void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char pre_char, const char post_char) { if (!PanelDetected) return; lcd_moveto(0, row); lcd.write(sel ? pre_char : ' '); uint8_t n = LCD_WIDTH - 2; - n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n); + n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n); for (; n; --n) lcd.write(' '); lcd.write(post_char); lcd.print_line(); } // Draw a menu item with a (potentially) editable value - void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char * const inStr, const bool pgm) { + void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) { if (!PanelDetected) return; const uint8_t vlen = inStr ? (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)) : 0; lcd_moveto(0, row); lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' '); uint8_t n = LCD_WIDTH - 2 - vlen; - n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n); + n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n); if (vlen) { lcd.write(':'); for (; n; --n) lcd.write(' '); diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 50774efa07a5..61528790a2c1 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -415,41 +415,35 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL); - int pwide = ftpl ? calculateWidth(ftpl) : 0; - const int owide = pwide; + + char estr[calculateWidth(ftpl) + 3] = "\0"; + pixel_len_t lwide = ftpl ? (MENU_FONT_WIDTH) * expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, (LCD_PIXEL_WIDTH) / (MENU_FONT_WIDTH)) : 0; // Value length, if any - int vlen = vstr ? utf8_strlen(vstr) : 0; + int8_t vlen = vstr ? utf8_strlen(vstr) : 0; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " owide=",owide, " vstr=",vstr, " vlen=",vlen); + //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " lwide=",lwide, " vstr=",vstr, " vlen=",vlen); bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below mv_colon = (*vstr == ':'); // Shorter value, wider label - if (mv_colon) { vstr++; vlen--; pwide += MENU_FONT_WIDTH; } + if (mv_colon) { vstr++; vlen--; lwide += MENU_FONT_WIDTH; } // Remove leading spaces from the value and shorten while (*vstr == ' ') { vstr++; vlen--; } } // Padding for center or full justification - int pad = (center || full) ? ((LCD_PIXEL_WIDTH) - pwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0; + int8_t pad = (center || full) ? ((LCD_PIXEL_WIDTH) - lwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0; - //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " pwide=",pwide, " vstr=",vstr, " vlen=",vlen, " pad=",pad); + //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " vstr=",vstr, " vlen=",vlen, " pad=",pad); // SS_CENTER: Pad with half of the unused space first - if (center) for (int lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" ")); + if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" ")); // Draw as much of the label as fits (without the relocated colon, drawn below) - // The label may be up to 2 chars wider than the assumed width - // which may skew center padding to the right. - if (owide) { - // TODO: Add get_lcd_u8str(...) so this can be done earlier - const int lwide = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH); - n -= lwide; - pad -= (lwide - owide) / (MENU_FONT_WIDTH); - } + if (lwide) lcd_put_u8str_max(estr, n); // Value string? if (vlen) { diff --git a/Marlin/src/lcd/lcdprint.cpp b/Marlin/src/lcd/lcdprint.cpp index bdf2513121ec..dffebc73deea 100644 --- a/Marlin/src/lcd/lcdprint.cpp +++ b/Marlin/src/lcd/lcdprint.cpp @@ -32,9 +32,9 @@ #include "lcdprint.h" /** - * lcd_put_u8str_P + * expand_u8str_P * - * Print a string with optional substitutions: + * Expand a string with optional substitutions: * * $ displays the clipped string given by fstr or cstr * { displays '0'....'10' for indexes 0 - 10 @@ -44,9 +44,10 @@ * * Return the number of characters emitted */ -lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) { +lcd_uint_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t ind, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) { const uint8_t prop = USE_WIDE_GLYPH ? 2 : 1; const uint8_t *p = (uint8_t*)ptpl; + char *o = outstr; int8_t n = maxlen; while (n > 0) { lchar_t wc; @@ -54,43 +55,80 @@ lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/ if (!wc) break; if (wc == '{' || wc == '~' || wc == '*') { if (ind >= 0) { - if (wc == '*') { lcd_put_u8str(F("E")); n--; } + if (wc == '*') { *o++ = 'E'; n--; } if (n) { int8_t inum = ind + ((wc == '{') ? 0 : LCD_FIRST_TOOL); if (inum >= 10) { - lcd_put_lchar('0' + (inum / 10)); n--; + *o++ = ('0' + (inum / 10)); n--; inum %= 10; } - if (n) { lcd_put_lchar('0' + inum); n--; } + if (n) { *o++ = '0' + inum; n--; } } } else { PGM_P const b = ind == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED); - n -= lcd_put_u8str_max_P(b, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH); + strncpy_P(o, b, n); + n -= utf8_strlen_P(b); + o += strlen(o); } - if (n) { - n -= lcd_put_u8str_max_P((PGM_P)p, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH); + if (n > 0) { + strncpy_P(o, (PGM_P)p, n); + n -= utf8_strlen(o); + o += strlen(o); break; } } else if (wc == '$' && fstr) { - n -= lcd_put_u8str_max_P(FTOP(fstr), n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH); + strncpy_P(o, FTOP(fstr), n); + n -= utf8_strlen_P(FTOP(fstr)); + o += strlen(o); } else if (wc == '$' && cstr) { - n -= lcd_put_u8str_max(cstr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH); + strncpy(o, cstr, n); + n -= utf8_strlen(o); + o += strlen(o); } else if (wc == '@') { - lcd_put_lchar(AXIS_CHAR(ind)); + *o++ = AXIS_CHAR(ind); + *o = '\0'; + n--; + } + else if (wc > 255 && prop == 2) { + // Wide glyph support incomplete + *((uint16_t*)o) = wc; + o += 2; + *o = '\0'; n--; } else { - lcd_put_lchar(wc); - n -= wc > 255 ? prop : 1; + *o++ = wc; + *o = '\0'; + n--; } } return maxlen - n; } +/** + * lcd_put_u8str_P + * + * Print a string with optional substitutions: + * + * $ displays the clipped string given by fstr or cstr + * { displays '0'....'10' for indexes 0 - 10 + * ~ displays '1'....'11' for indexes 0 - 10 + * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL) + * @ displays an axis name such as XYZUVW, or E for an extruder + * + * Return the number of characters emitted + */ +lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) { + char estr[maxlen + 2]; + lcd_uint_t outlen = expand_u8str_P(estr, ptpl, ind, cstr, fstr, maxlen); + lcd_put_u8str_max(estr, maxlen * (MENU_FONT_WIDTH)); + return outlen; +} + // Calculate UTF8 width with a simple check int calculateWidth(PGM_P const pstr) { if (!USE_WIDE_GLYPH) return utf8_strlen_P(pstr) * MENU_FONT_WIDTH; diff --git a/Marlin/src/lcd/lcdprint.h b/Marlin/src/lcd/lcdprint.h index 9ba514791894..87032201fb0c 100644 --- a/Marlin/src/lcd/lcdprint.h +++ b/Marlin/src/lcd/lcdprint.h @@ -205,14 +205,37 @@ inline int lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, FSTR_P cons return lcd_put_u8str_P(col, row, FTOP(fstr)); } +/** + * @brief Expand a string with optional substitution + * @details Expand a string with optional substitutions: + * $ : the clipped string given by fstr or cstr + * { : '0'....'10' for indexes 0 - 10 + * ~ : '1'....'11' for indexes 0 - 10 + * * : 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL) + * @ : an axis name such as XYZUVW, or E for an extruder + * + * @param *outstr The output destination buffer + * @param ptpl A ROM string (template) + * @param ind An index value to use for = ~ * substitution + * @param cstr An SRAM C-string to use for $ substitution + * @param fstr A ROM F-string to use for $ substitution + * @param maxlen The maximum size of the string (in pixels on GLCD) + * @return the output width (in pixels on GLCD) + */ +lcd_uint_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH); + +inline lcd_uint_t expand_u8str(char * const outstr, FSTR_P const ftpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) { + return expand_u8str_P(outstr, FTOP(ftpl), ind, cstr, fstr, maxlen); +} + /** * @brief Draw a string with optional substitution * @details Print a string with optional substitutions: - * $ displays the clipped string given by fstr or cstr - * { displays '0'....'10' for indexes 0 - 10 - * ~ displays '1'....'11' for indexes 0 - 10 - * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL) - * @ displays an axis name such as XYZUVW, or E for an extruder + * $ : the clipped string given by fstr or cstr + * { : '0'....'10' for indexes 0 - 10 + * ~ : '1'....'11' for indexes 0 - 10 + * * : 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL) + * @ : an axis name such as XYZUVW, or E for an extruder * * @param ptpl A ROM string (template) * @param ind An index value to use for = ~ * substitution From 006365ac8b8f0f58b744c3a0960c8181a41c1194 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 16:51:23 -0500 Subject: [PATCH 13/19] fix pad --- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 9bce4d9c33a9..ae2d85f12112 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -982,8 +982,6 @@ void MarlinUI::draw_status_screen() { char estr[utf8_strlen(ftpl) + 3] = "\0"; int8_t lwide = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; - int8_t pad = (center || full) ? n - lwide - vlen : 0; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " lwide=",lwide, " vstr=",vstr, " vlen=",vlen); bool mv_colon = false; @@ -996,6 +994,8 @@ void MarlinUI::draw_status_screen() { while (*vstr == ' ') { vstr++; vlen--; } } + int8_t pad = (center || full) ? n - lwide - vlen : 0; + // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd.write(' '); n--; } From 5cceab5fe42bb50ead98055c8a21bcee821d122c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 16:54:17 -0500 Subject: [PATCH 14/19] clean up --- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 4 ---- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 2 -- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 4 ---- Marlin/src/lcd/e3v2/marlinui/ui_common.cpp | 4 ---- 4 files changed, 14 deletions(-) diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 2db721d126ca..ce19cb35ed9f 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -1178,8 +1178,6 @@ void MarlinUI::draw_status_screen() { char estr[calculateWidth(ftpl) + 3] = "\0"; int8_t llen = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " llen=",llen, " vstr=",vstr, " vlen=",vlen); - bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below @@ -1193,8 +1191,6 @@ void MarlinUI::draw_status_screen() { // Padding for center or full justification int8_t pad = (center || full) ? n - llen - vlen : 0; - //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " llen=",llen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); - // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad, --pad, --n) lcd_put_u8str(F(" ")); diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index ae2d85f12112..f84b4e4b67d6 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -982,8 +982,6 @@ void MarlinUI::draw_status_screen() { char estr[utf8_strlen(ftpl) + 3] = "\0"; int8_t lwide = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " lwide=",lwide, " vstr=",vstr, " vlen=",vlen); - bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 61528790a2c1..3bc484e6e3f3 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -422,8 +422,6 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Value length, if any int8_t vlen = vstr ? utf8_strlen(vstr) : 0; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " lwide=",lwide, " vstr=",vstr, " vlen=",vlen); - bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below @@ -437,8 +435,6 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop // Padding for center or full justification int8_t pad = (center || full) ? ((LCD_PIXEL_WIDTH) - lwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0; - //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " vstr=",vstr, " vlen=",vlen, " pad=",pad); - // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" ")); diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp index 94892154b8f1..f7c463e88f29 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp @@ -323,8 +323,6 @@ void MarlinUI::draw_status_message(const bool blink) { // Value length, if any int8_t vlen = vstr ? utf8_strlen(vstr) : 0; - //if (full) SERIAL_ECHOLNPGM("A: (", row, ") ftpl=",ftpl, " olen=",olen, " vstr=",vstr, " vlen=",vlen); - bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below @@ -337,8 +335,6 @@ void MarlinUI::draw_status_message(const bool blink) { int8_t pad = (center || full) ? (LCD_WIDTH) - 1 - plen - vlen : 0; - //if (full) SERIAL_ECHOLNPGM("B: (", row, ") ftpl=",ftpl, " plen=",plen, " vstr=",vstr, " vlen=",vlen, " pad=",pad); - // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad, --pad) dwin_string.add(' '); From 6554bfa32c581e50bef063a96366170aeb041769 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 16:56:24 -0500 Subject: [PATCH 15/19] char width --- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index f84b4e4b67d6..68ee222480be 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -980,7 +980,7 @@ void MarlinUI::draw_status_screen() { int8_t vlen = vstr ? utf8_strlen(vstr) : 0; char estr[utf8_strlen(ftpl) + 3] = "\0"; - int8_t lwide = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; + int8_t lwide = ftpl ? (MENU_FONT_WIDTH) * expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; bool mv_colon = false; if (vlen) { From f9bd39f5c92fba40cbaae1e6ce2295ab25242e5d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 16:59:15 -0500 Subject: [PATCH 16/19] tft --- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 68ee222480be..b13f26c64450 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -980,14 +980,14 @@ void MarlinUI::draw_status_screen() { int8_t vlen = vstr ? utf8_strlen(vstr) : 0; char estr[utf8_strlen(ftpl) + 3] = "\0"; - int8_t lwide = ftpl ? (MENU_FONT_WIDTH) * expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; + int8_t lwide = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below mv_colon = (*vstr == ':'); // Shorter value, wider label - if (mv_colon) { vstr++; vlen--; lwide += MENU_FONT_WIDTH; } + if (mv_colon) { vstr++; vlen--; lwide++; } // Remove leading spaces from the value and shorten while (*vstr == ' ') { vstr++; vlen--; } } From 30b2753188b439ee7595dd99b7a2f99293b29af7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 17:00:54 -0500 Subject: [PATCH 17/19] llen --- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index b13f26c64450..a4d358c06311 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -980,25 +980,25 @@ void MarlinUI::draw_status_screen() { int8_t vlen = vstr ? utf8_strlen(vstr) : 0; char estr[utf8_strlen(ftpl) + 3] = "\0"; - int8_t lwide = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; + int8_t llen = ftpl ? expand_u8str(estr, ftpl, itemIndex, itemStringC, itemStringF, n - vlen) : 0; bool mv_colon = false; if (vlen) { // Move the leading colon from the value to the label below mv_colon = (*vstr == ':'); // Shorter value, wider label - if (mv_colon) { vstr++; vlen--; lwide++; } + if (mv_colon) { vstr++; vlen--; llen++; } // Remove leading spaces from the value and shorten while (*vstr == ' ') { vstr++; vlen--; } } - int8_t pad = (center || full) ? n - lwide - vlen : 0; + int8_t pad = (center || full) ? n - llen - vlen : 0; // SS_CENTER: Pad with half of the unused space first if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd.write(' '); n--; } // Draw as much of the label as fits - if (lwide) n -= lcd_put_u8str_max(estr, n - vlen); + if (llen) n -= lcd_put_u8str_max(estr, n - vlen); if (vlen && n > 0) { // SS_FULL: Pad with enough space to justify the value From 66a8343ae67a52652249dc4c17c97aaba717c0c7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Oct 2023 17:32:53 -0500 Subject: [PATCH 18/19] misc. --- Marlin/src/lcd/lcdprint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/lcd/lcdprint.cpp b/Marlin/src/lcd/lcdprint.cpp index dffebc73deea..2b524e983f7e 100644 --- a/Marlin/src/lcd/lcdprint.cpp +++ b/Marlin/src/lcd/lcdprint.cpp @@ -124,7 +124,7 @@ lcd_uint_t expand_u8str_P(char * const outstr, PGM_P const ptpl, const int8_t in */ lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) { char estr[maxlen + 2]; - lcd_uint_t outlen = expand_u8str_P(estr, ptpl, ind, cstr, fstr, maxlen); + const lcd_uint_t outlen = expand_u8str_P(estr, ptpl, ind, cstr, fstr, maxlen); lcd_put_u8str_max(estr, maxlen * (MENU_FONT_WIDTH)); return outlen; } From aa269f19a6ceafa84d75bef83f1491c1d944f0e5 Mon Sep 17 00:00:00 2001 From: Sascha Date: Sat, 21 Oct 2023 22:27:24 +0200 Subject: [PATCH 19/19] Update cardreader.cpp If an sd card is removed using the menu the ui won't be updated, just update the menu if the flag NO_SD_DETECT is enabled. --- Marlin/src/sd/cardreader.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 8ec33d1f72ef..0bbde43dc5cc 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -588,6 +588,10 @@ void CardReader::release() { flag.workDirIsRoot = true; nrItems = -1; SERIAL_ECHO_MSG(STR_SD_CARD_RELEASED); + + #if ENABLED(NO_SD_DETECT) + ui.refresh(); + #endif } /**