🧑💻 Extend LCD string substitution (#24278)
This commit is contained in:
1 parent
fcef8d946c
commit
1e127a93c4
83 files changed
+1062
-1281
No files matched your search
@@ -28,7 +28,7 @@ void lcd_put_int(const int i) { u8g.print(i); }
|
||||
|
||||
// return < 0 on error
|
||||
// return the advanced pixels
|
||||
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
|
||||
int lcd_put_wchar_max(const wchar_t c, const pixel_len_t max_length) {
|
||||
if (c < 256) {
|
||||
u8g.print((char)c);
|
||||
return u8g_GetFontBBXWidth(u8g.getU8g());
|
||||
@@ -39,14 +39,14 @@ int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
|
||||
int lcd_put_u8str_max(const char * utf8_str, const pixel_len_t max_length) {
|
||||
u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(),
|
||||
ret = uxg_DrawUtf8Str(u8g.getU8g(), x, y, utf8_str, max_length);
|
||||
u8g.setPrintPos(x + ret, y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lcd_put_u8str_max_P(PGM_P utf8_pstr, pixel_len_t max_length) {
|
||||
int lcd_put_u8str_max_P(PGM_P utf8_pstr, const pixel_len_t max_length) {
|
||||
u8g_uint_t x = u8g.getPrintCol(), y = u8g.getPrintRow(),
|
||||
ret = uxg_DrawUtf8StrP(u8g.getU8g(), x, y, utf8_pstr, max_length);
|
||||
u8g.setPrintPos(x + ret, y);
|
||||
|
||||
@@ -330,13 +330,13 @@ void MarlinUI::update_language_font() {
|
||||
// The kill screen is displayed for unrecoverable conditions
|
||||
void MarlinUI::draw_kill_screen() {
|
||||
TERN_(LIGHTWEIGHT_UI, ST7920_Lite_Status_Screen::clear_text_buffer());
|
||||
const u8g_uint_t h4 = u8g.getHeight() / 4;
|
||||
const u8g_uint_t x = 0, h4 = u8g.getHeight() / 4;
|
||||
u8g.firstPage();
|
||||
do {
|
||||
set_font(FONT_MENU);
|
||||
lcd_put_u8str(0, h4 * 1, status_message);
|
||||
lcd_put_u8str(0, h4 * 2, GET_TEXT_F(MSG_HALTED));
|
||||
lcd_put_u8str(0, h4 * 3, GET_TEXT_F(MSG_PLEASE_RESET));
|
||||
lcd_put_u8str(x, h4 * 1, status_message);
|
||||
lcd_put_u8str(x, h4 * 2, GET_TEXT_F(MSG_HALTED));
|
||||
lcd_put_u8str(x, h4 * 3, GET_TEXT_F(MSG_PLEASE_RESET));
|
||||
} while (u8g.nextPage());
|
||||
}
|
||||
|
||||
@@ -412,28 +412,28 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
|
||||
}
|
||||
|
||||
// Draw a static line of text in the same idiom as a menu item
|
||||
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
|
||||
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
|
||||
|
||||
if (mark_as_selected(row, style & SS_INVERT)) {
|
||||
pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed
|
||||
|
||||
const int plen = fstr ? calculateWidth(FTOP(fstr)) : 0,
|
||||
const int plen = ftpl ? calculateWidth(ftpl) : 0,
|
||||
vlen = vstr ? utf8_strlen(vstr) : 0;
|
||||
if (style & SS_CENTER) {
|
||||
int pad = (LCD_PIXEL_WIDTH - plen - vlen * MENU_FONT_WIDTH) / MENU_FONT_WIDTH / 2;
|
||||
while (--pad >= 0) n -= lcd_put_wchar(' ');
|
||||
}
|
||||
|
||||
if (plen) n = lcd_put_u8str_ind(fstr, itemIndex, itemString, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
|
||||
if (plen) n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
|
||||
if (vlen) n -= lcd_put_u8str_max(vstr, n);
|
||||
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a generic menu item
|
||||
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char, const char post_char) {
|
||||
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_ind(fstr, itemIndex, itemString, LCD_WIDTH - 1) * (MENU_FONT_WIDTH);
|
||||
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_wchar(' ');
|
||||
lcd_put_wchar(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH), row_y2, post_char);
|
||||
lcd_put_wchar(' ');
|
||||
@@ -441,27 +441,27 @@ 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, FSTR_P const fstr, const char * const inStr, const bool pgm) {
|
||||
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) {
|
||||
if (mark_as_selected(row, sel)) {
|
||||
const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen((char*)inStr)),
|
||||
pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), (char*)inStr));
|
||||
const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)),
|
||||
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_ind(fstr, itemIndex, itemString, LCD_WIDTH - 2 - vallen * prop) * (MENU_FONT_WIDTH);
|
||||
pixel_len_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vallen * prop) * (MENU_FONT_WIDTH);
|
||||
if (vallen) {
|
||||
lcd_put_wchar(':');
|
||||
while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
|
||||
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((char*)inStr);
|
||||
if (pgm) lcd_put_u8str_P(inStr); else lcd_put_u8str(inStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const value/*=nullptr*/) {
|
||||
void MenuEditItemBase::draw_edit_screen(FSTR_P const ftpl, const char * const value/*=nullptr*/) {
|
||||
ui.encoder_direction_normal();
|
||||
|
||||
const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
|
||||
const u8g_uint_t labellen = utf8_strlen(fstr), vallen = utf8_strlen(value);
|
||||
const u8g_uint_t labellen = utf8_strlen(ftpl), vallen = utf8_strlen(value);
|
||||
bool extra_row = labellen * prop > LCD_WIDTH - 2 - vallen * prop;
|
||||
|
||||
#if ENABLED(USE_BIG_EDIT_FONT)
|
||||
@@ -490,7 +490,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
|
||||
|
||||
// Assume the label is alpha-numeric (with a descender)
|
||||
bool onpage = PAGE_CONTAINS(baseline - (EDIT_FONT_ASCENT - 1), baseline + EDIT_FONT_DESCENT);
|
||||
if (onpage) lcd_put_u8str_ind(0, baseline, fstr, itemIndex, itemString);
|
||||
if (onpage) lcd_put_u8str(0, baseline, ftpl, itemIndex, itemStringC, itemStringF);
|
||||
|
||||
// If a value is included, print a colon, then print the value right-justified
|
||||
if (value) {
|
||||
@@ -522,8 +522,8 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
|
||||
if (inv) u8g.setColorIndex(1);
|
||||
}
|
||||
|
||||
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/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
|
||||
ui.draw_select_screen_prompt(pref, string, suff);
|
||||
void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const fpre, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
|
||||
ui.draw_select_screen_prompt(fpre, string, suff);
|
||||
if (no) draw_boxed_string(1, LCD_HEIGHT - 1, no, !yesno);
|
||||
if (yes) draw_boxed_string(LCD_WIDTH - (utf8_strlen(yes) * (USE_WIDE_GLYPH ? 2 : 1) + 1), LCD_HEIGHT - 1, yes, yesno);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ static void fontgroup_drawwchar(font_group_t *group, const font_t *fnt_default,
|
||||
* Get the screen pixel width of a ROM UTF-8 string
|
||||
*/
|
||||
static void fontgroup_drawstring(font_group_t *group, const font_t *fnt_default, const char *utf8_msg, read_byte_cb_t cb_read_byte, void * userdata, fontgroup_cb_draw_t cb_draw_ram) {
|
||||
uint8_t *p = (uint8_t*)utf8_msg;
|
||||
const uint8_t *p = (uint8_t*)utf8_msg;
|
||||
for (;;) {
|
||||
wchar_t val = 0;
|
||||
p = get_utf8_value_cb(p, cb_read_byte, &val);
|
||||
|
||||
@@ -26,10 +26,10 @@ typedef struct _uxg_fontinfo_t {
|
||||
|
||||
int uxg_SetUtf8Fonts(const uxg_fontinfo_t * fntinfo, int number); // fntinfo is type of PROGMEM
|
||||
|
||||
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, wchar_t ch, pixel_len_t max_length);
|
||||
unsigned int uxg_DrawWchar(u8g_t *pu8g, unsigned int x, unsigned int y, wchar_t ch, const pixel_len_t max_length);
|
||||
|
||||
unsigned int uxg_DrawUtf8Str(u8g_t *pu8g, unsigned int x, unsigned int y, const char *utf8_msg, pixel_len_t max_length);
|
||||
unsigned int uxg_DrawUtf8StrP(u8g_t *pu8g, unsigned int x, unsigned int y, PGM_P utf8_msg, pixel_len_t max_length);
|
||||
unsigned int uxg_DrawUtf8Str(u8g_t *pu8g, unsigned int x, unsigned int y, const char *utf8_msg, const pixel_len_t max_length);
|
||||
unsigned int uxg_DrawUtf8StrP(u8g_t *pu8g, unsigned int x, unsigned int y, PGM_P utf8_msg, const pixel_len_t max_length);
|
||||
|
||||
int uxg_GetUtf8StrPixelWidth(u8g_t *pu8g, const char *utf8_msg);
|
||||
int uxg_GetUtf8StrPixelWidthP(u8g_t *pu8g, PGM_P utf8_msg);
|
||||
|
||||
Reference in new issue
Block a user