0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-01-31 14:12:52 +00:00

🐛 Fix FTDI Eve Touch UI (#22500)

This commit is contained in:
Marcio T 2021-08-03 18:06:16 -06:00 committed by GitHub
parent afca6e7459
commit 092b5942c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 83 additions and 92 deletions

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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;

View file

@ -31,7 +31,6 @@ class DialogBoxBaseClass : public BaseScreen {
template<typename T> 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:

View file

@ -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));

View file

@ -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

View file

@ -51,7 +51,5 @@ class InterfaceSoundsScreen : public BaseScreen, public CachedScreen<INTERFACE_S
static void onEntry();
static void onRedraw(draw_mode_t);
static bool onTouchStart(uint8_t tag);
static bool onTouchEnd(uint8_t tag);
static void onIdle();
};

View file

@ -26,8 +26,12 @@
#ifdef FTDI_SPINNER_DIALOG_BOX
#define GRID_COLS 2
#define GRID_ROWS 8
using namespace FTDI;
using namespace ExtUI;
using namespace Theme;
constexpr static SpinnerDialogBoxData &mydata = screen_data.SpinnerDialogBox;
@ -35,35 +39,65 @@ void SpinnerDialogBox::onEntry() {
mydata.auto_hide = true;
}
void SpinnerDialogBox::onExit() {
CommandProcessor cmd;
cmd.stop().execute();
}
void SpinnerDialogBox::onRefresh() {
using namespace FTDI;
DLCache dlcache(SPINNER_CACHE);
CommandProcessor cmd;
cmd.cmd(CMD_DLSTART);
if (dlcache.has_data())
dlcache.append();
else
dlcache.store(SPINNER_DL_SIZE);
cmd.spinner(BTN_POS(1,4), BTN_SIZE(2,3)).execute();
}
void SpinnerDialogBox::onRedraw(draw_mode_t) {
}
void SpinnerDialogBox::show(progmem_str message) {
drawMessage(message);
drawSpinner();
storeBackground();
GOTO_SCREEN(SpinnerDialogBox);
CommandProcessor cmd;
if (AT_SCREEN(SpinnerDialogBox)) cmd.stop().execute();
cmd.cmd(CMD_DLSTART)
.cmd(CLEAR_COLOR_RGB(bg_color))
.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_large);
DLCache dlcache(SPINNER_CACHE);
if (!dlcache.store(SPINNER_DL_SIZE)) {
SERIAL_ECHO_MSG("CachedScreen::storeBackground() failed: not enough DL cache space");
cmd.cmd(CMD_DLSTART).cmd(CLEAR(true,true,true));
dlcache.store(SPINNER_DL_SIZE);
}
if (AT_SCREEN(SpinnerDialogBox))
cmd.spinner(BTN_POS(1,4), BTN_SIZE(2,3)).execute();
else
GOTO_SCREEN(SpinnerDialogBox);
mydata.auto_hide = false;
}
void SpinnerDialogBox::hide() {
CommandProcessor cmd;
cmd.stop().execute();
GOTO_PREVIOUS();
}
void SpinnerDialogBox::enqueueAndWait(progmem_str message, progmem_str commands) {
show(message);
ExtUI::injectCommands_P((const char*)commands);
mydata.auto_hide = true;
}
void SpinnerDialogBox::enqueueAndWait(progmem_str message, char *commands) {
show(message);
ExtUI::injectCommands(commands);
mydata.auto_hide = true;
}
void SpinnerDialogBox::onIdle() {
reset_menu_timeout();
if (mydata.auto_hide && !commandsInQueue()) {
mydata.auto_hide = false;
hide();

View file

@ -29,10 +29,12 @@ struct SpinnerDialogBoxData {
bool auto_hide;
};
class SpinnerDialogBox : public DialogBoxBaseClass, public CachedScreen<SPINNER_CACHE,SPINNER_DL_SIZE> {
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);