♻️ Apply F() to more LCD code (#24228)
This commit is contained in:
@@ -380,13 +380,10 @@ void MarlinUI::clear_lcd() {
|
||||
void MarlinUI::_set_contrast() { lcd.setContrast(contrast); }
|
||||
#endif
|
||||
|
||||
static void center_text_P(PGM_P pstart, uint8_t y) {
|
||||
uint8_t len = utf8_strlen_P(pstart);
|
||||
if (len < LCD_WIDTH)
|
||||
lcd.setCursor((LCD_WIDTH - len) / 2, y);
|
||||
else
|
||||
lcd.setCursor(0, y);
|
||||
lcd_put_u8str_P(pstart);
|
||||
static void center_text(FSTR_P const fstart, const uint8_t y) {
|
||||
const uint8_t len = utf8_strlen(fstart);
|
||||
lcd.setCursor(len < LCD_WIDTH ? (LCD_WIDTH - len) / 2 : 0, y);
|
||||
lcd_put_u8str(fstart);
|
||||
}
|
||||
|
||||
#if ENABLED(SHOW_BOOTSCREEN)
|
||||
@@ -402,8 +399,8 @@ static void center_text_P(PGM_P pstart, uint8_t y) {
|
||||
lcd.setCursor(indent, 0); lcd.write(TLC); lcd_put_u8str(F("------")); lcd.write(TRC);
|
||||
lcd.setCursor(indent, 1); lcd.write(LR); lcd_put_u8str(F("Marlin")); lcd.write(LR);
|
||||
lcd.setCursor(indent, 2); lcd.write(BLC); lcd_put_u8str(F("------")); lcd.write(BRC);
|
||||
center_text_P(PSTR(SHORT_BUILD_VERSION), 3);
|
||||
center_text_P(PSTR(MARLIN_WEBSITE_URL), 4);
|
||||
center_text(F(SHORT_BUILD_VERSION), 3);
|
||||
center_text(F(MARLIN_WEBSITE_URL), 4);
|
||||
picBits = ICON_LOGO;
|
||||
lcd.print_screen();
|
||||
}
|
||||
@@ -420,8 +417,8 @@ void MarlinUI::draw_kill_screen() {
|
||||
lcd.setCursor(0, 3); lcd.write(COLOR_ERROR);
|
||||
lcd.setCursor((LCD_WIDTH - utf8_strlen(status_message)) / 2 + 1, 3);
|
||||
lcd_put_u8str(status_message);
|
||||
center_text_P(GET_TEXT(MSG_HALTED), 5);
|
||||
center_text_P(GET_TEXT(MSG_PLEASE_RESET), 6);
|
||||
center_text(GET_TEXT_F(MSG_HALTED), 5);
|
||||
center_text(GET_TEXT_F(MSG_PLEASE_RESET), 6);
|
||||
lcd.print_screen();
|
||||
}
|
||||
|
||||
@@ -940,38 +937,38 @@ 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, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) {
|
||||
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) {
|
||||
if (!PanelDetected) return;
|
||||
uint8_t n = LCD_WIDTH;
|
||||
lcd.setCursor(0, row);
|
||||
if ((style & SS_CENTER) && !valstr) {
|
||||
int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
|
||||
int8_t pad = (LCD_WIDTH - utf8_strlen(fstr)) / 2;
|
||||
while (--pad >= 0) { lcd.write(' '); n--; }
|
||||
}
|
||||
n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, n);
|
||||
n = lcd_put_u8str_ind(fstr, itemIndex, itemString, n);
|
||||
if (valstr) n -= lcd_put_u8str_max(valstr, n);
|
||||
for (; n; --n) lcd.write(' ');
|
||||
lcd.print_line();
|
||||
}
|
||||
|
||||
// Draw a generic menu item with pre_char (if selected) and post_char
|
||||
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
|
||||
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char pre_char, const char post_char) {
|
||||
if (!PanelDetected) return;
|
||||
lcd.setCursor(0, row);
|
||||
lcd.write(sel ? pre_char : ' ');
|
||||
uint8_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2);
|
||||
uint8_t n = lcd_put_u8str_ind(fstr, itemIndex, itemString, LCD_WIDTH - 2);
|
||||
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, PGM_P const pstr, const char * const data, const bool pgm) {
|
||||
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char * const data, const bool pgm) {
|
||||
if (!PanelDetected) return;
|
||||
const uint8_t vlen = data ? (pgm ? utf8_strlen_P(data) : utf8_strlen(data)) : 0;
|
||||
lcd.setCursor(0, row);
|
||||
lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
|
||||
uint8_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2 - vlen);
|
||||
uint8_t n = lcd_put_u8str_ind(fstr, itemIndex, itemString, LCD_WIDTH - 2 - vlen);
|
||||
if (vlen) {
|
||||
lcd.write(':');
|
||||
for (; n; --n) lcd.write(' ');
|
||||
@@ -982,13 +979,13 @@ void MarlinUI::draw_status_screen() {
|
||||
|
||||
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
|
||||
// This line moves to the last line of the screen for UBL plot screen on the panel side
|
||||
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const value/*=nullptr*/) {
|
||||
void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const value/*=nullptr*/) {
|
||||
if (!PanelDetected) return;
|
||||
ui.encoder_direction_normal();
|
||||
const uint8_t y = TERN0(AUTO_BED_LEVELING_UBL, ui.external_control) ? LCD_HEIGHT - 1 : MIDDLE_Y;
|
||||
lcd.setCursor(0, y);
|
||||
lcd.write(COLOR_EDIT);
|
||||
lcd_put_u8str_P(pstr);
|
||||
lcd_put_u8str(fstr);
|
||||
if (value) {
|
||||
lcd.write(':');
|
||||
lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), y); // Right-justified, padded by spaces
|
||||
@@ -1000,24 +997,24 @@ void MarlinUI::draw_status_screen() {
|
||||
}
|
||||
|
||||
// The Select Screen presents a prompt and two "buttons"
|
||||
void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff) {
|
||||
void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const pref, const char * const string, FSTR_P const suff) {
|
||||
if (!PanelDetected) return;
|
||||
ui.draw_select_screen_prompt(pref, string, suff);
|
||||
lcd.write(COLOR_EDIT);
|
||||
if (no) {
|
||||
lcd.setCursor(0, MIDDLE_Y);
|
||||
lcd.write(yesno ? ' ' : '['); lcd_put_u8str_P(no); lcd.write(yesno ? ' ' : ']');
|
||||
lcd.write(yesno ? ' ' : '['); lcd_put_u8str(no); lcd.write(yesno ? ' ' : ']');
|
||||
}
|
||||
if (yes) {
|
||||
lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, MIDDLE_Y);
|
||||
lcd.write(yesno ? '[' : ' '); lcd_put_u8str_P(yes); lcd.write(yesno ? ']' : ' ');
|
||||
lcd.setCursor(LCD_WIDTH - utf8_strlen(yes) - 3, MIDDLE_Y);
|
||||
lcd.write(yesno ? '[' : ' '); lcd_put_u8str(yes); lcd.write(yesno ? ']' : ' ');
|
||||
}
|
||||
lcd.print_line();
|
||||
}
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
|
||||
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
|
||||
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
|
||||
if (!PanelDetected) return;
|
||||
lcd.setCursor(0, row);
|
||||
lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
|
||||
@@ -1081,7 +1078,7 @@ void MarlinUI::draw_status_screen() {
|
||||
else
|
||||
lcd_put_u8str(F(" -----"));
|
||||
|
||||
center_text_P(GET_TEXT(MSG_UBL_FINE_TUNE_MESH), 8);
|
||||
center_text(GET_TEXT_F(MSG_UBL_FINE_TUNE_MESH), 8);
|
||||
|
||||
lcd.print_screen();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user