🚸 Enhance FTDI Eve Touch UI file select dialog (#22742)

This commit is contained in:
Marcio T 2021-09-10 19:03:46 -06:00 committed by Scott Lahteine
parent ee1c1034e5
commit e2a790b759
4 changed files with 19 additions and 20 deletions

View File

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

View File

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

View File

@ -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() {
@ -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))
if (!files.seek(fileIndex)) break;
drawFileButton(files.filename(), getTagForLine(i), files.isDir(), false);
else
break;
mydata.flags.is_empty = false;
}
}
@ -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;
}

View File

@ -29,6 +29,7 @@ struct FilesScreenData {
struct {
uint8_t is_dir : 1;
uint8_t is_root : 1;
uint8_t is_empty : 1;
} flags;
uint8_t selected_tag;
uint8_t num_page;
@ -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);