mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-26 13:25:54 +00:00
🚸 Improved menu responsiveness with MarlinUI + U8Glib. (#26555)
Co-authored-by: Jason Smith <jason.inet@gmail.com> Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
9a5f1d2f51
commit
ee99eed3bf
@ -1344,7 +1344,7 @@ void MarlinUI::draw_status_screen() {
|
||||
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
|
||||
lcd_put_lchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
|
||||
uint8_t n = LCD_WIDTH - 2;
|
||||
n -= lcd_put_u8str_max(ui.scrolled_filename(theCard, n, row, sel), n);
|
||||
n -= lcd_put_u8str_max(ui.scrolled_filename(theCard, n, sel), n);
|
||||
for (; n; --n) lcd_put_u8str(F(" "));
|
||||
lcd_put_lchar(isDir ? LCD_STR_FOLDER[0] : ' ');
|
||||
}
|
||||
|
@ -1088,7 +1088,7 @@ void MarlinUI::draw_status_screen() {
|
||||
lcd_moveto(0, row);
|
||||
lcd.write(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
|
||||
uint8_t n = LCD_WIDTH - 2;
|
||||
n -= lcd_put_u8str_max(ui.scrolled_filename(theCard, n, row, sel), n);
|
||||
n -= lcd_put_u8str_max(ui.scrolled_filename(theCard, n, sel), n);
|
||||
for (; n; --n) lcd.write(' ');
|
||||
lcd.write(isDir ? LCD_STR_FOLDER[0] : ' ');
|
||||
lcd.print_line();
|
||||
|
@ -619,7 +619,7 @@ void MarlinUI::clear_for_drawing() {
|
||||
const uint8_t maxlen = LCD_WIDTH - isDir;
|
||||
if (isDir) lcd_put_lchar(LCD_STR_FOLDER[0]);
|
||||
const pixel_len_t pixw = maxlen * (MENU_FONT_WIDTH);
|
||||
pixel_len_t n = pixw - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), pixw);
|
||||
pixel_len_t n = pixw - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, sel), pixw);
|
||||
for (; n > MENU_FONT_WIDTH; n -= MENU_FONT_WIDTH) lcd_put_u8str(F(" "));
|
||||
}
|
||||
|
||||
|
@ -489,7 +489,7 @@ void MarlinUI::draw_status_message(const bool blink) {
|
||||
maxlen -= 2;
|
||||
}
|
||||
|
||||
dwin_string.add(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
|
||||
dwin_string.add(ui.scrolled_filename(theCard, maxlen, sel), maxlen);
|
||||
uint8_t n = maxlen - dwin_string.length;
|
||||
while (n > 0) { dwin_string.add(' '); --n; }
|
||||
lcd_moveto(1, row);
|
||||
|
@ -358,25 +358,21 @@ void MarlinUI::init() {
|
||||
#if HAS_MEDIA
|
||||
|
||||
#if MARLINUI_SCROLL_NAME
|
||||
uint8_t MarlinUI::filename_scroll_pos, MarlinUI::filename_scroll_max;
|
||||
static uint8_t filename_scroll_pos, filename_scroll_max;
|
||||
#endif
|
||||
|
||||
const char * MarlinUI::scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll) {
|
||||
const char * MarlinUI::scrolled_filename(CardReader &theCard, const uint8_t maxlen, const bool doScroll) {
|
||||
const char *outstr = theCard.longest_filename();
|
||||
if (theCard.longFilename[0]) {
|
||||
#if MARLINUI_SCROLL_NAME
|
||||
if (doScroll) {
|
||||
for (uint8_t l = FILENAME_LENGTH; l--;)
|
||||
hash = ((hash << 1) | (hash >> 7)) ^ theCard.filename[l]; // rotate, xor
|
||||
static uint8_t filename_scroll_hash;
|
||||
if (filename_scroll_hash != hash) { // If the hash changed...
|
||||
filename_scroll_hash = hash; // Save the new hash
|
||||
filename_scroll_max = _MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
|
||||
filename_scroll_pos = 0; // Reset scroll to the start
|
||||
lcd_status_update_delay = 8; // Don't scroll right away
|
||||
filename_scroll_max = _MAX(0, utf8_strlen(theCard.longFilename) - maxlen);
|
||||
if (filename_scroll_max) {
|
||||
// Ensure filename_scroll_pos isn't out of bounds even though it should never happen.
|
||||
if (filename_scroll_pos > filename_scroll_max) filename_scroll_pos = 0;
|
||||
// Advance byte position corresponding to filename_scroll_pos char position
|
||||
outstr += TERN(UTF_FILENAME_SUPPORT, utf8_byte_pos_by_char_num(outstr, filename_scroll_pos), filename_scroll_pos);
|
||||
}
|
||||
// Advance byte position corresponding to filename_scroll_pos char position
|
||||
outstr += TERN(UTF_FILENAME_SUPPORT, utf8_byte_pos_by_char_num(outstr, filename_scroll_pos), filename_scroll_pos);
|
||||
}
|
||||
#else
|
||||
theCard.longFilename[
|
||||
@ -1002,22 +998,19 @@ void MarlinUI::init() {
|
||||
|
||||
#endif // HAS_MARLINUI_MENU
|
||||
|
||||
if (ELAPSED(ms, next_lcd_update_ms) || TERN0(HAS_MARLINUI_U8GLIB, drawing_screen)) {
|
||||
|
||||
const bool lcd_update_ms_elapsed = ELAPSED(ms, next_lcd_update_ms);
|
||||
if (lcd_update_ms_elapsed) {
|
||||
next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
|
||||
|
||||
#if HAS_TOUCH_BUTTONS
|
||||
|
||||
if (on_status_screen()) next_lcd_update_ms += (LCD_UPDATE_INTERVAL) * 2;
|
||||
|
||||
TERN_(HAS_ENCODER_ACTION, touch_buttons = touchBt.read_buttons());
|
||||
|
||||
#endif
|
||||
|
||||
TERN_(LCD_HAS_STATUS_INDICATORS, update_indicators());
|
||||
|
||||
#if HAS_ENCODER_ACTION
|
||||
|
||||
TERN_(HAS_SLOW_BUTTONS, slow_buttons = read_slow_buttons()); // Buttons that take too long to read in interrupt context
|
||||
|
||||
if (TERN0(IS_RRW_KEYPAD, handle_keypad()))
|
||||
@ -1082,9 +1075,16 @@ void MarlinUI::init() {
|
||||
#endif
|
||||
|
||||
refresh(LCDVIEW_REDRAW_NOW);
|
||||
TERN_(HAS_MARLINUI_U8GLIB, drawing_screen = false);
|
||||
#if MARLINUI_SCROLL_NAME
|
||||
filename_scroll_max = 0;
|
||||
filename_scroll_pos = 0;
|
||||
lcd_status_update_delay = 9;
|
||||
#endif
|
||||
|
||||
TERN_(HAS_LED_POWEROFF_TIMEOUT, if (!powerManager.psu_on) leds.reset_timeout(ms));
|
||||
} // encoder or click
|
||||
|
||||
} // encoder activity
|
||||
|
||||
#endif // HAS_ENCODER_ACTION
|
||||
|
||||
@ -1094,19 +1094,23 @@ void MarlinUI::init() {
|
||||
lcd_status_update_delay = TERN(HAS_MARLINUI_U8GLIB, 12, 9);
|
||||
if (max_display_update_time) max_display_update_time--; // Be sure never go to a very big number
|
||||
refresh(LCDVIEW_REDRAW_NOW);
|
||||
TERN_(HAS_MARLINUI_U8GLIB, drawing_screen = false);
|
||||
}
|
||||
|
||||
#if ALL(HAS_MARLINUI_MENU, SCROLL_LONG_FILENAMES)
|
||||
#if MARLINUI_SCROLL_NAME
|
||||
// If scrolling of long file names is enabled and we are in the sd card menu,
|
||||
// cause a refresh to occur until all the text has scrolled into view.
|
||||
if (currentScreen == menu_media && !lcd_status_update_delay--) {
|
||||
if (currentScreen == menu_media && filename_scroll_max && !lcd_status_update_delay--) {
|
||||
lcd_status_update_delay = ++filename_scroll_pos >= filename_scroll_max ? 12 : 4; // Long delay at end and start
|
||||
if (filename_scroll_pos > filename_scroll_max) filename_scroll_pos = 0;
|
||||
refresh(LCDVIEW_REDRAW_NOW);
|
||||
TERN_(HAS_MARLINUI_U8GLIB, drawing_screen = false);
|
||||
reset_status_timeout(ms);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (lcd_update_ms_elapsed || drawing_screen) {
|
||||
// Then we want to use only 50% of the time
|
||||
const uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
|
||||
|
||||
@ -1128,7 +1132,6 @@ void MarlinUI::init() {
|
||||
TERN_(HAS_ADC_BUTTONS, keypad_buttons = 0);
|
||||
|
||||
#if HAS_MARLINUI_U8GLIB
|
||||
|
||||
#if ENABLED(LIGHTWEIGHT_UI)
|
||||
const bool in_status = on_status_screen(),
|
||||
do_u8g_loop = !in_status;
|
||||
@ -1157,14 +1160,11 @@ void MarlinUI::init() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
run_current_screen();
|
||||
|
||||
// Apply all DWIN drawing after processing
|
||||
TERN_(IS_DWIN_MARLINUI, dwinUpdateLCD());
|
||||
|
||||
#endif
|
||||
|
||||
TERN_(HAS_MARLINUI_MENU, lcd_clicked = false);
|
||||
@ -1209,8 +1209,7 @@ void MarlinUI::init() {
|
||||
case LCDVIEW_CALL_NO_REDRAW:
|
||||
default: break;
|
||||
} // switch
|
||||
|
||||
} // ELAPSED(ms, next_lcd_update_ms)
|
||||
}
|
||||
|
||||
TERN_(HAS_GRAPHICAL_TFT, tft_idle());
|
||||
}
|
||||
|
@ -649,10 +649,7 @@ public:
|
||||
#if ALL(SCROLL_LONG_FILENAMES, HAS_MARLINUI_MENU)
|
||||
#define MARLINUI_SCROLL_NAME 1
|
||||
#endif
|
||||
#if MARLINUI_SCROLL_NAME
|
||||
static uint8_t filename_scroll_pos, filename_scroll_max;
|
||||
#endif
|
||||
static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
|
||||
static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, const bool doScroll);
|
||||
#endif
|
||||
|
||||
#if HAS_PREHEAT
|
||||
|
@ -386,7 +386,7 @@ void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t s
|
||||
menu_item(row, sel);
|
||||
if (isDir) tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
|
||||
uint8_t maxlen = (MENU_ITEM_HEIGHT) - (MENU_TEXT_Y) + 1;
|
||||
tft.add_text(MENU_ITEM_ICON_SPACE, MENU_TEXT_Y, COLOR_MENU_TEXT, ui.scrolled_filename(theCard, maxlen, row, sel));
|
||||
tft.add_text(MENU_ITEM_ICON_SPACE, MENU_TEXT_Y, COLOR_MENU_TEXT, ui.scrolled_filename(theCard, maxlen, sel));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user