feat(color): delay load images in SD browser, show 'Loading...' msg (#5376)
This commit is contained in:
@@ -110,7 +110,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
|
||||
f_close(&imgFile);
|
||||
|
||||
if (!img) {
|
||||
TRACE("load_stb(%s) failed: %s", filename, stbi_failure_reason());
|
||||
TRACE("loadBitmap(%s) failed: %s", filename, stbi_failure_reason());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
|
||||
|
||||
BitmapBuffer *bmp = new BitmapBuffer(dst_fmt, w, h);
|
||||
if (bmp == nullptr) {
|
||||
TRACE("convert_stn_bitmap: malloc failed");
|
||||
TRACE("loadBitmap: malloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,20 +239,48 @@ void RadioSdManagerPage::build(Window * window)
|
||||
// Adjust file browser width
|
||||
browser->adjustWidth();
|
||||
|
||||
preview = new FilePreview(form, rect_t{0, 0, PREVIEW_W, PREVIEW_H});
|
||||
preview->padAll(PAD_SMALL);
|
||||
grid.add(preview);
|
||||
auto box = new Window(form, {0, 0, PREVIEW_W, PREVIEW_H});
|
||||
grid.add(box);
|
||||
grid.nextCell();
|
||||
|
||||
loading = new StaticText(box, {0, 0, LV_SIZE_CONTENT, LV_SIZE_CONTENT}, STR_LOADING);
|
||||
loading->hide();
|
||||
lv_obj_center(loading->getLvObj());
|
||||
|
||||
preview = new FilePreview(box, {0, 0, PREVIEW_W, PREVIEW_H});
|
||||
preview->padAll(PAD_SMALL);
|
||||
|
||||
browser->setFileAction([=](const char* path, const char* name, const char* fullpath) {
|
||||
fileAction(path, name, fullpath);
|
||||
});
|
||||
browser->setFileSelected([=](const char* path, const char* name, const char* fullpath) {
|
||||
preview->setFile(fullpath);
|
||||
preview->setFile(nullptr);
|
||||
loading->hide();
|
||||
auto ext = getFileExtension(fullpath);
|
||||
if (strcasecmp(ext, ".bmp") == 0 || strcasecmp(ext, ".png") == 0 ||
|
||||
strcasecmp(ext, ".jpg") == 0 || strcasecmp(ext, ".jpeg") == 0) {
|
||||
previewFilename = fullpath;
|
||||
loadPreview = 10;
|
||||
loading->show();
|
||||
}
|
||||
});
|
||||
browser->refresh();
|
||||
}
|
||||
|
||||
void RadioSdManagerPage::checkEvents()
|
||||
{
|
||||
PageTab::checkEvents();
|
||||
|
||||
if (loadPreview) {
|
||||
loadPreview -= 1;
|
||||
if (loadPreview == 0) {
|
||||
loading->hide();
|
||||
auto filename = previewFilename;
|
||||
previewFilename = nullptr;
|
||||
preview->setFile(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
void RadioSdManagerPage::fileAction(const char* path, const char* name,
|
||||
const char* fullpath)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,10 @@ class RadioSdManagerPage : public PageTab
|
||||
static LAYOUT_VAL(PREVIEW_H, LCD_H - 68, (LCD_H - 68) / 3)
|
||||
|
||||
protected:
|
||||
int loadPreview = 0;
|
||||
Window* loading = nullptr;
|
||||
const char* previewFilename = nullptr;
|
||||
|
||||
void fileAction(const char* path, const char* name, const char* fullpath);
|
||||
|
||||
void BootloaderUpdate(const char* fn);
|
||||
@@ -51,4 +55,6 @@ class RadioSdManagerPage : public PageTab
|
||||
void FrSkyFirmwareUpdate(const char* fn, ModuleIndex module);
|
||||
void MultiFirmwareUpdate(const char* fn, ModuleIndex module,
|
||||
MultiModuleType type);
|
||||
|
||||
void checkEvents() override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user