Skip to content

Commit dd8ac68

Browse files
marciotthinkyhead
authored andcommitted
⚡️ Fixes to FTDI Eve Touch UI (#22347)
1 parent 24f0613 commit dd8ac68

7 files changed

Lines changed: 81 additions & 69 deletions

File tree

Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,25 @@ class CommandProcessor : public CLCD::CommandFifo {
209209
inline CommandProcessor& rectangle(int16_t x, int16_t y, int16_t w, int16_t h) {
210210
using namespace FTDI;
211211
CLCD::CommandFifo::cmd(BEGIN(RECTS));
212-
CLCD::CommandFifo::cmd(VERTEX2F(x * 16, y * 16));
212+
CLCD::CommandFifo::cmd(VERTEX2F( x * 16, y * 16));
213213
CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, (y + h) * 16));
214214
return *this;
215215
}
216216

217+
inline CommandProcessor& border(int16_t x, int16_t y, int16_t w, int16_t h) {
218+
using namespace FTDI;
219+
CLCD::CommandFifo::cmd(BEGIN(LINES));
220+
CLCD::CommandFifo::cmd(VERTEX2F( x * 16, y * 16));
221+
CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, y * 16));
222+
CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, y * 16));
223+
CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, (y + h) * 16));
224+
CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, (y + h) * 16));
225+
CLCD::CommandFifo::cmd(VERTEX2F( x * 16, (y + h) * 16));
226+
CLCD::CommandFifo::cmd(VERTEX2F( x * 16, (y + h) * 16));
227+
CLCD::CommandFifo::cmd(VERTEX2F( x * 16, y * 16));
228+
return *this;
229+
}
230+
217231
template<typename T>
218232
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) {
219233
CLCD::FontMetrics fm(_font);

Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,95 +29,107 @@ namespace FTDI {
2929
* be broken so that the display width is less than w. The line will also
3030
* be broken after a '\n'. Returns the display width of the line.
3131
*/
32-
static uint16_t find_line_break(const FontMetrics &fm, uint16_t w, const char *str, const char *&end) {
33-
w -= fm.get_char_width(' ');
32+
static uint16_t find_line_break(const FontMetrics &utf8_fm, const CLCD::FontMetrics &clcd_fm, const uint16_t w, const char *str, const char *&end, bool use_utf8) {
3433
const char *p = str;
3534
end = str;
3635
uint16_t lw = 0, result = 0;
3736
for (;;) {
38-
utf8_char_t c = get_utf8_char_and_inc(p);
39-
if (c == ' ' || c == '\n' || c == '\0') {
40-
if (lw < w || end == str) {
41-
end = (c == '\0') ? p-1 : p;
37+
const char *next = p;
38+
utf8_char_t c = get_utf8_char_and_inc(next);
39+
// Decide whether to break the string at this location
40+
if (c == '\n' || c == '\0' || c == ' ') {
41+
end = p;
42+
result = lw;
43+
}
44+
if (c == '\n' || c == '\0') break;
45+
// Now add the length of the current character to the tally.
46+
lw += use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c];
47+
// Stop processing once string exceeds the display width
48+
if (lw >= w) {
49+
if (end == str) {
50+
end = p;
4251
result = lw;
4352
}
44-
if (c == '\0' || c == '\n') break;
53+
break;
4554
}
46-
lw += fm.get_char_width(c);
47-
}
48-
if (end == str) {
49-
end = p-1;
50-
result = lw;
55+
p = next;
5156
}
5257
return result;
5358
}
5459

5560
/**
5661
* This function returns a measurements of the word-wrapped text box.
5762
*/
58-
static void measure_text_box(const FontMetrics &fm, const char *str, uint16_t &width, uint16_t &height) {
63+
static void measure_text_box(const FontMetrics &utf8_fm, const CLCD::FontMetrics &clcd_fm, const char *str, uint16_t &width, uint16_t &height, bool use_utf8) {
5964
const char *line_start = (const char*)str;
6065
const char *line_end;
6166
const uint16_t wrap_width = width;
6267
width = height = 0;
6368
for (;;) {
64-
uint16_t line_width = find_line_break(fm, wrap_width, line_start, line_end);
65-
if (line_end == line_start) break;
69+
uint16_t line_width = find_line_break(utf8_fm, clcd_fm, wrap_width, line_start, line_end, use_utf8);
6670
width = max(width, line_width);
67-
height += fm.get_height();
71+
height += utf8_fm.get_height();
6872
line_start = line_end;
73+
if (line_start[0] == '\n' || line_start[0] == ' ') line_start++;
74+
if (line_start[0] == '\0') break;
6975
}
7076
}
7177

7278
/**
7379
* This function draws text inside a bounding box, doing word wrapping and using the largest font that will fit.
7480
*/
7581
void draw_text_box(CommandProcessor& cmd, int x, int y, int w, int h, const char *str, uint16_t options, uint8_t font) {
82+
#if ENABLED(TOUCH_UI_USE_UTF8)
83+
const bool use_utf8 = has_utf8_chars(str);
84+
#else
85+
constexpr bool use_utf8 = false;
86+
#endif
7687
uint16_t box_width, box_height;
7788

78-
FontMetrics fm(font);
89+
FontMetrics utf8_fm(font);
90+
CLCD::FontMetrics clcd_fm;
91+
clcd_fm.load(font);
7992

8093
// Shrink the font until we find a font that fits
8194
for (;;) {
8295
box_width = w;
83-
measure_text_box(fm, str, box_width, box_height);
96+
measure_text_box(utf8_fm, clcd_fm, str, box_width, box_height, use_utf8);
8497
if (box_width <= (uint16_t)w && box_height <= (uint16_t)h) break;
8598
if (font == 26) break;
86-
fm.load(--font);
99+
utf8_fm.load(--font);
100+
clcd_fm.load(font);
87101
}
88102

89103
const uint16_t dx = (options & OPT_RIGHTX) ? w :
90-
(options & OPT_CENTERX) ? w/2 : 0;
91-
const uint16_t dy = (options & OPT_BOTTOMY) ? (h - box_height) :
92-
(options & OPT_CENTERY) ? (h - box_height)/2 : 0;
104+
(options & OPT_CENTERX) ? w / 2 : 0,
105+
dy = (options & OPT_BOTTOMY) ? (h - box_height) :
106+
(options & OPT_CENTERY) ? (h - box_height) / 2 : 0;
93107

94-
const char *line_start = str;
95-
const char *line_end;
108+
const char *line_start = str, *line_end;
96109
for (;;) {
97-
find_line_break(fm, w, line_start, line_end);
98-
if (line_end == line_start) break;
110+
find_line_break(utf8_fm, clcd_fm, w, line_start, line_end, use_utf8);
99111

100112
const size_t line_len = line_end - line_start;
101113
if (line_len) {
102114
char line[line_len + 1];
103115
strncpy(line, line_start, line_len);
104116
line[line_len] = 0;
105-
if (line[line_len - 1] == '\n' || line[line_len - 1] == ' ')
106-
line[line_len - 1] = 0;
107117

108118
#if ENABLED(TOUCH_UI_USE_UTF8)
109-
if (has_utf8_chars(line)) {
110-
draw_utf8_text(cmd, x + dx, y + dy, line, fm.fs, options & ~(OPT_CENTERY | OPT_BOTTOMY));
119+
if (use_utf8) {
120+
draw_utf8_text(cmd, x + dx, y + dy, line, utf8_fm.fs, options & ~(OPT_CENTERY | OPT_BOTTOMY));
111121
} else
112122
#endif
113123
{
114124
cmd.CLCD::CommandFifo::text(x + dx, y + dy, font, options & ~(OPT_CENTERY | OPT_BOTTOMY));
115125
cmd.CLCD::CommandFifo::str(line);
116126
}
117127
}
118-
y += fm.get_height();
128+
y += utf8_fm.get_height();
119129

120130
line_start = line_end;
131+
if (line_start[0] == '\n' || line_start[0] == ' ') line_start++;
132+
if (line_start[0] == '\0') break;
121133
}
122134
}
123135

Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/about_screen.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,13 @@ void AboutScreen::onRedraw(draw_mode_t) {
4444
.cmd(COLOR_RGB(bg_text_enabled))
4545
.tag(0);
4646

47-
#define HEADING_POS BTN_POS(1,2), BTN_SIZE(4,1)
47+
#define HEADING_POS BTN_POS(1,1), BTN_SIZE(4,2)
4848
#define FW_VERS_POS BTN_POS(1,3), BTN_SIZE(4,1)
4949
#define FW_INFO_POS BTN_POS(1,4), BTN_SIZE(4,1)
5050
#define LICENSE_POS BTN_POS(1,5), BTN_SIZE(4,3)
5151
#define STATS_POS BTN_POS(1,8), BTN_SIZE(2,1)
5252
#define BACK_POS BTN_POS(3,8), BTN_SIZE(2,1)
5353

54-
#define _INSET_POS(x,y,w,h) x + w/10, y, w - w/5, h
55-
#define INSET_POS(pos) _INSET_POS(pos)
56-
5754
char about_str[1
5855
+ strlen_P(GET_TEXT(MSG_ABOUT_TOUCH_PANEL_2))
5956
#ifdef TOOLHEAD_NAME
@@ -89,7 +86,7 @@ void AboutScreen::onRedraw(draw_mode_t) {
8986
, OPT_CENTER, font_medium);
9087
cmd.tag(0);
9188
draw_text_box(cmd, FW_INFO_POS, about_str, OPT_CENTER, font_medium);
92-
draw_text_box(cmd, INSET_POS(LICENSE_POS), GET_TEXT_F(MSG_LICENSE), OPT_CENTER, font_tiny);
89+
draw_text_box(cmd, LICENSE_POS, GET_TEXT_F(MSG_LICENSE), OPT_CENTER, font_tiny);
9390

9491
cmd.font(font_medium);
9592
#if ENABLED(PRINTCOUNTER) && defined(FTDI_STATISTICS_SCREEN)

Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_settings_screen.cpp

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
5858
if (what & BACKGROUND) {
5959

6060
#define GRID_COLS 4
61-
#if ENABLED(TOUCH_UI_PORTRAIT)
62-
#define GRID_ROWS 7
63-
#else
64-
#define GRID_ROWS 6
65-
#endif
61+
#define GRID_ROWS TERN(TOUCH_UI_PORTRAIT, 7, 6)
6662

6763
cmd.cmd(CLEAR_COLOR_RGB(bg_color))
6864
.cmd(CLEAR(true,true,true))
@@ -77,21 +73,19 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
7773
#if DISABLED(LCD_FYSETC_TFT81050)
7874
.text(BTN_POS(1,2), BTN_SIZE(2,1), GET_TEXT_F(MSG_LCD_BRIGHTNESS), OPT_RIGHTX | OPT_CENTERY)
7975
#endif
80-
.text(BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_SOUND_VOLUME), OPT_RIGHTX | OPT_CENTERY)
81-
.text(BTN_POS(1,4), BTN_SIZE(2,1), GET_TEXT_F(MSG_SCREEN_LOCK), OPT_RIGHTX | OPT_CENTERY);
76+
.text(BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_SOUND_VOLUME), OPT_RIGHTX | OPT_CENTERY);
77+
#if ENABLED(FTDI_LOCK_SCREEN)
78+
cmd.text(BTN_POS(1,4), BTN_SIZE(2,1), GET_TEXT_F(MSG_SCREEN_LOCK), OPT_RIGHTX | OPT_CENTERY);
79+
#endif
8280
#if DISABLED(TOUCH_UI_NO_BOOTSCREEN)
83-
cmd.text(BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_BOOT_SCREEN), OPT_RIGHTX | OPT_CENTERY);
81+
cmd.text(BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_BOOT_SCREEN), OPT_RIGHTX | OPT_CENTERY);
8482
#endif
8583
#undef EDGE_R
8684
}
8785

8886
if (what & FOREGROUND) {
89-
#if defined(FTDI_LOCK_SCREEN) || DISABLED(TOUCH_UI_NO_BOOTSCREEN)
90-
#if ENABLED(TOUCH_UI_PORTRAIT)
91-
constexpr uint8_t w = 2;
92-
#else
93-
constexpr uint8_t w = 1;
94-
#endif
87+
#if ENABLED(FTDI_LOCK_SCREEN) || DISABLED(TOUCH_UI_NO_BOOTSCREEN)
88+
constexpr uint8_t w = TERN(TOUCH_UI_PORTRAIT, 2, 1);
9589
#endif
9690

9791
cmd.font(font_medium)
@@ -101,7 +95,7 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
10195
.tag(2).slider(BTN_POS(3,2), BTN_SIZE(2,1), mydata.brightness, 128)
10296
#endif
10397
.tag(3).slider(BTN_POS(3,3), BTN_SIZE(2,1), mydata.volume, 0xFF)
104-
#ifdef FTDI_LOCK_SCREEN
98+
#if ENABLED(FTDI_LOCK_SCREEN)
10599
.colors(ui_toggle)
106100
.tag(4).toggle2(BTN_POS(3,4), BTN_SIZE(w,1), GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), LockScreen::is_enabled())
107101
#endif
@@ -126,7 +120,7 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
126120
bool InterfaceSettingsScreen::onTouchEnd(uint8_t tag) {
127121
switch (tag) {
128122
case 1: GOTO_PREVIOUS(); return true;
129-
#ifdef FTDI_LOCK_SCREEN
123+
#if ENABLED(FTDI_LOCK_SCREEN)
130124
case 4:
131125
if (!LockScreen::is_enabled())
132126
LockScreen::enable();
@@ -185,8 +179,7 @@ void InterfaceSettingsScreen::onIdle() {
185179
}
186180

187181
void InterfaceSettingsScreen::failSafeSettings() {
188-
// Reset settings that may make the printer interface
189-
// unusable.
182+
// Reset settings that may make the printer interface unusable.
190183
CLCD::mem_write_32(CLCD::REG::ROTATE, 0);
191184
CLCD::default_touch_transform();
192185
CLCD::default_display_orientation();
@@ -197,9 +190,7 @@ void InterfaceSettingsScreen::failSafeSettings() {
197190
}
198191

199192
void InterfaceSettingsScreen::defaultSettings() {
200-
#ifdef FTDI_LOCK_SCREEN
201-
LockScreen::passcode = 0;
202-
#endif
193+
TERN_(FTDI_LOCK_SCREEN, LockScreen::passcode = 0);
203194
SoundPlayer::set_volume(255);
204195
CLCD::set_brightness(255);
205196
UIData::reset_persistent_data();
@@ -218,11 +209,7 @@ void InterfaceSettingsScreen::saveSettings(char *buff) {
218209

219210
persistent_data_t eeprom;
220211

221-
#ifdef FTDI_LOCK_SCREEN
222-
eeprom.passcode = LockScreen::passcode;
223-
#else
224-
eeprom.passcode = 0;
225-
#endif
212+
eeprom.passcode = TERN0(FTDI_LOCK_SCREEN, LockScreen::passcode);
226213
eeprom.sound_volume = SoundPlayer::get_volume();
227214
eeprom.display_brightness = CLCD::get_brightness();
228215
eeprom.bit_flags = UIData::get_persistent_data();
@@ -251,7 +238,7 @@ void InterfaceSettingsScreen::loadSettings(const char *buff) {
251238

252239
SERIAL_ECHOLNPGM("Loading setting from EEPROM");
253240

254-
#ifdef FTDI_LOCK_SCREEN
241+
#if ENABLED(FTDI_LOCK_SCREEN)
255242
LockScreen::passcode = eeprom.passcode;
256243
#endif
257244
SoundPlayer::set_volume(eeprom.sound_volume);
@@ -282,10 +269,7 @@ void InterfaceSettingsScreen::loadSettings(const char *buff) {
282269
if (success)
283270
success = persistentStore.write_data(0, data, ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE) == PERSISTENT_STORE_SUCCESS;
284271

285-
if (success)
286-
StatusScreen::setStatusMessage(GET_TEXT_F(MSG_EEPROM_RESTORED));
287-
else
288-
StatusScreen::setStatusMessage(GET_TEXT_F(MSG_EEPROM_RESET));
272+
StatusScreen::setStatusMessage(success ? GET_TEXT_F(MSG_EEPROM_RESTORED) : GET_TEXT_F(MSG_EEPROM_RESET));
289273

290274
return success;
291275
}

Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/save_settings_dialog_box.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ void SaveSettingsDialogBox::promptToSaveSettings() {
6060
GOTO_PREVIOUS(); // No save needed.
6161
}
6262

63+
void SaveSettingsDialogBox::promptToSaveAndStay() {
64+
if (needs_save) GOTO_SCREEN(SaveSettingsDialogBox);
65+
}
66+
6367
#endif // FTDI_SAVE_SETTINGS_DIALOG_BOX

Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/save_settings_dialog_box.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ class SaveSettingsDialogBox : public DialogBoxBaseClass, public UncachedScreen {
3434
static bool onTouchEnd(uint8_t tag);
3535

3636
static void promptToSaveSettings();
37+
static void promptToSaveAndStay();
3738
static void settingsChanged() {needs_save = true;}
3839
};

Marlin/src/lcd/extui/ftdi_eve_touch_ui/theme/fonts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace Theme {
5555
constexpr int16_t font_small = 27;
5656
constexpr int16_t font_medium = 28;
5757
constexpr int16_t font_large = 30;
58-
constexpr int16_t font_xlarge = 31;
58+
constexpr int16_t font_xlarge = 30;
5959
constexpr float icon_scale = 0.6;
6060
#endif
6161
#elif defined(TOUCH_UI_320x240)

0 commit comments

Comments
 (0)