Skip to content

Commit

Permalink
🚸 Enhance FTDI Eve Touch UI file select dialog (MarlinFirmware#22742)
Browse files Browse the repository at this point in the history
  • Loading branch information
marciot authored and Darred committed Dec 1, 2021
1 parent 440534e commit 11caf23
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using namespace ExtUI;
constexpr static ConfirmStartPrintDialogBoxData &mydata = screen_data.ConfirmStartPrintDialogBox;

void ConfirmStartPrintDialogBox::onRedraw(draw_mode_t) {
const char *filename = getLongFilename();
const char *filename = getFilename();
char buffer[strlen_P(GET_TEXT(MSG_START_PRINT_CONFIRMATION)) + strlen(filename) + 1];
sprintf_P(buffer, GET_TEXT(MSG_START_PRINT_CONFIRMATION), filename);
drawMessage((const char *)buffer);
Expand All @@ -52,10 +52,10 @@ bool ConfirmStartPrintDialogBox::onTouchEnd(uint8_t tag) {
}
}

const char *ConfirmStartPrintDialogBox::getFilename(bool longName) {
const char *ConfirmStartPrintDialogBox::getFilename(bool shortName) {
FileList files;
files.seek(mydata.file_index, true);
return longName ? files.longFilename() : files.shortFilename();
return shortName ? files.shortFilename() : files.filename();
}

void ConfirmStartPrintDialogBox::show(uint8_t file_index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ struct ConfirmStartPrintDialogBoxData {

class ConfirmStartPrintDialogBox : public DialogBoxBaseClass, public UncachedScreen {
private:
inline static const char *getShortFilename() {return getFilename(false);}
inline static const char *getLongFilename() {return getFilename(true);}
inline static const char *getShortFilename() {return getFilename(true);}

static const char *getFilename(bool longName);
static const char *getFilename(bool shortName = false);
public:
static void onRedraw(draw_mode_t);
static bool onTouchEnd(uint8_t);
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/files_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ void FilesScreen::onEntry() {
BaseScreen::onEntry();
}

const char *FilesScreen::getSelectedFilename(bool longName) {
const char *FilesScreen::getSelectedFilename(bool shortName) {
FileList files;
files.seek(getSelectedFileIndex(), true);
return longName ? files.longFilename() : files.shortFilename();
return shortName ? files.shortFilename() : files.filename();
}

void FilesScreen::drawSelectedFile() {
Expand Down Expand Up @@ -132,13 +132,13 @@ void FilesScreen::drawFileList() {
mydata.num_page = max(1,ceil(float(files.count()) / FILES_PER_PAGE));
mydata.cur_page = min(mydata.cur_page, mydata.num_page-1);
mydata.flags.is_root = files.isAtRootDir();
mydata.flags.is_empty = true;

uint16_t fileIndex = mydata.cur_page * FILES_PER_PAGE;
for (uint8_t i = 0; i < FILES_PER_PAGE; i++, fileIndex++) {
if (files.seek(fileIndex))
drawFileButton(files.filename(), getTagForLine(i), files.isDir(), false);
else
break;
if (!files.seek(fileIndex)) break;
drawFileButton(files.filename(), getTagForLine(i), files.isDir(), false);
mydata.flags.is_empty = false;
}
}

Expand Down Expand Up @@ -252,11 +252,11 @@ bool FilesScreen::onTouchEnd(uint8_t tag) {
mydata.scroll_pos = 0;
mydata.scroll_max = 0;
if (FTDI::ftdi_chip >= 810) {
const char *longFilename = getSelectedLongFilename();
if (longFilename[0]) {
const char *filename = getSelectedFilename();
if (filename[0]) {
CommandProcessor cmd;
constexpr int dim[4] = {LIST_POS};
const uint16_t text_width = cmd.font(font_medium).text_width(longFilename);
const uint16_t text_width = cmd.font(font_medium).text_width(filename);
if (text_width > dim[2])
mydata.scroll_max = text_width - dim[2] + MARGIN_L + MARGIN_R + 10;
}
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/files_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

struct FilesScreenData {
struct {
uint8_t is_dir : 1;
uint8_t is_root : 1;
uint8_t is_dir : 1;
uint8_t is_root : 1;
uint8_t is_empty : 1;
} flags;
uint8_t selected_tag;
uint8_t num_page;
Expand All @@ -46,9 +47,8 @@ class FilesScreen : public BaseScreen, public CachedScreen<FILES_SCREEN_CACHE, F
static uint16_t getFileForTag(uint8_t tag);
static uint16_t getSelectedFileIndex();

inline static const char *getSelectedShortFilename() {return getSelectedFilename(false);}
inline static const char *getSelectedLongFilename() {return getSelectedFilename(true);}
static const char *getSelectedFilename(bool longName);
inline static const char *getSelectedShortFilename() {return getSelectedFilename(true);}
static const char *getSelectedFilename(bool shortName = false);

static void drawFileButton(int x, int y, int w, int h, const char *filename, uint8_t tag, bool is_dir, bool is_highlighted);
static void drawFileButton(const char *filename, uint8_t tag, bool is_dir, bool is_highlighted);
Expand Down

0 comments on commit 11caf23

Please sign in to comment.