🧑‍💻 Adjust LCD string draw (#26154)

This commit is contained in:
lukasradek 2023-08-24 19:41:30 +02:00 committed by GitHub
parent adfc787a45
commit 20fec98f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 30 deletions

View file

@ -1178,11 +1178,7 @@ void MarlinUI::draw_status_screen() {
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) {
const int8_t expl = n;
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
pad -= (expl - n - plen); // Reduce the padding
}
if (plen) n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n - vlen);
if (vlen && n > 0) {
// SS_FULL: Pad with enough space to justify the value
@ -1203,7 +1199,8 @@ 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 ftpl, const char pre_char, const char post_char) {
lcd_put_lchar(0, row, sel ? pre_char : ' ');
uint8_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2);
uint8_t n = LCD_WIDTH - 2;
n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n);
for (; n; --n) lcd_put_u8str(F(" "));
lcd_put_lchar(post_char);
}
@ -1224,7 +1221,8 @@ void MarlinUI::draw_status_screen() {
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
void MenuEditItemBase::draw_edit_screen(FSTR_P const ftpl, const char * const value/*=nullptr*/) {
ui.encoder_direction_normal();
uint8_t n = lcd_put_u8str(0, 1, ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 1);
uint8_t n = LCD_WIDTH - 1;
n -= lcd_put_u8str(0, 1, ftpl, itemIndex, itemStringC, itemStringF, n);
if (value) {
lcd_put_u8str(F(":")); n--;
const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space
@ -1251,8 +1249,8 @@ void MarlinUI::draw_status_screen() {
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
lcd_put_lchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
constexpr uint8_t maxlen = LCD_WIDTH - 2;
uint8_t n = maxlen - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
uint8_t n = LCD_WIDTH - 2;
n -= lcd_put_u8str_max(ui.scrolled_filename(theCard, n, row, sel), n);
for (; n; --n) lcd_put_u8str(F(" "));
lcd_put_lchar(isDir ? LCD_STR_FOLDER[0] : ' ');
}

View file

@ -983,11 +983,7 @@ void MarlinUI::draw_status_screen() {
if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd.write(' '); n--; }
// Draw as much of the label as fits
if (plen) {
const int8_t expl = n;
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
pad -= (expl - n - plen); // Reduce the padding
}
if (plen) n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n - vlen);
if (vlen && n > 0) {
// SS_FULL: Pad with enough space to justify the value
@ -1012,7 +1008,8 @@ void MarlinUI::draw_status_screen() {
if (!PanelDetected) return;
lcd_moveto(0, row);
lcd.write(sel ? pre_char : ' ');
uint8_t n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2);
uint8_t n = LCD_WIDTH - 2;
n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
for (; n; --n) lcd.write(' ');
lcd.write(post_char);
lcd.print_line();
@ -1024,7 +1021,8 @@ void MarlinUI::draw_status_screen() {
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_put_u8str(fstr, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vlen);
uint8_t n = LCD_WIDTH - 2 - vlen;
n -= lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
if (vlen) {
lcd.write(':');
for (; n; --n) lcd.write(' ');
@ -1074,8 +1072,8 @@ void MarlinUI::draw_status_screen() {
if (!PanelDetected) return;
lcd_moveto(0, row);
lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
constexpr uint8_t maxlen = LCD_WIDTH - 2;
uint8_t n = maxlen - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
uint8_t n = LCD_WIDTH - 2;
n -= lcd_put_u8str_max(ui.scrolled_filename(theCard, n, row, sel), n);
for (; n; --n) lcd.write(' ');
lcd.write(isDir ? LCD_STR_FOLDER[0] : ' ');
lcd.print_line();

View file

@ -424,11 +424,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
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) {
const pixel_len_t expw = n;
n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
pad -= (expw - n - pwide) / (MENU_FONT_WIDTH); // Reduce the padding
}
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
@ -449,8 +445,9 @@ 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)) {
pixel_len_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 1) * (MENU_FONT_WIDTH);
while (n > MENU_FONT_WIDTH) n -= lcd_put_u8str(F(" "));
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(" "));
}
@ -463,10 +460,11 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), inStr));
const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
pixel_len_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vallen * prop) * (MENU_FONT_WIDTH);
uint8_t n = LCD_WIDTH - 2 - vallen * prop;
n -= lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n);
if (vallen) {
lcd_put_u8str(F(":"));
while (n > MENU_FONT_WIDTH) n -= 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);
}
@ -552,7 +550,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
if (isDir) lcd_put_lchar(LCD_STR_FOLDER[0]);
const pixel_len_t pixw = maxlen * (MENU_FONT_WIDTH);
pixel_len_t n = pixw - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), pixw);
while (n > MENU_FONT_WIDTH) n -= lcd_put_u8str(F(" "));
for (; n > MENU_FONT_WIDTH; n -= MENU_FONT_WIDTH) lcd_put_u8str(F(" "));
}
}

View file

@ -42,7 +42,7 @@
* * 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 given maxlen minus the number of characters emitted, i.e., the number of unused columns
* 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*/) {
const uint8_t prop = USE_WIDE_GLYPH ? 2 : 1;
@ -88,7 +88,7 @@ lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr/
n -= wc > 255 ? prop : 1;
}
}
return n;
return maxlen - n;
}
// Calculate UTF8 width with a simple check