diff --git a/radio/src/gui/colorlcd/model_select.cpp b/radio/src/gui/colorlcd/model_select.cpp index 36d476881..ab6fef7b8 100644 --- a/radio/src/gui/colorlcd/model_select.cpp +++ b/radio/src/gui/colorlcd/model_select.cpp @@ -36,7 +36,6 @@ inline tmr10ms_t getTicks() { return g_tmr10ms; } struct ModelButtonLayout { uint16_t width; uint16_t height; - uint16_t padding; bool hasImage; uint16_t font; uint16_t columns; @@ -49,10 +48,10 @@ static LAYOUT_VAL(L1_H, 61, 61) static LAYOUT_VAL(L3_W, 336, 300) ModelButtonLayout modelLayouts[] = { - {L0_W, L0_H, PAD_SMALL, true, FONT(STD), 2}, - {L1_W, L1_H, PAD_SMALL, true, FONT(XS), 3}, - {L0_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, PAD_SMALL, false, FONT(STD), 2}, - {L3_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, PAD_SMALL, false, FONT(STD), 1}, + {L0_W, L0_H, true, FONT(STD), 2}, + {L1_W, L1_H, true, FONT(XS), 3}, + {L0_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, false, FONT(STD), 2}, + {L3_W, EdgeTxStyles::UI_ELEMENT_HEIGHT, false, FONT(STD), 1}, }; class ModelButton : public Button @@ -81,42 +80,29 @@ class ModelButton : public Button ? COLOR_THEME_ACTIVE_INDEX : COLOR_THEME_PRIMARY2_INDEX; - coord_t w = width() - 8; - coord_t h = height() - 8; + coord_t w = width() - PAD_SMALL * 2; LcdFlags font = modelLayouts[layout].font; if ((getTextWidth(modelCell->modelName, 0, font) > w)) font = (font == FONT(STD)) ? FONT(XS) : FONT(XXS); if (modelLayouts[layout].hasImage) { - GET_FILENAME(filename, BITMAPS_PATH, modelCell->modelBitmap, ""); - auto bitmap = new StaticBitmap(this, {2, 2, w, h}, COLOR(bg_col_idx), filename); - bitmap->show(bitmap->hasImage()); + if (modelCell->modelBitmap[0] == 0) + showNoImgMsg(); - if (!bitmap->hasImage()) { - 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 fh = getFontHeight(font) - ((font == FONT(STD)) ? 4 : (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); 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_obj_add_style(name->getLvObj(), styles->bg_opacity_75, LV_PART_MAIN); name->padTop(fo); } 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); lv_label_set_long_mode(name->getLvObj(), LV_LABEL_LONG_DOT); - name->setWidth(w); } 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: bool loaded = false; + bool imgLoaded = false; uint8_t layout; ModelCell *modelCell; std::function 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 { setFocused(); @@ -264,6 +290,15 @@ class ModelsPageBody : public Window ModelCell *focusedModel = nullptr; std::function refreshLabels = nullptr; + void checkEvents() override + { + for (auto c : children) { + if (((ModelButton*)c)->loadImage()) { + return; + } + } + } + void openMenu() { Menu *menu = new Menu(this); diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer_fileio.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer_fileio.cpp index c992dad64..878f8d3f4 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer_fileio.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer_fileio.cpp @@ -16,6 +16,8 @@ * GNU General Public License for more details. */ +#pragma GCC optimize("O3") + #include "bitmapbuffer.h" #include "libopenui_file.h" #include "opentx_helpers.h" diff --git a/radio/src/thirdparty/libopenui/src/static.cpp b/radio/src/thirdparty/libopenui/src/static.cpp index 4ac4b65b0..1981586da 100644 --- a/radio/src/thirdparty/libopenui/src/static.cpp +++ b/radio/src/thirdparty/libopenui/src/static.cpp @@ -183,8 +183,8 @@ void StaticIcon::center(coord_t w, coord_t h) // Display image from file system using LVGL with LVGL scaling // - LVGL scaling is slow so don't use this if there are many images StaticImage::StaticImage(Window* parent, const rect_t& rect, - const char* filename) : - Window(parent, rect) + const char* filename, bool dontEnlarge) : + Window(parent, rect), dontEnlarge(dontEnlarge) { setWindowFlag(NO_FOCUS); diff --git a/radio/src/thirdparty/libopenui/src/static.h b/radio/src/thirdparty/libopenui/src/static.h index bb1735276..afbf9604a 100644 --- a/radio/src/thirdparty/libopenui/src/static.h +++ b/radio/src/thirdparty/libopenui/src/static.h @@ -142,7 +142,7 @@ class StaticImage : public Window { public: StaticImage(Window *parent, const rect_t &rect, - const char *filename = nullptr); + const char *filename = nullptr, bool dontEnlarge = false); #if defined(DEBUG_WINDOWS) std::string getName() const override { return "StaticImage"; }