♻️ Apply F() to more LCD code (#24228)
This commit is contained in:
committed by
Scott Lahteine
parent
9a74bcd4cf
commit
28f8646aa6
@ -74,7 +74,7 @@ inline void DWIN_Text(size_t &i, const char * const string, uint16_t rlimit=0xFF
|
||||
|
||||
inline void DWIN_Text(size_t &i, FSTR_P string, uint16_t rlimit=0xFFFF) {
|
||||
if (!string) return;
|
||||
const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, _MIN(rlimit, strlen_P((PGM_P)string))); // cast to PGM_P (const char*) measure with strlen_P.
|
||||
const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, _MIN(rlimit, strlen_P(FTOP(string))));
|
||||
if (len == 0) return;
|
||||
memcpy_P(&DWIN_SendBuf[i+1], string, len);
|
||||
i += len;
|
||||
|
@ -2944,7 +2944,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
break;
|
||||
case LEVELING_VIEW:
|
||||
if (draw)
|
||||
Draw_Menu_Item(row, ICON_Mesh, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
|
||||
Draw_Menu_Item(row, ICON_Mesh, GET_TEXT_F(MSG_MESH_VIEW), nullptr, true);
|
||||
else {
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
if (bedlevel.storage_slot < 0) {
|
||||
@ -3017,7 +3017,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
|
||||
break;
|
||||
case LEVELING_VIEW_MESH:
|
||||
if (draw)
|
||||
Draw_Menu_Item(row, ICON_PrintSize, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
|
||||
Draw_Menu_Item(row, ICON_PrintSize, GET_TEXT_F(MSG_MESH_VIEW), nullptr, true);
|
||||
else
|
||||
Draw_Menu(MeshViewer);
|
||||
break;
|
||||
|
@ -43,13 +43,13 @@ uint8_t read_byte(uint8_t *byte) { return *byte; }
|
||||
/**
|
||||
* Add a string, applying substitutions for the following characters:
|
||||
*
|
||||
* $ displays the clipped C-string given by the itemString argument
|
||||
* $ displays the clipped C-string given by the inStr argument
|
||||
* = displays '0'....'10' for indexes 0 - 10
|
||||
* ~ displays '1'....'11' for indexes 0 - 10
|
||||
* * 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
|
||||
*/
|
||||
void DWIN_String::add(uint8_t *string, const int8_t index, uint8_t *itemString/*=nullptr*/) {
|
||||
void DWIN_String::add(uint8_t *string, const int8_t index, uint8_t *inStr/*=nullptr*/) {
|
||||
wchar_t wchar;
|
||||
|
||||
while (*string) {
|
||||
@ -67,8 +67,8 @@ void DWIN_String::add(uint8_t *string, const int8_t index, uint8_t *itemString/*
|
||||
else
|
||||
add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
|
||||
}
|
||||
else if (ch == '$' && itemString)
|
||||
add(itemString);
|
||||
else if (ch == '$' && inStr)
|
||||
add(inStr);
|
||||
else if (ch == '@')
|
||||
add_character(axis_codes[index]);
|
||||
else
|
||||
|
@ -61,15 +61,20 @@ class DWIN_String {
|
||||
//static void add(uint8_t character) { add_character(character); eol(); }
|
||||
static void add(wchar_t character);
|
||||
static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
|
||||
static void add(uint8_t *string, const int8_t index, uint8_t *itemString=nullptr);
|
||||
static void add(uint8_t *string, const int8_t index, uint8_t *inStr=nullptr);
|
||||
static void set(uint8_t *string) { set(); add(string); }
|
||||
static void set(wchar_t character) { set(); add(character); }
|
||||
static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); }
|
||||
static void set(FSTR_P fstring) { set((uint8_t *)fstring); }
|
||||
static void set(uint8_t *string, int8_t index, const char *inStr=nullptr) { set(); add(string, index, (uint8_t *)inStr); }
|
||||
static void set(const char *string) { set((uint8_t *)string); }
|
||||
static void set(const char *string, int8_t index, const char *itemString=nullptr) { set((uint8_t *)string, index, itemString); }
|
||||
static void set(const char *string, int8_t index, const char *inStr=nullptr) { set((uint8_t *)string, index, inStr); }
|
||||
static void add(const char *string) { add((uint8_t *)string); }
|
||||
|
||||
static void add(FSTR_P const string, uint8_t max_len=MAX_STRING_LENGTH) { add((uint8_t *)FTOP(string), max_len); }
|
||||
static void add(FSTR_P const string, int8_t index, uint8_t *inStr=nullptr) { add((uint8_t *)FTOP(string), index, inStr); }
|
||||
static void set(FSTR_P const string) { set((uint8_t *)FTOP(string)); }
|
||||
static void set(FSTR_P const string, int8_t index, const char *inStr=nullptr) { set((uint8_t *)FTOP(string), index, inStr); }
|
||||
static void add(FSTR_P const string) { add((uint8_t *)FTOP(string)); }
|
||||
|
||||
static void trim(const uint8_t character=0x20);
|
||||
static void rtrim(const uint8_t character=0x20);
|
||||
static void ltrim(const uint8_t character=0x20);
|
||||
|
@ -311,7 +311,7 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
|
||||
// Draw a static line of text in the same idiom as a menu item
|
||||
|
||||
void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
|
||||
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
|
||||
// Call mark_as_selected to draw a bigger selection box
|
||||
// and draw the text without a background
|
||||
if (mark_as_selected(row, (bool)(style & SS_INVERT), true)) {
|
||||
@ -320,14 +320,14 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
dwin_font.fg = Color_White;
|
||||
|
||||
dwin_string.set();
|
||||
const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0,
|
||||
const int8_t plen = fstr ? utf8_strlen(fstr) : 0,
|
||||
vlen = vstr ? utf8_strlen(vstr) : 0;
|
||||
if (style & SS_CENTER) {
|
||||
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
|
||||
while (--pad) dwin_string.add(' ');
|
||||
}
|
||||
|
||||
if (plen) dwin_string.add((uint8_t*)pstr, itemIndex, (uint8_t*)itemString);
|
||||
if (plen) dwin_string.add((uint8_t*)FTOP(fstr), itemIndex, (uint8_t*)FTOP(itemString));
|
||||
if (vlen) dwin_string.add((uint8_t*)vstr);
|
||||
if (style & SS_CENTER) {
|
||||
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
|
||||
@ -340,13 +340,13 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
}
|
||||
|
||||
// Draw a generic menu item
|
||||
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char, const char post_char) {
|
||||
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char, const char post_char) {
|
||||
if (mark_as_selected(row, sel)) {
|
||||
ui.set_font(DWIN_FONT_MENU);
|
||||
dwin_font.solid = false;
|
||||
dwin_font.fg = Color_White;
|
||||
|
||||
dwin_string.set(pstr, itemIndex, itemString);
|
||||
dwin_string.set(fstr, itemIndex, FTOP(itemString));
|
||||
|
||||
pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length();
|
||||
while (--n > 1) dwin_string.add(' ');
|
||||
@ -361,15 +361,15 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
//
|
||||
// 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) {
|
||||
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char * const inStr, const bool pgm) {
|
||||
if (mark_as_selected(row, sel)) {
|
||||
ui.set_font(DWIN_FONT_MENU);
|
||||
dwin_font.solid = false;
|
||||
dwin_font.fg = Color_White;
|
||||
|
||||
const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen(S(data)));
|
||||
const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(S(inStr)));
|
||||
|
||||
dwin_string.set(pstr, itemIndex, itemString);
|
||||
dwin_string.set(fstr, itemIndex, FTOP(itemString));
|
||||
if (vallen) dwin_string.add(':');
|
||||
|
||||
lcd_moveto(1, row);
|
||||
@ -377,7 +377,7 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
|
||||
if (vallen) {
|
||||
dwin_font.fg = Color_Yellow;
|
||||
dwin_string.set(data);
|
||||
dwin_string.set(inStr);
|
||||
lcd_moveto(LCD_WIDTH - vallen - 1, row);
|
||||
lcd_put_dwin_string();
|
||||
}
|
||||
@ -387,13 +387,13 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
//
|
||||
// Draw an edit screen with label and current value
|
||||
//
|
||||
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*/) {
|
||||
ui.encoder_direction_normal();
|
||||
|
||||
const dwin_coord_t labellen = utf8_strlen_P(pstr), vallen = utf8_strlen(value);
|
||||
const dwin_coord_t labellen = utf8_strlen(fstr), vallen = utf8_strlen(value);
|
||||
|
||||
dwin_string.set();
|
||||
dwin_string.add((uint8_t*)pstr, itemIndex);
|
||||
dwin_string.add((uint8_t*)FTOP(fstr), itemIndex);
|
||||
if (vallen) dwin_string.add(':'); // If a value is included, add a colon
|
||||
|
||||
// Assume the label is alpha-numeric (with a descender)
|
||||
@ -430,19 +430,19 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
}
|
||||
}
|
||||
|
||||
inline void draw_boxed_string(const bool yesopt, PGM_P const pstr, const bool inv) {
|
||||
const uint8_t len = utf8_strlen_P(pstr),
|
||||
inline void draw_boxed_string(const bool yesopt, FSTR_P const fstr, const bool inv) {
|
||||
const uint8_t len = utf8_strlen(fstr),
|
||||
mar = TERN(DWIN_MARLINUI_PORTRAIT, 1, 4),
|
||||
col = yesopt ? LCD_WIDTH - mar - len : mar,
|
||||
row = (LCD_HEIGHT >= 8 ? LCD_HEIGHT / 2 + 3 : LCD_HEIGHT - 1);
|
||||
lcd_moveto(col, row);
|
||||
DWIN_Draw_Box(1, inv ? Select_Color : Color_Bg_Black, cursor.x - dwin_font.width, cursor.y + 1, dwin_font.width * (len + 2), dwin_font.height + 2);
|
||||
lcd_put_u8str_P(col, row, pstr);
|
||||
lcd_put_u8str(col, row, fstr);
|
||||
}
|
||||
|
||||
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/*=nullptr*/, PGM_P const suff/*=nullptr*/
|
||||
FSTR_P const yes, FSTR_P const no, const bool yesno,
|
||||
FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/
|
||||
) {
|
||||
ui.set_font(DWIN_FONT_MENU);
|
||||
dwin_font.solid = false;
|
||||
@ -454,7 +454,7 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
|
||||
#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 (mark_as_selected(row, sel)) {
|
||||
dwin_string.set();
|
||||
|
||||
|
Reference in New Issue
Block a user