file browser: re-add bitmap preview
This commit is contained in:
committed by
Raphael Coeffic
parent
32c1789c73
commit
dff0478351
@@ -108,7 +108,6 @@ FileBrowser::FileBrowser(Window* parent, const rect_t& rect, const char* dir) :
|
|||||||
lv_obj_add_event_cb(lvobj, fb_event, LV_EVENT_ALL, nullptr);
|
lv_obj_add_event_cb(lvobj, fb_event, LV_EVENT_ALL, nullptr);
|
||||||
|
|
||||||
setColumnCount(1);
|
setColumnCount(1);
|
||||||
setColumnWidth(0, rect.w);
|
|
||||||
|
|
||||||
f_chdir(dir);
|
f_chdir(dir);
|
||||||
|
|
||||||
@@ -119,6 +118,7 @@ FileBrowser::FileBrowser(Window* parent, const rect_t& rect, const char* dir) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileBrowser::setFileAction(FileAction fct) { fileAction = std::move(fct); }
|
void FileBrowser::setFileAction(FileAction fct) { fileAction = std::move(fct); }
|
||||||
|
void FileBrowser::setFileSelected(FileAction fct) { fileSelected = std::move(fct); }
|
||||||
|
|
||||||
void FileBrowser::refresh()
|
void FileBrowser::refresh()
|
||||||
{
|
{
|
||||||
@@ -147,6 +147,18 @@ void FileBrowser::refresh()
|
|||||||
select(0, 0);
|
select(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileBrowser::adjustWidth()
|
||||||
|
{
|
||||||
|
lv_obj_update_layout(lvobj);
|
||||||
|
setColumnWidth(0, lv_obj_get_width(lvobj));
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileBrowser::onSelected(uint16_t row, uint16_t col)
|
||||||
|
{
|
||||||
|
bool is_dir = lv_table_has_cell_ctrl(lvobj, row, col, CELL_CTRL_DIR);
|
||||||
|
onSelected(lv_table_get_cell_value(lvobj, row, col), is_dir);
|
||||||
|
}
|
||||||
|
|
||||||
void FileBrowser::onPress(uint16_t row, uint16_t col)
|
void FileBrowser::onPress(uint16_t row, uint16_t col)
|
||||||
{
|
{
|
||||||
bool is_dir = lv_table_has_cell_ctrl(lvobj, row, col, CELL_CTRL_DIR);
|
bool is_dir = lv_table_has_cell_ctrl(lvobj, row, col, CELL_CTRL_DIR);
|
||||||
@@ -189,6 +201,14 @@ void FileBrowser::onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t*
|
|||||||
lv_draw_label(dsc->draw_ctx, dsc->label_dsc, &coords, sym, nullptr);
|
lv_draw_label(dsc->draw_ctx, dsc->label_dsc, &coords, sym, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileBrowser::onSelected(const char* name, bool is_dir)
|
||||||
|
{
|
||||||
|
if (is_dir) return;
|
||||||
|
const char* path = getCurrentPath();
|
||||||
|
const char* fullpath = getFullPath(name);
|
||||||
|
if (fileSelected) fileSelected(path, name, fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
void FileBrowser::onPress(const char* name, bool is_dir)
|
void FileBrowser::onPress(const char* name, bool is_dir)
|
||||||
{
|
{
|
||||||
const char* path = getCurrentPath();
|
const char* path = getCurrentPath();
|
||||||
|
|||||||
@@ -30,17 +30,24 @@ class FileBrowser : public TableField
|
|||||||
typedef std::function<void(const char*, const char*, const char*)> FileAction;
|
typedef std::function<void(const char*, const char*, const char*)> FileAction;
|
||||||
|
|
||||||
FileBrowser(Window* parent, const rect_t& rect, const char* dir);
|
FileBrowser(Window* parent, const rect_t& rect, const char* dir);
|
||||||
|
|
||||||
void setFileAction(FileAction fct);
|
void setFileAction(FileAction fct);
|
||||||
|
void setFileSelected(FileAction fct);
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
|
void adjustWidth();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void onSelected(const char* name, bool is_dir);
|
||||||
void onPress(const char* name, bool is_dir);
|
void onPress(const char* name, bool is_dir);
|
||||||
|
|
||||||
// TableField methods
|
// TableField methods
|
||||||
|
void onSelected(uint16_t row, uint16_t col) override;
|
||||||
void onPress(uint16_t row, uint16_t col) override;
|
void onPress(uint16_t row, uint16_t col) override;
|
||||||
void onDrawBegin(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t* dsc) override;
|
void onDrawBegin(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;
|
void onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t* dsc) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileAction fileAction;
|
FileAction fileAction;
|
||||||
|
FileAction fileSelected;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,14 +61,18 @@ coord_t FilePreview::getBitmapHeight() const
|
|||||||
|
|
||||||
void FilePreview::paint(BitmapBuffer *dc)
|
void FilePreview::paint(BitmapBuffer *dc)
|
||||||
{
|
{
|
||||||
|
if (!bitmap) return;
|
||||||
|
|
||||||
|
coord_t w = lv_obj_get_content_width(lvobj);
|
||||||
|
coord_t h = lv_obj_get_content_height(lvobj);
|
||||||
|
|
||||||
|
coord_t bm_w = min<coord_t>(w, bitmap->width());
|
||||||
|
coord_t bm_h = min<coord_t>(h, bitmap->height());
|
||||||
|
|
||||||
|
coord_t border_w = lv_obj_get_style_border_width(lvobj, 0);
|
||||||
|
coord_t x = border_w + lv_obj_get_style_pad_left(lvobj, 0);
|
||||||
|
coord_t y = border_w + lv_obj_get_style_pad_top(lvobj, 0);
|
||||||
|
|
||||||
dc->setFormat(BMP_RGB565);
|
dc->setFormat(BMP_RGB565);
|
||||||
coord_t y = /*_drawCentered ? parent->getScrollPositionY() + 2 :*/ 2;
|
dc->drawScaledBitmap(bitmap, x + (w - bm_w) / 2, y + (h - bm_h) / 2, bm_w, bm_h);
|
||||||
coord_t h = _drawCentered ? MENU_BODY_HEIGHT - 4 : rect.h;
|
|
||||||
if (bitmap != nullptr) {
|
|
||||||
coord_t bitmapHeight = min<coord_t>(h, bitmap->height());
|
|
||||||
coord_t bitmapWidth = min<coord_t>(width(), bitmap->width());
|
|
||||||
dc->drawScaledBitmap(bitmap, (width() - bitmapWidth) / 2,
|
|
||||||
_drawCentered ? y + (h - bitmapHeight) / 2 : 0,
|
|
||||||
bitmapWidth, bitmapHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,10 +102,6 @@ class FileNameEditWindow : public Page
|
|||||||
RadioSdManagerPage::RadioSdManagerPage() :
|
RadioSdManagerPage::RadioSdManagerPage() :
|
||||||
PageTab(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, ICON_RADIO_SD_MANAGER)
|
PageTab(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, ICON_RADIO_SD_MANAGER)
|
||||||
{
|
{
|
||||||
// setOnSetVisibleHandler([]() {
|
|
||||||
// TRACE("f_chdir(ROOT_PATH)");
|
|
||||||
// f_chdir(ROOT_PATH);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -147,28 +143,49 @@ class FlashDialog: public FullScreenDialog
|
|||||||
Progress progress;
|
Progress progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if LCD_W > LCD_H // landscape
|
||||||
|
static const lv_coord_t col_dsc[] = {LV_GRID_FR(3), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST};
|
||||||
|
static const lv_coord_t row_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||||
|
#else // portrait
|
||||||
|
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||||
|
static const lv_coord_t row_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||||
|
#endif
|
||||||
|
|
||||||
void RadioSdManagerPage::build(FormWindow * window)
|
void RadioSdManagerPage::build(FormWindow * window)
|
||||||
{
|
{
|
||||||
rect_t r = window->getRect();
|
FlexGridLayout grid(col_dsc, row_dsc, 0);
|
||||||
#if LCD_W > LCD_H
|
FormGroup* form = new FormGroup(window, rect_t{});
|
||||||
r.w = r.w * 0.6;
|
form->setWidth(window->width());
|
||||||
#endif
|
form->setHeight(window->height());
|
||||||
browser = new FileBrowser(window, r, ROOT_PATH);
|
grid.apply(form);
|
||||||
|
|
||||||
|
browser = new FileBrowser(form, rect_t{}, ROOT_PATH);
|
||||||
|
grid.add(browser);
|
||||||
|
grid.nextCell();
|
||||||
|
|
||||||
|
auto obj = browser->getLvObj();
|
||||||
|
lv_obj_set_style_grid_cell_x_align(obj, LV_GRID_ALIGN_STRETCH, 0);
|
||||||
|
lv_obj_set_style_grid_cell_y_align(obj, LV_GRID_ALIGN_STRETCH, 0);
|
||||||
|
|
||||||
|
// Adjust file browser width
|
||||||
|
browser->adjustWidth();
|
||||||
|
|
||||||
|
preview = new FilePreview(form, rect_t{});
|
||||||
|
grid.add(preview);
|
||||||
|
grid.nextCell();
|
||||||
|
|
||||||
|
obj = preview->getLvObj();
|
||||||
|
lv_obj_set_style_pad_all(obj, lv_dpx(8), 0);
|
||||||
|
lv_obj_set_style_grid_cell_x_align(obj, LV_GRID_ALIGN_STRETCH, 0);
|
||||||
|
lv_obj_set_style_grid_cell_y_align(obj, LV_GRID_ALIGN_STRETCH, 0);
|
||||||
|
|
||||||
browser->setFileAction([=](const char* path, const char* name, const char* fullpath) {
|
browser->setFileAction([=](const char* path, const char* name, const char* fullpath) {
|
||||||
fileAction(path, name, fullpath);
|
fileAction(path, name, fullpath);
|
||||||
});
|
});
|
||||||
|
browser->setFileSelected([=](const char* path, const char* name, const char* fullpath) {
|
||||||
|
preview->setFile(fullpath);
|
||||||
|
});
|
||||||
browser->refresh();
|
browser->refresh();
|
||||||
|
|
||||||
// button->setFocusHandler([=](bool active) {
|
|
||||||
// if (active) {
|
|
||||||
// preview->setFile(getFullPath(name));
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// grid.nextLine();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// preview->setHeight(max(window->height(), grid.getWindowHeight()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioSdManagerPage::fileAction(const char* path, const char* name,
|
void RadioSdManagerPage::fileAction(const char* path, const char* name,
|
||||||
|
|||||||
@@ -24,10 +24,12 @@
|
|||||||
enum MultiModuleType : short;
|
enum MultiModuleType : short;
|
||||||
|
|
||||||
class FileBrowser;
|
class FileBrowser;
|
||||||
|
class FilePreview;
|
||||||
|
|
||||||
class RadioSdManagerPage : public PageTab
|
class RadioSdManagerPage : public PageTab
|
||||||
{
|
{
|
||||||
FileBrowser* browser = nullptr;
|
FileBrowser* browser = nullptr;
|
||||||
|
FilePreview* preview = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RadioSdManagerPage();
|
RadioSdManagerPage();
|
||||||
|
|||||||
Vendored
+1
-1
Submodule radio/src/thirdparty/libopenui updated: 9daecc6164...1dd1f6d623
Reference in New Issue
Block a user