feat(color): delay image load on manage models page (#5146)
This commit is contained in:
@@ -36,7 +36,6 @@ inline tmr10ms_t getTicks() { return g_tmr10ms; }
|
|||||||
struct ModelButtonLayout {
|
struct ModelButtonLayout {
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
uint16_t padding;
|
|
||||||
bool hasImage;
|
bool hasImage;
|
||||||
uint16_t font;
|
uint16_t font;
|
||||||
uint16_t columns;
|
uint16_t columns;
|
||||||
@@ -49,10 +48,10 @@ static LAYOUT_VAL(L1_H, 61, 61)
|
|||||||
static LAYOUT_VAL(L3_W, 336, 300)
|
static LAYOUT_VAL(L3_W, 336, 300)
|
||||||
|
|
||||||
ModelButtonLayout modelLayouts[] = {
|
ModelButtonLayout modelLayouts[] = {
|
||||||
{L0_W, L0_H, PAD_SMALL, true, FONT(STD), 2},
|
{L0_W, L0_H, true, FONT(STD), 2},
|
||||||
{L1_W, L1_H, PAD_SMALL, true, FONT(XS), 3},
|
{L1_W, L1_H, true, FONT(XS), 3},
|
||||||
{L0_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, PAD_SMALL, false, FONT(STD), 2},
|
{L0_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, false, FONT(STD), 2},
|
||||||
{L3_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, PAD_SMALL, false, FONT(STD), 1},
|
{L3_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, false, FONT(STD), 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
class ModelButton : public Button
|
class ModelButton : public Button
|
||||||
@@ -81,42 +80,29 @@ class ModelButton : public Button
|
|||||||
? COLOR_THEME_ACTIVE_INDEX
|
? COLOR_THEME_ACTIVE_INDEX
|
||||||
: COLOR_THEME_PRIMARY2_INDEX;
|
: COLOR_THEME_PRIMARY2_INDEX;
|
||||||
|
|
||||||
coord_t w = width() - 8;
|
coord_t w = width() - PAD_SMALL * 2;
|
||||||
coord_t h = height() - 8;
|
|
||||||
|
|
||||||
LcdFlags font = modelLayouts[layout].font;
|
LcdFlags font = modelLayouts[layout].font;
|
||||||
if ((getTextWidth(modelCell->modelName, 0, font) > w))
|
if ((getTextWidth(modelCell->modelName, 0, font) > w))
|
||||||
font = (font == FONT(STD)) ? FONT(XS) : FONT(XXS);
|
font = (font == FONT(STD)) ? FONT(XS) : FONT(XXS);
|
||||||
|
|
||||||
if (modelLayouts[layout].hasImage) {
|
if (modelLayouts[layout].hasImage) {
|
||||||
GET_FILENAME(filename, BITMAPS_PATH, modelCell->modelBitmap, "");
|
if (modelCell->modelBitmap[0] == 0)
|
||||||
auto bitmap = new StaticBitmap(this, {2, 2, w, h}, COLOR(bg_col_idx), filename);
|
showNoImgMsg();
|
||||||
bitmap->show(bitmap->hasImage());
|
|
||||||
|
|
||||||
if (!bitmap->hasImage()) {
|
coord_t fh = getFontHeight(font) - ((font == FONT(STD)) ? 4 : (font == FONT(XS)) ? 3 : 1);
|
||||||
std::string errorMsg = "(";
|
|
||||||
errorMsg += STR_NO_PICTURE;
|
|
||||||
errorMsg += ")";
|
|
||||||
new StaticText(this, {2, h / 2, w, 17}, errorMsg,
|
|
||||||
CENTERED | COLOR_THEME_SECONDARY1 | FONT(XS));
|
|
||||||
}
|
|
||||||
|
|
||||||
coord_t fh = (font == FONT(STD)) ? 17 : (font == FONT(XS)) ? 14 : 11;
|
|
||||||
coord_t fo = (font == FONT(STD)) ? -3 : (font == FONT(XS)) ? -3 : -1;
|
coord_t fo = (font == FONT(STD)) ? -3 : (font == FONT(XS)) ? -3 : -1;
|
||||||
|
|
||||||
auto name = new StaticText(this, {2, 2, w, fh}, modelCell->modelName,
|
auto name = new StaticText(this, {PAD_TINY, PAD_TINY, w, fh}, modelCell->modelName,
|
||||||
CENTERED | COLOR_THEME_SECONDARY1 | font);
|
CENTERED | COLOR_THEME_SECONDARY1 | font);
|
||||||
lv_label_set_long_mode(name->getLvObj(), LV_LABEL_LONG_DOT);
|
lv_label_set_long_mode(name->getLvObj(), LV_LABEL_LONG_DOT);
|
||||||
name->setWidth(w);
|
|
||||||
name->setHeight(fh);
|
|
||||||
etx_bg_color(name->getLvObj(), (LcdColorIndex)bg_col_idx);
|
etx_bg_color(name->getLvObj(), (LcdColorIndex)bg_col_idx);
|
||||||
etx_obj_add_style(name->getLvObj(), styles->bg_opacity_75, LV_PART_MAIN);
|
etx_obj_add_style(name->getLvObj(), styles->bg_opacity_75, LV_PART_MAIN);
|
||||||
name->padTop(fo);
|
name->padTop(fo);
|
||||||
} else {
|
} else {
|
||||||
auto name = new StaticText(this, {2, 4, w, 24}, modelCell->modelName,
|
auto name = new StaticText(this, {PAD_TINY, PAD_SMALL, w, EdgeTxStyles::PAGE_LINE_HEIGHT}, modelCell->modelName,
|
||||||
COLOR_THEME_SECONDARY1 | font);
|
COLOR_THEME_SECONDARY1 | font);
|
||||||
lv_label_set_long_mode(name->getLvObj(), LV_LABEL_LONG_DOT);
|
lv_label_set_long_mode(name->getLvObj(), LV_LABEL_LONG_DOT);
|
||||||
name->setWidth(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_update_layout(lvobj);
|
lv_obj_update_layout(lvobj);
|
||||||
@@ -145,12 +131,52 @@ class ModelButton : public Button
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool loadImage()
|
||||||
|
{
|
||||||
|
if (loaded && !imgLoaded) {
|
||||||
|
imgLoaded = true;
|
||||||
|
|
||||||
|
coord_t w = width() - PAD_SMALL * 2;
|
||||||
|
coord_t h = height() - PAD_SMALL * 2;
|
||||||
|
|
||||||
|
if (modelLayouts[layout].hasImage) {
|
||||||
|
if (modelCell->modelBitmap[0]) {
|
||||||
|
GET_FILENAME(filename, BITMAPS_PATH, modelCell->modelBitmap, "");
|
||||||
|
auto bitmap = new StaticImage(this, {PAD_TINY, PAD_TINY, w, h}, filename, true);
|
||||||
|
lv_obj_move_background(bitmap->getLvObj());
|
||||||
|
bitmap->show(bitmap->hasImage());
|
||||||
|
if (bitmap->hasImage()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showNoImgMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
|
bool imgLoaded = false;
|
||||||
uint8_t layout;
|
uint8_t layout;
|
||||||
ModelCell *modelCell;
|
ModelCell *modelCell;
|
||||||
std::function<void()> m_setSelected = nullptr;
|
std::function<void()> m_setSelected = nullptr;
|
||||||
|
|
||||||
|
void showNoImgMsg()
|
||||||
|
{
|
||||||
|
coord_t w = width() - PAD_SMALL * 2;
|
||||||
|
coord_t h = height() - PAD_SMALL * 2;
|
||||||
|
std::string errorMsg = "(";
|
||||||
|
errorMsg += STR_NO_PICTURE;
|
||||||
|
errorMsg += ")";
|
||||||
|
LcdFlags font = (modelLayouts[layout].font == FONT(STD)) ? FONT(XS) : FONT(XXS);
|
||||||
|
new StaticText(this, {PAD_TINY, h / 2, w, getFontHeight(font)}, errorMsg,
|
||||||
|
CENTERED | COLOR_THEME_SECONDARY1 | font);
|
||||||
|
}
|
||||||
|
|
||||||
void onClicked() override
|
void onClicked() override
|
||||||
{
|
{
|
||||||
setFocused();
|
setFocused();
|
||||||
@@ -264,6 +290,15 @@ class ModelsPageBody : public Window
|
|||||||
ModelCell *focusedModel = nullptr;
|
ModelCell *focusedModel = nullptr;
|
||||||
std::function<void()> refreshLabels = nullptr;
|
std::function<void()> refreshLabels = nullptr;
|
||||||
|
|
||||||
|
void checkEvents() override
|
||||||
|
{
|
||||||
|
for (auto c : children) {
|
||||||
|
if (((ModelButton*)c)->loadImage()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void openMenu()
|
void openMenu()
|
||||||
{
|
{
|
||||||
Menu *menu = new Menu(this);
|
Menu *menu = new Menu(this);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma GCC optimize("O3")
|
||||||
|
|
||||||
#include "bitmapbuffer.h"
|
#include "bitmapbuffer.h"
|
||||||
#include "libopenui_file.h"
|
#include "libopenui_file.h"
|
||||||
#include "opentx_helpers.h"
|
#include "opentx_helpers.h"
|
||||||
|
|||||||
+2
-2
@@ -183,8 +183,8 @@ void StaticIcon::center(coord_t w, coord_t h)
|
|||||||
// Display image from file system using LVGL with LVGL scaling
|
// Display image from file system using LVGL with LVGL scaling
|
||||||
// - LVGL scaling is slow so don't use this if there are many images
|
// - LVGL scaling is slow so don't use this if there are many images
|
||||||
StaticImage::StaticImage(Window* parent, const rect_t& rect,
|
StaticImage::StaticImage(Window* parent, const rect_t& rect,
|
||||||
const char* filename) :
|
const char* filename, bool dontEnlarge) :
|
||||||
Window(parent, rect)
|
Window(parent, rect), dontEnlarge(dontEnlarge)
|
||||||
{
|
{
|
||||||
setWindowFlag(NO_FOCUS);
|
setWindowFlag(NO_FOCUS);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ class StaticImage : public Window
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StaticImage(Window *parent, const rect_t &rect,
|
StaticImage(Window *parent, const rect_t &rect,
|
||||||
const char *filename = nullptr);
|
const char *filename = nullptr, bool dontEnlarge = false);
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override { return "StaticImage"; }
|
std::string getName() const override { return "StaticImage"; }
|
||||||
|
|||||||
Reference in New Issue
Block a user