diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h index 309c1927c8cb..7504a1387dda 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h @@ -232,13 +232,11 @@ class CommandProcessor : public CLCD::CommandFifo { FORCEDINLINE CommandProcessor& toggle(int16_t x, int16_t y, int16_t w, int16_t h, T text, bool state, uint16_t options = FTDI::OPT_3D) { CLCD::FontMetrics fm(_font); const int16_t widget_h = fm.height * 20.0 / 16; - //const int16_t outer_bar_r = widget_h / 2; - //const int16_t knob_r = outer_bar_r - 1.5; // The y coordinate of the toggle is the baseline of the text, // so we must introduce a fudge factor based on the line height to // actually center the control. const int16_t fudge_y = fm.height * 5 / 16; - CLCD::CommandFifo::toggle(x + h / 2, y + (h - widget_h) / 2 + fudge_y, w - h, _font, options, state); + CLCD::CommandFifo::toggle(x + widget_h, y + (h - widget_h) / 2 + fudge_y, w - widget_h, _font, options, state); CLCD::CommandFifo::str(text); return *this; } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp index 0701e7d68251..544c5fed050e 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp @@ -67,12 +67,12 @@ namespace FTDI { width = height = 0; for (;;) { const uint16_t line_width = find_line_break(utf8_fm, clcd_fm, wrap_width, line_start, line_end, use_utf8); - if (line_end == line_start) break; width = max(width, line_width); height += utf8_fm.get_height(); + if (*line_end == '\n' || *line_end == ' ') line_end++; + if (*line_end == '\0') break; + if (line_end == line_start) break; line_start = line_end; - if (*line_start == '\n' || *line_start == ' ') line_start++; - if (*line_start == '\0') break; } } @@ -109,7 +109,6 @@ namespace FTDI { const char *line_start = str, *line_end; for (;;) { find_line_break(utf8_fm, clcd_fm, w, line_start, line_end, use_utf8); - if (line_end == line_start) break; const size_t line_len = line_end - line_start; if (line_len) { @@ -125,9 +124,10 @@ namespace FTDI { } y += utf8_fm.get_height(); + if (*line_end == '\n' || *line_end == ' ') line_end++; + if (*line_end == '\0') break; + if (line_end == line_start) break; line_start = line_end; - if (*line_start == '\n' || *line_start == ' ') line_start++; - if (*line_start == '\0') break; } } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp index 6a58dd2e497a..4262dd115576 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp @@ -29,30 +29,30 @@ namespace FTDI { * Helper function for drawing text with ellipses. The str buffer may be modified and should have space for up to two extra characters. */ static void _draw_text_with_ellipsis(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, char *str, uint16_t options, uint8_t font) { - FontMetrics fm(font); - const int16_t ellipsisWidth = fm.get_char_width('.') * 3; + #if ENABLED(TOUCH_UI_USE_UTF8) + const bool use_utf8 = has_utf8_chars(str); + #define CHAR_WIDTH(c) use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c] + #else + #define CHAR_WIDTH(c) utf8_fm.get_char_width(c) + constexpr bool use_utf8 = false; + #endif + FontMetrics utf8_fm(font); + CLCD::FontMetrics clcd_fm; + clcd_fm.load(font); + const int16_t ellipsisWidth = utf8_fm.get_char_width('.') * 3; // Compute the total line length, as well as // the location in the string where it can // split and still allow the ellipsis to fit. int16_t lineWidth = 0; - char *breakPoint = str; - #ifdef TOUCH_UI_USE_UTF8 - char *tstr = str; - while (*tstr) { - breakPoint = tstr; - const utf8_char_t c = get_utf8_char_and_inc(tstr); - lineWidth += fm.get_char_width(c); - if (lineWidth + ellipsisWidth < w) - break; - } - #else - for (char *c = str; *c; c++) { - lineWidth += fm.get_char_width(*c); - if (lineWidth + ellipsisWidth < w) - breakPoint = c; - } - #endif + char *breakPoint = str; + char *next = str; + while (*next) { + const utf8_char_t c = get_utf8_char_and_inc(next); + lineWidth += CHAR_WIDTH(c); + if (lineWidth + ellipsisWidth < w) + breakPoint = next; + } if (lineWidth > w) { *breakPoint = '\0'; @@ -61,7 +61,7 @@ namespace FTDI { cmd.apply_text_alignment(x, y, w, h, options); #if ENABLED(TOUCH_UI_USE_UTF8) - if (has_utf8_chars(str)) { + if (use_utf8) { draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options); } else #endif diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.cpp index 500551e862ba..1811779297e3 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.cpp @@ -39,7 +39,7 @@ void DialogBoxBaseClass::drawMessage(T message, int16_t font) { .cmd(CLEAR(true,true,true)) .cmd(COLOR_RGB(bg_text_enabled)) .tag(0); - draw_text_box(cmd, BTN_POS(1,1), BTN_SIZE(2,3), message, OPT_CENTER, font ? font : font_large); + draw_text_box(cmd, BTN_POS(1,1), BTN_SIZE(2,6), message, OPT_CENTER, font ? font : font_large); cmd.colors(normal_btn); } @@ -69,12 +69,6 @@ void DialogBoxBaseClass::drawButton(T label) { template void DialogBoxBaseClass::drawButton(const char *); template void DialogBoxBaseClass::drawButton(progmem_str); -void DialogBoxBaseClass::drawSpinner() { - CommandProcessor cmd; - cmd.cmd(COLOR_RGB(bg_text_enabled)) - .spinner(BTN_POS(1,4), BTN_SIZE(2,3)).execute(); -} - bool DialogBoxBaseClass::onTouchEnd(uint8_t tag) { switch (tag) { case 1: GOTO_PREVIOUS(); return true; diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.h index d48f3a03b3e3..c87640992866 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.h @@ -31,7 +31,6 @@ class DialogBoxBaseClass : public BaseScreen { template static void drawButton(T); static void drawYesNoButtons(uint8_t default_btn = 0); static void drawOkayButton(); - static void drawSpinner(); static void onRedraw(draw_mode_t) {}; public: diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_settings_screen.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_settings_screen.cpp index ebefea2dcd52..5b160c80dfa6 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_settings_screen.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_settings_screen.cpp @@ -104,8 +104,8 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) { #endif #undef EDGE_R #define EDGE_R 0 - #if ENABLED(TOUCH_UI_PORTRAIT) .colors(normal_btn) + #if ENABLED(TOUCH_UI_PORTRAIT) .tag(6).button (BTN_POS(1,6), BTN_SIZE(4,1), GET_TEXT_F(MSG_SOUNDS)) .colors(action_btn) .tag(1).button (BTN_POS(1,7), BTN_SIZE(4,1), GET_TEXT_F(MSG_BUTTON_DONE)); diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.cpp index b951844196f5..889fd606840c 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.cpp @@ -74,8 +74,7 @@ void InterfaceSoundsScreen::onRedraw(draw_mode_t what) { #undef EDGE_R #define EDGE_R 30 .font(font_small) - .tag(0).text (BTN_POS(1,2), BTN_SIZE(2,1), GET_TEXT_F(MSG_SOUND_VOLUME), OPT_RIGHTX | OPT_CENTERY) - .text (BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_CLICK_SOUNDS), OPT_RIGHTX | OPT_CENTERY) + .tag(0).text (BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_CLICK_SOUNDS), OPT_RIGHTX | OPT_CENTERY) .text (BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_STARTING), OPT_RIGHTX | OPT_CENTERY) .text (BTN_POS(1,6), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_FINISHED), OPT_RIGHTX | OPT_CENTERY) .text (BTN_POS(1,7), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_ERROR), OPT_RIGHTX | OPT_CENTERY); @@ -89,18 +88,16 @@ void InterfaceSoundsScreen::onRedraw(draw_mode_t what) { constexpr uint8_t w = 1; #endif - cmd.font(font_medium) - .colors(ui_slider) + cmd.font(font_small) #define EDGE_R 30 - .tag(2).slider (BTN_POS(3,2), BTN_SIZE(2,1), screen_data.InterfaceSettingsScreen.volume, 0xFF) .colors(ui_toggle) - .tag(3).toggle2 (BTN_POS(3,3), BTN_SIZE(w,1), GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), UIData::touch_sounds_enabled()) + .tag(2).toggle2 (BTN_POS(3,3), BTN_SIZE(w,1), GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), UIData::touch_sounds_enabled()) #undef EDGE_R .colors(normal_btn) #define EDGE_R 0 - .tag(4).button (BTN_POS(3,5), BTN_SIZE(2,1), getSoundSelection(PRINTING_STARTED)) - .tag(5).button (BTN_POS(3,6), BTN_SIZE(2,1), getSoundSelection(PRINTING_FINISHED)) - .tag(6).button (BTN_POS(3,7), BTN_SIZE(2,1), getSoundSelection(PRINTING_FAILED)) + .tag(3).button (BTN_POS(3,5), BTN_SIZE(2,1), getSoundSelection(PRINTING_STARTED)) + .tag(4).button (BTN_POS(3,6), BTN_SIZE(2,1), getSoundSelection(PRINTING_FINISHED)) + .tag(5).button (BTN_POS(3,7), BTN_SIZE(2,1), getSoundSelection(PRINTING_FAILED)) .colors(action_btn) .tag(1).button (BTN_POS(1,9), BTN_SIZE(4,1), GET_TEXT_F(MSG_BUTTON_DONE)); } @@ -114,10 +111,10 @@ void InterfaceSoundsScreen::onEntry() { bool InterfaceSoundsScreen::onTouchEnd(uint8_t tag) { switch (tag) { case 1: GOTO_PREVIOUS(); return true; - case 3: UIData::enable_touch_sounds(!UIData::touch_sounds_enabled()); break; - case 4: toggleSoundSelection(PRINTING_STARTED); break; - case 5: toggleSoundSelection(PRINTING_FINISHED); break; - case 6: toggleSoundSelection(PRINTING_FAILED); break; + case 2: UIData::enable_touch_sounds(!UIData::touch_sounds_enabled()); break; + case 3: toggleSoundSelection(PRINTING_STARTED); break; + case 4: toggleSoundSelection(PRINTING_FINISHED); break; + case 5: toggleSoundSelection(PRINTING_FAILED); break; default: return false; } @@ -125,35 +122,4 @@ bool InterfaceSoundsScreen::onTouchEnd(uint8_t tag) { return true; } -bool InterfaceSoundsScreen::onTouchStart(uint8_t tag) { - CommandProcessor cmd; - #undef EDGE_R - #define EDGE_R 30 - switch (tag) { - case 2: cmd.track_linear(BTN_POS(3,2), BTN_SIZE(2,1), 2).execute(); break; - default: break; - } - return true; -} - -void InterfaceSoundsScreen::onIdle() { - if (refresh_timer.elapsed(TOUCH_UPDATE_INTERVAL)) { - refresh_timer.start(); - - uint16_t value; - CommandProcessor cmd; - switch (cmd.track_tag(value)) { - case 2: - screen_data.InterfaceSettingsScreen.volume = value >> 8; - SoundPlayer::set_volume(screen_data.InterfaceSettingsScreen.volume); - SaveSettingsDialogBox::settingsChanged(); - break; - default: - return; - } - onRefresh(); - } - BaseScreen::onIdle(); -} - #endif // FTDI_INTERFACE_SOUNDS_SCREEN diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.h index 046d7390fe32..258fc77c26c0 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.h @@ -51,7 +51,5 @@ class InterfaceSoundsScreen : public BaseScreen, public CachedScreen { +class SpinnerDialogBox : public BaseScreen { public: static void onEntry(); + static void onExit(); static void onRedraw(draw_mode_t); + static void onRefresh(); static void onIdle(); static void show(progmem_str);