1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-29 23:07:42 +00:00

🧑‍💻 Misc. LCD / string updates

This commit is contained in:
Scott Lahteine 2023-10-25 19:41:32 -05:00
parent b25f523aca
commit 2a88e76002
13 changed files with 71 additions and 58 deletions

View File

@ -57,7 +57,8 @@
* 41 - Counter-Clockwise M4
* 50 - Clockwise M5
* 51 - Counter-Clockwise M5
**/
*
*/
void GcodeSuite::G35() {
DEBUG_SECTION(log_G35, "G35", DEBUGGING(LEVELING));
@ -82,9 +83,7 @@ void GcodeSuite::G35() {
set_bed_leveling_enabled(false);
#endif
#if ENABLED(CNC_WORKSPACE_PLANES)
workspace_plane = PLANE_XY;
#endif
TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY);
probe.use_probing_tool();

View File

@ -1248,8 +1248,8 @@ void MarlinUI::draw_status_screen() {
}
// The Select Screen presents a prompt and two "buttons"
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 fsuf/*=nullptr*/) {
ui.draw_select_screen_prompt(fpre, string, fsuf);
if (no) {
SETCURSOR(0, LCD_HEIGHT - 1);
lcd_put_lchar(yesno ? ' ' : '['); lcd_put_u8str(no); lcd_put_lchar(yesno ? ' ' : ']');

View File

@ -1064,9 +1064,9 @@ void MarlinUI::draw_status_screen() {
}
// The Select Screen presents a prompt and two "buttons"
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) {
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, FSTR_P const fsuf) {
if (!PanelDetected) return;
ui.draw_select_screen_prompt(pref, string, suff);
ui.draw_select_screen_prompt(fpre, string, fsuf);
lcd.write(COLOR_EDIT);
if (no) {
lcd_moveto(0, MIDDLE_Y);

View File

@ -38,6 +38,9 @@ int lcd_put_lchar_max(const lchar_t &c, const pixel_len_t max_length) {
return ret;
}
/**
* @return output width in pixels
*/
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);
@ -45,6 +48,9 @@ int lcd_put_u8str_max(const char * utf8_str, const pixel_len_t max_length) {
return ret;
}
/**
* @return output width in pixels
*/
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);

View File

@ -551,8 +551,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 fpre, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
ui.draw_select_screen_prompt(fpre, 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 fsuf/*=nullptr*/) {
ui.draw_select_screen_prompt(fpre, string, fsuf);
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);
}

View File

@ -412,12 +412,12 @@ void MarlinUI::draw_status_message(const bool blink) {
//
// Draw an edit screen with label and current value
//
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 dwin_coord_t labellen = utf8_strlen(fstr), vallen = utf8_strlen(value);
const dwin_coord_t labellen = utf8_strlen(ftpl), vallen = utf8_strlen(value);
dwin_string.set(FTOP(fstr), itemIndex);
dwin_string.set(FTOP(ftpl), itemIndex);
if (vallen) dwin_string.add(':'); // If a value is included, add a colon
// Assume the label is alpha-numeric (with a descender)
@ -453,7 +453,7 @@ void MarlinUI::draw_status_message(const bool blink) {
}
inline void draw_boxed_string(const bool yesopt, FSTR_P const fstr, const bool inv) {
const uint8_t len = utf8_strlen(fstr),
const uint8_t len = utf8_strlen_P(FTOP(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);
@ -464,12 +464,12 @@ void MarlinUI::draw_status_message(const bool blink) {
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*/
FSTR_P const fpre, const char * const string/*=nullptr*/, FSTR_P const fsuf/*=nullptr*/
) {
ui.set_font(DWIN_FONT_MENU);
dwin_font.solid = false;
dwin_font.fg = COLOR_WHITE;
ui.draw_select_screen_prompt(pref, string, suff);
ui.draw_select_screen_prompt(fpre, string, fsuf);
if (no) draw_boxed_string(false, no, !yesno);
if (yes) draw_boxed_string(true, yes, yesno);
}

View File

@ -444,8 +444,9 @@ void MarlinUI::init() {
p = get_utf8_value_cb(p, cb_read_byte, wc);
const bool eol = !wc; // zero ends the string
// End or a break between phrases?
if (eol || wc == ' ' || wc == '-' || wc == '+' || wc == '.') {
if (!c && wc == ' ') { if (wrd) wrd++; continue; } // collapse extra spaces
if (eol || wc == ' ' || wc == '-' || wc == '+' || wc == '.' || wc == '\n') {
const bool newline_after = wc == '\n';
if (!c && (wc == ' ' || newline_after)) { if (wrd) wrd++; continue; } // collapse extra spaces
// Past the right and the word is not too long?
if (col + c > LCD_WIDTH && col >= (LCD_WIDTH) / 4) _newline(); // should it wrap?
c += !eol; // +1 so the space will be printed
@ -456,6 +457,7 @@ void MarlinUI::init() {
lcd_put_lchar(wc); // character to the LCD
}
if (eol) break; // all done!
if (newline_after) _newline();
wrd = nullptr; // set up for next word
}
else c++; // count word characters
@ -472,20 +474,20 @@ void MarlinUI::init() {
}
}
void MarlinUI::draw_select_screen_prompt(FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
const uint8_t plen = utf8_strlen(pref), slen = suff ? utf8_strlen(suff) : 0;
void MarlinUI::draw_select_screen_prompt(FSTR_P const fpre, const char * const string/*=nullptr*/, FSTR_P const fsuf/*=nullptr*/) {
const uint8_t plen = utf8_strlen_P(FTOP(fpre)), slen = fsuf ? utf8_strlen_P(FTOP(fsuf)) : 0;
uint8_t col = 0, row = 0;
if (!string && plen + slen <= LCD_WIDTH) {
col = (LCD_WIDTH - plen - slen) / 2;
row = LCD_HEIGHT > 3 ? 1 : 0;
}
if (LCD_HEIGHT >= 8) row = LCD_HEIGHT / 2 - 2;
wrap_string_P(col, row, FTOP(pref), true);
wrap_string_P(col, row, FTOP(fpre), true);
if (string) {
if (col) { col = 0; row++; } // Move to the start of the next line
wrap_string(col, row, string);
}
if (suff) wrap_string_P(col, row, FTOP(suff));
if (fsuf) wrap_string_P(col, row, FTOP(fsuf));
}
#endif // !HAS_GRAPHICAL_TFT

View File

@ -729,7 +729,7 @@ public:
static float ubl_mesh_value();
#endif
static void draw_select_screen_prompt(FSTR_P const pref, const char * const string=nullptr, FSTR_P const suff=nullptr);
static void draw_select_screen_prompt(FSTR_P const fpre, const char * const string=nullptr, FSTR_P const fsuf=nullptr);
#else

View File

@ -352,13 +352,13 @@ bool MarlinUI::update_selection() {
void MenuItem_confirm::select_screen(
FSTR_P const yes, FSTR_P const no,
selectFunc_t yesFunc, selectFunc_t noFunc,
FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/
FSTR_P const fpre, const char * const string/*=nullptr*/, FSTR_P const fsuf/*=nullptr*/
) {
ui.defer_status_screen();
const bool ui_selection = !yes ? false : !no || ui.update_selection(),
got_click = ui.use_click();
if (got_click || ui.should_draw()) {
draw_select_screen(yes, no, ui_selection, pref, string, suff);
draw_select_screen(yes, no, ui_selection, fpre, string, fsuf);
if (got_click) {
selectFunc_t callFunc = ui_selection ? yesFunc : noFunc;
if (callFunc) callFunc(); else ui.goto_previous_screen();

View File

@ -102,31 +102,31 @@ class MenuItem_confirm : public MenuItemBase {
FSTR_P const yes, // Right option label
FSTR_P const no, // Left option label
const bool yesno, // Is "yes" selected?
FSTR_P const pref, // Prompt prefix
FSTR_P const fpre, // Prompt prefix
const char * const string, // Prompt runtime string
FSTR_P const suff // Prompt suffix
FSTR_P const fsuf // Prompt suffix
);
static void select_screen(
FSTR_P const yes, FSTR_P const no,
selectFunc_t yesFunc, selectFunc_t noFunc,
FSTR_P const pref, const char * const string=nullptr, FSTR_P const suff=nullptr
FSTR_P const fpre, const char * const string=nullptr, FSTR_P const fsuf=nullptr
);
static void select_screen(
FSTR_P const yes, FSTR_P const no,
selectFunc_t yesFunc, selectFunc_t noFunc,
FSTR_P const pref, FSTR_P const fstr, FSTR_P const suff=nullptr
FSTR_P const fpre, FSTR_P const fstr, FSTR_P const fsuf=nullptr
) {
#ifdef __AVR__
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
select_screen(yes, no, yesFunc, noFunc, pref, str, suff);
select_screen(yes, no, yesFunc, noFunc, fpre, str, fsuf);
#else
select_screen(yes, no, yesFunc, noFunc, pref, FTOP(fstr), suff);
select_screen(yes, no, yesFunc, noFunc, fpre, FTOP(fstr), fsuf);
#endif
}
// Shortcut for prompt with "NO"/ "YES" labels
FORCE_INLINE static void confirm_screen(selectFunc_t yesFunc, selectFunc_t noFunc, FSTR_P const pref, const char * const string=nullptr, FSTR_P const suff=nullptr) {
select_screen(GET_TEXT_F(MSG_YES), GET_TEXT_F(MSG_NO), yesFunc, noFunc, pref, string, suff);
FORCE_INLINE static void confirm_screen(selectFunc_t yesFunc, selectFunc_t noFunc, FSTR_P const fpre, const char * const string=nullptr, FSTR_P const fsuf=nullptr) {
select_screen(GET_TEXT_F(MSG_YES), GET_TEXT_F(MSG_NO), yesFunc, noFunc, fpre, string, fsuf);
}
};

View File

@ -242,6 +242,9 @@ class MenuItem_bool : public MenuEditItemBase {
#define START_SCREEN() SCREEN_OR_MENU_LOOP(false)
#define START_MENU() SCREEN_OR_MENU_LOOP(true)
#define NEXT_ITEM() (++_thisItemNr)
#define MY_LINE() (_menuLineNr == _thisItemNr)
#define HIGHLIGHTED() (encoderLine == _thisItemNr)
#define CLICKED() (HIGHLIGHTED() && ui.use_click())
#define SKIP_ITEM() NEXT_ITEM()
#define END_SCREEN() } screen_items = _thisItemNr
#define END_MENU() END_SCREEN(); UNUSED(_skipStatic)
@ -274,19 +277,19 @@ class MenuItem_bool : public MenuEditItemBase {
#define _MENU_INNER_F(TYPE, USE_MULTIPLIER, FLABEL, V...) do { \
FSTR_P const flabel = FLABEL; \
if (encoderLine == _thisItemNr && ui.use_click()) { \
if (CLICKED()) { \
_MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
MenuItem_##TYPE::action(flabel, ##V); \
if (ui.screen_changed) return; \
} \
if (ui.should_draw()) \
MenuItem_##TYPE::draw \
(encoderLine == _thisItemNr, _lcdLineNr, flabel, ##V); \
(HIGHLIGHTED(), _lcdLineNr, flabel, ##V); \
}while(0)
// Item with optional data
#define _MENU_ITEM_F(TYPE, V...) do { \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
_MENU_INNER_F(TYPE, ##V); \
} \
@ -295,7 +298,7 @@ class MenuItem_bool : public MenuEditItemBase {
// Item with index value, C-string, and optional data
#define _MENU_ITEM_N_S_F(TYPE, N, S, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
MenuItemBase::init(N, S); \
_MENU_INNER_F(TYPE, ##V); \
@ -305,7 +308,7 @@ class MenuItem_bool : public MenuEditItemBase {
// Item with index value and F-string
#define _MENU_ITEM_N_f_F(TYPE, N, f, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
MenuItemBase::init(N, f); \
_MENU_INNER_F(TYPE, ##V); \
@ -315,7 +318,7 @@ class MenuItem_bool : public MenuEditItemBase {
// Item with index value
#define _MENU_ITEM_N_F(TYPE, N, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
MenuItemBase::init(N); \
_MENU_INNER_F(TYPE, ##V); \
@ -325,7 +328,7 @@ class MenuItem_bool : public MenuEditItemBase {
// Items with a unique string
#define _MENU_ITEM_S_F(TYPE, S, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
MenuItemBase::init(0, S); \
_MENU_INNER_F(TYPE, ##V); \
@ -335,7 +338,7 @@ class MenuItem_bool : public MenuEditItemBase {
// Items with a unique F-string
#define _MENU_ITEM_f_F(TYPE, f, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
MenuItemBase::init(0, f); \
_MENU_INNER_F(TYPE, ##V); \
@ -356,13 +359,13 @@ class MenuItem_bool : public MenuEditItemBase {
} while(0)
#define STATIC_ITEM_F(FLABEL, V...) do{ \
if (_menuLineNr == _thisItemNr) \
if (MY_LINE()) \
STATIC_ITEM_INNER_F(FLABEL, ##V); \
NEXT_ITEM(); \
} while(0)
#define STATIC_ITEM_N_F(N, FLABEL, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
MenuItemBase::init(N); \
STATIC_ITEM_INNER_F(FLABEL, ##V); \
} \
@ -500,18 +503,18 @@ class MenuItem_bool : public MenuEditItemBase {
#define EDIT_ITEM_FAST_f(TYPE, f, LABEL, V...) EDIT_ITEM_FAST_f_F(TYPE, f, GET_TEXT_F(LABEL), ##V)
#define _CONFIRM_ITEM_INNER_F(FLABEL, V...) do { \
if (encoderLine == _thisItemNr && ui.use_click()) { \
if (CLICKED()) { \
ui.push_current_screen(); \
ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
return; \
} \
if (ui.should_draw()) MenuItem_confirm::draw \
(encoderLine == _thisItemNr, _lcdLineNr, FLABEL, ##V); \
(HIGHLIGHTED(), _lcdLineNr, FLABEL, ##V); \
}while(0)
// Indexed items set a global index value and optional data
#define _CONFIRM_ITEM_F(FLABEL, V...) do { \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
_CONFIRM_ITEM_INNER_F(FLABEL, ##V); \
} \
@ -520,7 +523,7 @@ class MenuItem_bool : public MenuEditItemBase {
// Indexed items set a global index value
#define _CONFIRM_ITEM_N_S_F(N, S, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (MY_LINE()) { \
_skipStatic = false; \
MenuItemBase::init(N, S); \
_CONFIRM_ITEM_INNER_F(TYPE, ##V); \

View File

@ -393,14 +393,14 @@ 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 fstr, const char * const value/*=nullptr*/) {
void MenuEditItemBase::draw_edit_screen(FSTR_P const ftpl, const char * const value/*=nullptr*/) {
ui.encoder_direction_normal();
TERN_(TOUCH_SCREEN, touch.clear());
uint16_t line = 1;
menu_line(line++);
tft_string.set(fstr, itemIndex, itemStringC, itemStringF);
tft_string.set(ftpl, itemIndex, itemStringC, itemStringF);
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
@ -457,13 +457,13 @@ void TFT::draw_edit_screen_buttons() {
}
// The Select Screen presents a prompt and two "buttons"
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*/) {
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 fsuf/*=nullptr*/) {
uint16_t line = 1;
if (!string) line++;
menu_line(line++);
tft_string.set(pref);
tft_string.set(fpre);
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
@ -474,9 +474,9 @@ void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, con
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
}
if (suff) {
if (fsuf) {
menu_line(line);
tft_string.set(suff);
tft_string.set(fsuf);
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
}

View File

@ -316,14 +316,14 @@ void lcd_put_int(const int i) {
//
// 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 fstr, const char pre_char, const char post_char) {
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char pre_char, const char post_char) {
menu_item(row, sel);
const char *string = FTOP(fstr);
const char *string = FTOP(ftpl);
MarlinImage image = noImage;
switch (*string) {
case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH
case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER
case LCD_STR_REFRESH[0]: image = imgRefresh; break;
case LCD_STR_FOLDER[0]: image = imgDirectory; break;
}
uint8_t offset = MENU_TEXT_X;
@ -354,7 +354,10 @@ void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
menu_item(row);
if (ftpl)
tft_string.set(ftpl, itemIndex, itemStringC, itemStringF);
else
tft_string.set();
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
if (!full || !vstr) {