feat(color): reduce lag in scrolling main view when using model info widget (#6296)
This commit is contained in:
@@ -301,6 +301,14 @@ void StaticBitmap::setSource(const char *filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StaticBitmap::clearSource()
|
||||||
|
{
|
||||||
|
if (img) delete img;
|
||||||
|
img = nullptr;
|
||||||
|
if (canvas) lv_obj_del(canvas);
|
||||||
|
canvas = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
StaticBitmap::~StaticBitmap()
|
StaticBitmap::~StaticBitmap()
|
||||||
{
|
{
|
||||||
if (img) delete img;
|
if (img) delete img;
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ class StaticBitmap : public Window
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setSource(const char *filename);
|
void setSource(const char *filename);
|
||||||
|
void clearSource();
|
||||||
bool hasImage() const;
|
bool hasImage() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -73,30 +73,24 @@ rect_t TopBar::getZone(unsigned int index) const
|
|||||||
|
|
||||||
void TopBar::setVisible(float visible) // 0.0 -> 1.0
|
void TopBar::setVisible(float visible) // 0.0 -> 1.0
|
||||||
{
|
{
|
||||||
|
coord_t y = 0;
|
||||||
if (visible == 0.0) {
|
if (visible == 0.0) {
|
||||||
setTop(-(int)EdgeTxStyles::MENU_HEADER_HEIGHT);
|
y = -EdgeTxStyles::MENU_HEADER_HEIGHT;
|
||||||
}
|
} else if (visible > 0.0 && visible < 1.0){
|
||||||
else if (visible == 1.0) {
|
y = -(float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
|
||||||
setTop(0);
|
|
||||||
}
|
|
||||||
else if (visible > 0.0 && visible < 1.0){
|
|
||||||
float top = - (float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
|
|
||||||
setTop((coord_t)top);
|
|
||||||
}
|
}
|
||||||
|
if (y != top()) setTop(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBar::setEdgeTxButtonVisible(float visible) // 0.0 -> 1.0
|
void TopBar::setEdgeTxButtonVisible(float visible) // 0.0 -> 1.0
|
||||||
{
|
{
|
||||||
|
coord_t y = 0;
|
||||||
if (visible == 0.0) {
|
if (visible == 0.0) {
|
||||||
headerIcon->setTop(-(int)EdgeTxStyles::MENU_HEADER_HEIGHT);
|
y = -EdgeTxStyles::MENU_HEADER_HEIGHT;
|
||||||
}
|
} else if (visible > 0.0 && visible < 1.0){
|
||||||
else if (visible == 1.0) {
|
y = -(float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
|
||||||
headerIcon->setTop(0);
|
|
||||||
}
|
|
||||||
else if (visible > 0.0 && visible < 1.0){
|
|
||||||
float top = - (float)EdgeTxStyles::MENU_HEADER_HEIGHT * (1.0 - visible);
|
|
||||||
headerIcon->setTop((coord_t)top);
|
|
||||||
}
|
}
|
||||||
|
if (y != headerIcon->top()) headerIcon->setTop(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
|
coord_t TopBar::getVisibleHeight(float visible) const // 0.0 -> 1.0
|
||||||
|
|||||||
@@ -52,17 +52,26 @@ static void saveViewId(unsigned view)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tile_view_scroll_begin(lv_event_t * e)
|
||||||
|
{
|
||||||
|
lv_anim_t* a = (lv_anim_t*)lv_event_get_param(e);
|
||||||
|
if (a) a->time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void tile_view_scroll(lv_event_t* e)
|
static void tile_view_scroll(lv_event_t* e)
|
||||||
{
|
{
|
||||||
// (void)e;
|
|
||||||
auto viewMain = ViewMain::instance();
|
auto viewMain = ViewMain::instance();
|
||||||
if (viewMain) {
|
if (viewMain) {
|
||||||
if (lv_event_get_code(e) == LV_EVENT_SCROLL_END) {
|
viewMain->updateTopbarVisibility();
|
||||||
auto view = viewMain->getCurrentMainView();
|
}
|
||||||
saveViewId(view);
|
}
|
||||||
} else {
|
|
||||||
viewMain->updateTopbarVisibility();
|
static void tile_view_scroll_end(lv_event_t* e)
|
||||||
}
|
{
|
||||||
|
auto viewMain = ViewMain::instance();
|
||||||
|
if (viewMain) {
|
||||||
|
auto view = viewMain->getCurrentMainView();
|
||||||
|
saveViewId(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +90,9 @@ ViewMain::ViewMain() :
|
|||||||
|
|
||||||
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_EVENT_BUBBLE);
|
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||||
lv_obj_set_user_data(tile_view, this);
|
lv_obj_set_user_data(tile_view, this);
|
||||||
|
lv_obj_add_event_cb(tile_view, tile_view_scroll_begin, LV_EVENT_SCROLL_BEGIN, NULL);
|
||||||
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL, nullptr);
|
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL, nullptr);
|
||||||
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL_END,
|
lv_obj_add_event_cb(tile_view, tile_view_scroll_end, LV_EVENT_SCROLL_END,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
// create last to be on top
|
// create last to be on top
|
||||||
|
|||||||
@@ -38,15 +38,13 @@ class ModelBitmapWidget : public Widget
|
|||||||
etx_obj_add_style(lvobj, styles->bg_opacity_cover,
|
etx_obj_add_style(lvobj, styles->bg_opacity_cover,
|
||||||
LV_PART_MAIN | ETX_STATE_BG_FILL);
|
LV_PART_MAIN | ETX_STATE_BG_FILL);
|
||||||
|
|
||||||
char s[LEN_MODEL_NAME + 1];
|
label = new StaticText(this, rect_t{}, "");
|
||||||
strAppend(s, g_model.header.name, LEN_MODEL_NAME);
|
|
||||||
label = new StaticText(this, rect_t{}, s);
|
|
||||||
label->hide();
|
label->hide();
|
||||||
|
|
||||||
image = new StaticImage(this, rect_t{0, 0, width(), height()});
|
image = new StaticBitmap(this, {0, 0, width(), height()});
|
||||||
image->hide();
|
image->hide();
|
||||||
|
|
||||||
update();
|
checkEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkEvents() override
|
void checkEvents() override
|
||||||
@@ -55,8 +53,6 @@ class ModelBitmapWidget : public Widget
|
|||||||
|
|
||||||
if (getHash() != deps_hash) {
|
if (getHash() != deps_hash) {
|
||||||
update();
|
update();
|
||||||
// Force bitmap redraw
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char s[LEN_MODEL_NAME + 1];
|
char s[LEN_MODEL_NAME + 1];
|
||||||
@@ -95,24 +91,28 @@ class ModelBitmapWidget : public Widget
|
|||||||
else
|
else
|
||||||
lv_obj_clear_state(lvobj, ETX_STATE_BG_FILL);
|
lv_obj_clear_state(lvobj, ETX_STATE_BG_FILL);
|
||||||
|
|
||||||
if (!image->hasImage() || deps_hash != getHash()) {
|
coord_t w = width();
|
||||||
|
coord_t h = height() - (isLarge ? LARGE_IMG_H : 0);
|
||||||
|
bool sizeChg = (w != image->width()) || (h != image->height());
|
||||||
|
|
||||||
|
if (sizeChg)
|
||||||
|
image->setRect({0, isLarge ? LARGE_IMG_H : 0, w, h});
|
||||||
|
|
||||||
|
if (!image->hasImage() || deps_hash != getHash() || sizeChg) {
|
||||||
if (g_model.header.bitmap[0]) {
|
if (g_model.header.bitmap[0]) {
|
||||||
char filename[LEN_BITMAP_NAME + 1];
|
char filename[LEN_BITMAP_NAME + 1];
|
||||||
strAppend(filename, g_model.header.bitmap, LEN_BITMAP_NAME);
|
strAppend(filename, g_model.header.bitmap, LEN_BITMAP_NAME);
|
||||||
std::string fullpath =
|
std::string fullpath =
|
||||||
std::string(BITMAPS_PATH PATH_SEPARATOR) + filename;
|
std::string(BITMAPS_PATH PATH_SEPARATOR) + filename;
|
||||||
|
|
||||||
image->setSource(fullpath);
|
image->setSource(fullpath.c_str());
|
||||||
} else {
|
} else {
|
||||||
image->clearSource();
|
image->clearSource();
|
||||||
}
|
}
|
||||||
deps_hash = getHash();
|
deps_hash = getHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
image->setRect(
|
|
||||||
{0, isLarge ? LARGE_IMG_H : 0, width(), height() - (isLarge ? LARGE_IMG_H : 0)});
|
|
||||||
image->show(image->hasImage());
|
image->show(image->hasImage());
|
||||||
image->setZoom();
|
|
||||||
|
|
||||||
label->show(isLarge || !image->hasImage());
|
label->show(isLarge || !image->hasImage());
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ class ModelBitmapWidget : public Widget
|
|||||||
bool isLarge = false;
|
bool isLarge = false;
|
||||||
uint32_t deps_hash = 0;
|
uint32_t deps_hash = 0;
|
||||||
StaticText* label = nullptr;
|
StaticText* label = nullptr;
|
||||||
StaticImage* image = nullptr;
|
StaticBitmap* image = nullptr;
|
||||||
|
|
||||||
uint32_t getHash() { return hash(g_model.header.bitmap, LEN_BITMAP_NAME); }
|
uint32_t getHash() { return hash(g_model.header.bitmap, LEN_BITMAP_NAME); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user