Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Misc. LCD / string updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 26, 2023
1 parent b25f523 commit 2a88e76
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 58 deletions.
7 changes: 3 additions & 4 deletions Marlin/src/gcode/bedlevel/G35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? ' ' : ']');
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/lcd/dogm/lcdprint_u8g.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ 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);
u8g.setPrintPos(x + ret, y);
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);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
14 changes: 8 additions & 6 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ class MarlinUI {
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

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/lcd/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
31 changes: 17 additions & 14 deletions Marlin/src/lcd/menu/menu_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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); \
} \
Expand All @@ -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); \
Expand All @@ -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); \
Expand All @@ -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); \
Expand All @@ -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); \
Expand All @@ -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); \
Expand All @@ -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); \
} \
Expand Down Expand Up @@ -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); \
} \
Expand All @@ -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); \
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/tft/ui_color_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 2a88e76

Please sign in to comment.