Fix UTF char cutoff at DOGM edge (#18294)

This commit is contained in:
cccc 2020-06-16 08:07:46 +08:00 committed by GitHub
parent a4b46eaf8f
commit fe46704848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -377,12 +377,14 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
// Draw a menu item with an editable value
void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
if (mark_as_selected(row, sel)) {
const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data));
const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data)),
pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), data) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), (char*)data));
u8g_uint_t n = lcd_put_u8str_ind_P(pstr, itemIndex, LCD_WIDTH - 2 - vallen) * (MENU_FONT_WIDTH);
if (vallen) {
lcd_put_wchar(':');
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
lcd_moveto(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH) * vallen, row_y2);
lcd_moveto(LCD_PIXEL_WIDTH - _MAX((MENU_FONT_WIDTH) * vallen, pixelwidth + 2), row_y2);
if (pgm) lcd_put_u8str_P(data); else lcd_put_u8str((char*)data);
}
}