-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Touch UI long filenames fixes (#19262)
* Improvements to FTDI DLCache functionality. * Better handling of long file names in Touch UI - Long file names now truncated and shown with ellipsis. - Increased display cache buffer to allow for longer filenames. - Visual error message when display cache is exceeded.
- Loading branch information
Showing
9 changed files
with
187 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,5 @@ | |
#include "sound_list.h" | ||
#include "polygon.h" | ||
#include "text_box.h" | ||
#include "text_ellipsis.h" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/********************* | ||
* text_ellipsis.cpp * | ||
*********************/ | ||
|
||
/**************************************************************************** | ||
* Written By Marcio Teixeira 2019 - Aleph Objects, Inc. * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* To view a copy of the GNU General Public License, go to the following * | ||
* location: <https://www.gnu.org/licenses/>. * | ||
****************************************************************************/ | ||
|
||
#include "ftdi_extended.h" | ||
|
||
#ifdef FTDI_EXTENDED | ||
|
||
namespace FTDI { | ||
|
||
/** | ||
* Helper function for drawing text with ellipses. The str buffer may be modified and should have space for up to two extra characters. | ||
*/ | ||
static void _draw_text_with_ellipsis(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, char *str, uint16_t options, uint8_t font) { | ||
FontMetrics fm(font); | ||
const uint16_t ellipsisWidth = fm.get_char_width('.') * 3; | ||
|
||
// Compute the total line length, as well as | ||
// the location in the string where it can | ||
// split and still allow the ellipsis to fit. | ||
uint16_t lineWidth = 0; | ||
char *breakPoint = str; | ||
for(char* c = str; *c; c++) { | ||
lineWidth += fm.get_char_width(*c); | ||
if(lineWidth + ellipsisWidth < w) | ||
breakPoint = c; | ||
} | ||
|
||
if(lineWidth > w) { | ||
*breakPoint = '\0'; | ||
strcpy_P(breakPoint,PSTR("...")); | ||
} | ||
|
||
cmd.apply_text_alignment(x, y, w, h, options); | ||
#ifdef TOUCH_UI_USE_UTF8 | ||
if (has_utf8_chars(str)) { | ||
draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options); | ||
} else | ||
#endif | ||
{ | ||
cmd.CLCD::CommandFifo::text(x, y, font, options); | ||
cmd.CLCD::CommandFifo::str(str); | ||
} | ||
} | ||
|
||
/** | ||
* These functions draws text inside a bounding box, truncating the text and | ||
* adding ellipsis if the text does not fit. | ||
*/ | ||
void draw_text_with_ellipsis(CommandProcessor& cmd, int x, int y, int w, int h, const char *str, uint16_t options, uint8_t font) { | ||
char tmp[strlen(str) + 3]; | ||
strcpy(tmp, str); | ||
_draw_text_with_ellipsis(cmd, x, y, w, h, tmp, options, font); | ||
} | ||
|
||
void draw_text_with_ellipsis(CommandProcessor& cmd, int x, int y, int w, int h, progmem_str pstr, uint16_t options, uint8_t font) { | ||
char tmp[strlen_P((const char*)pstr) + 3]; | ||
strcpy_P(tmp, (const char*)pstr); | ||
_draw_text_with_ellipsis(cmd, x, y, w, h, tmp, options, font); | ||
} | ||
} // namespace FTDI | ||
|
||
#endif // FTDI_EXTENDED |
31 changes: 31 additions & 0 deletions
31
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/******************* | ||
* text_ellipsis.h * | ||
*******************/ | ||
|
||
/**************************************************************************** | ||
* Written By Marcio Teixeira 2020 - SynDaver Labs, Inc. * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* To view a copy of the GNU General Public License, go to the following * | ||
* location: <https://www.gnu.org/licenses/>. * | ||
****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
/** | ||
* This function draws text inside a bounding box, truncating the text and | ||
* showing ellipsis if it does not fit. | ||
*/ | ||
namespace FTDI { | ||
void draw_text_with_ellipsis(class CommandProcessor& cmd, int x, int y, int w, int h, progmem_str str, uint16_t options = 0, uint8_t font = 31); | ||
void draw_text_with_ellipsis(class CommandProcessor& cmd, int x, int y, int w, int h, const char *str, uint16_t options = 0, uint8_t font = 31); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters