@@ -1699,27 +1699,31 @@ void MarlinUI::refresh() {
16991699
17001700#define ICON_Folder ICON_More
17011701
1702- char shift_name[LONG_FILENAME_LENGTH + 1 ];
1703- int8_t shift_amt; // = 0
1704- millis_t shift_ms; // = 0
1702+ #if ENABLED(SCROLL_LONG_FILENAMES)
17051703
1706- // Init the shift name based on the highlighted item
1707- inline void Init_Shift_Name () {
1708- const bool is_subdir = !card.flag .workDirIsRoot ;
1709- const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
1710- const uint16_t fileCnt = card.get_num_Files ();
1711- if (WITHIN (filenum, 0 , fileCnt - 1 )) {
1712- card.getfilename_sorted (SD_ORDER (filenum, fileCnt));
1713- char * const name = card.longest_filename ();
1714- make_name_without_ext (shift_name, name, 100 );
1704+ char shift_name[LONG_FILENAME_LENGTH + 1 ];
1705+ int8_t shift_amt; // = 0
1706+ millis_t shift_ms; // = 0
1707+
1708+ // Init the shift name based on the highlighted item
1709+ inline void Init_Shift_Name () {
1710+ const bool is_subdir = !card.flag .workDirIsRoot ;
1711+ const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
1712+ const uint16_t fileCnt = card.get_num_Files ();
1713+ if (WITHIN (filenum, 0 , fileCnt - 1 )) {
1714+ card.getfilename_sorted (SD_ORDER (filenum, fileCnt));
1715+ char * const name = card.longest_filename ();
1716+ make_name_without_ext (shift_name, name, 100 );
1717+ }
17151718 }
1716- }
17171719
1718- inline void Init_SDItem_Shift () {
1719- shift_amt = 0 ;
1720- shift_ms = select_file.now > 0 && strlen (shift_name) > MENU_CHAR_LIMIT
1721- ? millis () + 750UL : 0 ;
1722- }
1720+ inline void Init_SDItem_Shift () {
1721+ shift_amt = 0 ;
1722+ shift_ms = select_file.now > 0 && strlen (shift_name) > MENU_CHAR_LIMIT
1723+ ? millis () + 750UL : 0 ;
1724+ }
1725+
1726+ #endif
17231727
17241728/* *
17251729 * Display an SD item, adding a CDUP for subfolders.
@@ -1735,37 +1739,42 @@ inline void Draw_SDItem(const uint16_t item, int16_t row=-1) {
17351739 card.getfilename_sorted (item - is_subdir);
17361740 char * const name = card.longest_filename ();
17371741
1738- // Init the current selected name
1739- // This is used during scroll drawing
1740- if (item == select_file.now - 1 ) {
1741- make_name_without_ext (shift_name, name, 100 );
1742- Init_SDItem_Shift ();
1743- }
1742+ #if ENABLED(SCROLL_LONG_FILENAMES)
1743+ // Init the current selected name
1744+ // This is used during scroll drawing
1745+ if (item == select_file.now - 1 ) {
1746+ make_name_without_ext (shift_name, name, 100 );
1747+ Init_SDItem_Shift ();
1748+ }
1749+ #endif
17441750
1751+ // Draw the file/folder with name aligned left
17451752 char str[strlen (name) + 1 ];
1746-
17471753 make_name_without_ext (str, name);
1748-
17491754 Draw_Menu_Line (row, card.flag .filenameIsDir ? ICON_Folder : ICON_File, str);
17501755}
17511756
1752- inline void Draw_SDItem_Shifted (int8_t &shift) {
1753- // Limit to the number of chars past the cutoff
1754- const size_t len = strlen (shift_name);
1755- NOMORE (shift, _MAX ((signed )len - MENU_CHAR_LIMIT, 0 ));
1757+ #if ENABLED(SCROLL_LONG_FILENAMES)
17561758
1757- // Shorten to the available space
1758- const size_t lastchar = _MIN ((signed )len, shift + MENU_CHAR_LIMIT);
1759+ inline void Draw_SDItem_Shifted (int8_t &shift) {
1760+ // Limit to the number of chars past the cutoff
1761+ const size_t len = strlen (shift_name);
1762+ NOMORE (shift, _MAX ((signed )len - MENU_CHAR_LIMIT, 0 ));
17591763
1760- const char c = shift_name[lastchar];
1761- shift_name[ lastchar] = ' \0 ' ;
1764+ // Shorten to the available space
1765+ const size_t lastchar = _MIN (( signed )len, shift + MENU_CHAR_LIMIT) ;
17621766
1763- const uint8_t row = select_file.now + MROWS - index_file; // skip "Back" and scroll
1764- Erase_Menu_Text (row);
1765- Draw_Menu_Line (row, 0 , &shift_name[shift]);
1767+ const char c = shift_name[lastchar];
1768+ shift_name[lastchar] = ' \0 ' ;
17661769
1767- shift_name[lastchar] = c;
1768- }
1770+ const uint8_t row = select_file.now + MROWS - index_file; // skip "Back" and scroll
1771+ Erase_Menu_Text (row);
1772+ Draw_Menu_Line (row, 0 , &shift_name[shift]);
1773+
1774+ shift_name[lastchar] = c;
1775+ }
1776+
1777+ #endif
17691778
17701779// Redraw the first set of SD Files
17711780inline void Redraw_SD_List () {
@@ -1975,21 +1984,23 @@ void HMI_SelectFile(void) {
19751984 const uint16_t hasUpDir = !card.flag .workDirIsRoot ;
19761985
19771986 if (encoder_diffState == ENCODER_DIFF_NO) {
1978- if (shift_ms && select_file.now >= 1 + hasUpDir) {
1979- // Scroll selected filename every second
1980- const millis_t ms = millis ();
1981- if (ELAPSED (ms, shift_ms)) {
1982- const bool was_reset = shift_amt < 0 ;
1983- shift_ms = ms + 375UL + was_reset * 250UL ; // ms per character
1984- int8_t shift_new = shift_amt + 1 ; // Try to shift by...
1985- Draw_SDItem_Shifted (shift_new); // Draw the item
1986- if (!was_reset && shift_new == 0 ) // Was it limited to 0?
1987- shift_ms = 0 ; // No scrolling needed
1988- else if (shift_new == shift_amt) // Scroll reached the end
1989- shift_new = -1 ; // Reset
1990- shift_amt = shift_new; // Set new scroll
1987+ #if ENABLED(SCROLL_LONG_FILENAMES)
1988+ if (shift_ms && select_file.now >= 1 + hasUpDir) {
1989+ // Scroll selected filename every second
1990+ const millis_t ms = millis ();
1991+ if (ELAPSED (ms, shift_ms)) {
1992+ const bool was_reset = shift_amt < 0 ;
1993+ shift_ms = ms + 375UL + was_reset * 250UL ; // ms per character
1994+ int8_t shift_new = shift_amt + 1 ; // Try to shift by...
1995+ Draw_SDItem_Shifted (shift_new); // Draw the item
1996+ if (!was_reset && shift_new == 0 ) // Was it limited to 0?
1997+ shift_ms = 0 ; // No scrolling needed
1998+ else if (shift_new == shift_amt) // Scroll reached the end
1999+ shift_new = -1 ; // Reset
2000+ shift_amt = shift_new; // Set new scroll
2001+ }
19912002 }
1992- }
2003+ # endif
19932004 return ;
19942005 }
19952006
@@ -2001,7 +2012,7 @@ void HMI_SelectFile(void) {
20012012 if (encoder_diffState == ENCODER_DIFF_CW && fullCnt) {
20022013 if (select_file.inc (fullCnt)) {
20032014 const uint8_t itemnum = select_file.now - 1 ; // -1 for "Back"
2004- if (shift_ms) { // If line was shifted
2015+ if (TERN0 (SCROLL_LONG_FILENAMES, shift_ms)) { // If line was shifted
20052016 Erase_Menu_Text (select_file.now - 1 + MROWS - index_file); // Erase and
20062017 Draw_SDItem (itemnum - 1 ); // redraw
20072018 }
@@ -2020,7 +2031,7 @@ void HMI_SelectFile(void) {
20202031 else if (encoder_diffState == ENCODER_DIFF_CCW && fullCnt) {
20212032 if (select_file.dec ()) {
20222033 const uint8_t itemnum = select_file.now - 1 ; // -1 for "Back"
2023- if (shift_ms) { // If line was shifted
2034+ if (TERN0 (SCROLL_LONG_FILENAMES, shift_ms)) { // If line was shifted
20242035 Erase_Menu_Text (select_file.now + 1 + MROWS - index_file); // Erase and
20252036 Draw_SDItem (itemnum + 1 ); // redraw
20262037 }
@@ -2029,7 +2040,7 @@ void HMI_SelectFile(void) {
20292040 Scroll_Menu (DWIN_SCROLL_DOWN);
20302041 if (index_file == MROWS) {
20312042 Draw_Back_First ();
2032- shift_ms = 0 ;
2043+ TERN_ (SCROLL_LONG_FILENAMES, shift_ms = 0 ) ;
20332044 }
20342045 else {
20352046 Draw_SDItem (itemnum, 0 ); // Draw the item (and init shift name)
0 commit comments