File browser touch preview (#2492)

* do not display model image when outside of the IMAGES folder

* Trigger file action only if file already selected

Co-authored-by: eshifri <eshifri@hotmail.com>
This commit is contained in:
Raphael Coeffic
2022-10-11 10:52:50 +10:00
committed by GitHub
co-authored by eshifri
parent 50c2e5bc77
commit c19373538a
3 changed files with 23 additions and 7 deletions
+15 -2
View File
@@ -203,10 +203,15 @@ void FileBrowser::onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t*
void FileBrowser::onSelected(const char* name, bool is_dir)
{
if (is_dir) return;
if (is_dir) {
if (fileSelected) fileSelected(nullptr, nullptr, nullptr);
return;
}
const char* path = getCurrentPath();
const char* fullpath = getFullPath(name);
if (fileSelected) fileSelected(path, name, fullpath);
selected = name;
}
void FileBrowser::onPress(const char* name, bool is_dir)
@@ -216,7 +221,15 @@ void FileBrowser::onPress(const char* name, bool is_dir)
if (is_dir) {
f_chdir(fullpath);
refresh();
} else if (fileAction){
return;
}
if (!selected || (selected != name)) {
onSelected(name, is_dir);
return;
}
if (fileAction){
fileAction(path, name, fullpath);
}
}
+1
View File
@@ -48,6 +48,7 @@ class FileBrowser : public TableField
void onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t* dsc) override;
private:
const char* selected = nullptr;
FileAction fileAction;
FileAction fileSelected;
};
+7 -5
View File
@@ -38,11 +38,13 @@ void FilePreview::setFile(const char *filename)
if (bitmap != nullptr) delete bitmap;
bitmap = nullptr;
const char *ext = getFileExtension(filename);
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
bitmap = BitmapBuffer::loadBitmap(filename);
} else {
bitmap = nullptr;
if (filename) {
const char *ext = getFileExtension(filename);
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
bitmap = BitmapBuffer::loadBitmap(filename);
} else {
bitmap = nullptr;
}
}
invalidate();
}