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:
co-authored by
eshifri
parent
50c2e5bc77
commit
c19373538a
@@ -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)
|
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* path = getCurrentPath();
|
||||||
const char* fullpath = getFullPath(name);
|
const char* fullpath = getFullPath(name);
|
||||||
if (fileSelected) fileSelected(path, name, fullpath);
|
if (fileSelected) fileSelected(path, name, fullpath);
|
||||||
|
selected = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBrowser::onPress(const char* name, bool is_dir)
|
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) {
|
if (is_dir) {
|
||||||
f_chdir(fullpath);
|
f_chdir(fullpath);
|
||||||
refresh();
|
refresh();
|
||||||
} else if (fileAction){
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selected || (selected != name)) {
|
||||||
|
onSelected(name, is_dir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileAction){
|
||||||
fileAction(path, name, fullpath);
|
fileAction(path, name, fullpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class FileBrowser : public TableField
|
|||||||
void onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t* dsc) override;
|
void onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t* dsc) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const char* selected = nullptr;
|
||||||
FileAction fileAction;
|
FileAction fileAction;
|
||||||
FileAction fileSelected;
|
FileAction fileSelected;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,11 +38,13 @@ void FilePreview::setFile(const char *filename)
|
|||||||
if (bitmap != nullptr) delete bitmap;
|
if (bitmap != nullptr) delete bitmap;
|
||||||
bitmap = nullptr;
|
bitmap = nullptr;
|
||||||
|
|
||||||
const char *ext = getFileExtension(filename);
|
if (filename) {
|
||||||
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
|
const char *ext = getFileExtension(filename);
|
||||||
bitmap = BitmapBuffer::loadBitmap(filename);
|
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
|
||||||
} else {
|
bitmap = BitmapBuffer::loadBitmap(filename);
|
||||||
bitmap = nullptr;
|
} else {
|
||||||
|
bitmap = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user