fix(color): slow scrolling on model select page (#5184)

This commit is contained in:
philmoz
2024-06-17 09:02:18 +10:00
committed by GitHub
parent 12031c44c2
commit e5bf5f8226
7 changed files with 74 additions and 56 deletions
+1 -1
View File
@@ -22,7 +22,7 @@
#include "file_preview.h" #include "file_preview.h"
FilePreview::FilePreview(Window *parent, const rect_t &rect) : FilePreview::FilePreview(Window *parent, const rect_t &rect) :
StaticBitmap(parent, rect, COLOR_THEME_SECONDARY3) StaticBitmap(parent, rect)
{ {
hide(); hide();
} }
+53 -20
View File
@@ -68,18 +68,12 @@ class ModelButton : public Button
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
check(modelCell == modelslist.getCurrentModel());
lv_obj_add_event_cb(lvobj, ModelButton::on_draw, LV_EVENT_DRAW_MAIN_BEGIN, lv_obj_add_event_cb(lvobj, ModelButton::on_draw, LV_EVENT_DRAW_MAIN_BEGIN,
nullptr); nullptr);
} }
void addDetails() void addDetails()
{ {
int bg_col_idx = modelCell == modelslist.getCurrentModel()
? COLOR_THEME_ACTIVE_INDEX
: COLOR_THEME_PRIMARY2_INDEX;
coord_t w = width() - PAD_SMALL * 2; coord_t w = width() - PAD_SMALL * 2;
LcdFlags font = modelLayouts[layout].font; LcdFlags font = modelLayouts[layout].font;
@@ -93,17 +87,18 @@ class ModelButton : public Button
coord_t fh = getFontHeight(font) - ((font == FONT(STD)) ? 4 : (font == FONT(XS)) ? 3 : 1); 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; coord_t fo = (font == FONT(STD)) ? -3 : (font == FONT(XS)) ? -3 : -1;
auto name = new StaticText(this, {PAD_TINY, PAD_TINY, w, fh}, modelCell->modelName, modelName = 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); etx_bg_color(modelName->getLvObj(), COLOR_THEME_ACTIVE_INDEX, LV_STATE_USER_1);
etx_bg_color(name->getLvObj(), (LcdColorIndex)bg_col_idx); etx_obj_add_style(modelName->getLvObj(), styles->bg_opacity_75, LV_STATE_USER_1);
etx_obj_add_style(name->getLvObj(), styles->bg_opacity_75, LV_PART_MAIN); modelName->padTop(fo);
name->padTop(fo);
} else { } else {
auto name = new StaticText(this, {PAD_TINY, PAD_SMALL, w, EdgeTxStyles::PAGE_LINE_HEIGHT}, modelCell->modelName, modelName = 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(modelName->getLvObj(), LV_LABEL_LONG_DOT);
checkEvents();
lv_obj_update_layout(lvobj); lv_obj_update_layout(lvobj);
} }
@@ -142,7 +137,7 @@ class ModelButton : public Button
if (modelLayouts[layout].hasImage) { if (modelLayouts[layout].hasImage) {
if (modelCell->modelBitmap[0]) { if (modelCell->modelBitmap[0]) {
GET_FILENAME(filename, BITMAPS_PATH, modelCell->modelBitmap, ""); GET_FILENAME(filename, BITMAPS_PATH, modelCell->modelBitmap, "");
auto bitmap = new StaticImage(this, {PAD_TINY, PAD_TINY, w, h}, filename, false, true); auto bitmap = new StaticBitmap(this, {PAD_TINY, PAD_TINY, w, h}, filename);
lv_obj_move_background(bitmap->getLvObj()); lv_obj_move_background(bitmap->getLvObj());
bitmap->show(bitmap->hasImage()); bitmap->show(bitmap->hasImage());
if (bitmap->hasImage()) { if (bitmap->hasImage()) {
@@ -158,11 +153,15 @@ class ModelButton : public Button
return false; return false;
} }
bool isModel(ModelCell* cell) { return cell == modelCell; }
protected: protected:
bool loaded = false; bool loaded = false;
bool imgLoaded = false; bool imgLoaded = false;
uint8_t layout; uint8_t layout;
ModelCell *modelCell; ModelCell *modelCell;
StaticText* modelName = nullptr;
std::function<void()> m_setSelected = nullptr; std::function<void()> m_setSelected = nullptr;
void showNoImgMsg() void showNoImgMsg()
@@ -177,6 +176,18 @@ class ModelButton : public Button
CENTERED | COLOR_THEME_SECONDARY1 | font); CENTERED | COLOR_THEME_SECONDARY1 | font);
} }
void checkEvents() override
{
bool chk = (modelCell == modelslist.getCurrentModel());
if (chk != checked()) {
check(chk);
if (chk)
lv_obj_add_state(modelName->getLvObj(), LV_STATE_USER_1);
else
lv_obj_clear_state(modelName->getLvObj(), LV_STATE_USER_1);
}
}
void onClicked() override void onClicked() override
{ {
setFocused(); setFocused();
@@ -197,7 +208,8 @@ class ModelsPageBody : public Window
void update() void update()
{ {
clear(); for (auto b : modelButtons)
b->hide();
ModelsVector models; ModelsVector models;
if (selectedLabels.size()) { if (selectedLabels.size()) {
@@ -224,9 +236,22 @@ class ModelsPageBody : public Window
coord_t y = (n / cols) * (h + PAD_TINY); coord_t y = (n / cols) * (h + PAD_TINY);
n += 1; n += 1;
auto button = new ModelButton( ModelButton* button = nullptr;
this, {x, y, w, h}, model, [=]() { focusedModel = model; }, for (auto b : modelButtons)
g_eeGeneral.modelSelectLayout); if (b->isModel(model)) {
button = b;
break;
}
if (button) {
button->setPos(x, y);
button->show();
lv_obj_move_foreground(button->getLvObj());
} else {
button = new ModelButton(
this, {x, y, w, h}, model, [=]() { focusedModel = model; },
g_eeGeneral.modelSelectLayout);
modelButtons.push_back(button);
}
if (!firstButton) firstButton = button; if (!firstButton) firstButton = button;
if (model == modelslist.getCurrentModel()) focusedButton = button; if (model == modelslist.getCurrentModel()) focusedButton = button;
@@ -242,7 +267,7 @@ class ModelsPageBody : public Window
} else { } else {
focusedModel = model; focusedModel = model;
} }
return 0; return model == modelslist.getCurrentModel();
}); });
// Long Press Handler for Models // Long Press Handler for Models
@@ -262,6 +287,13 @@ class ModelsPageBody : public Window
} }
} }
void reload()
{
modelButtons.clear();
clear();
update();
}
void setLabels(LabelsVector labels) void setLabels(LabelsVector labels)
{ {
selectedLabels = labels; selectedLabels = labels;
@@ -288,6 +320,7 @@ class ModelsPageBody : public Window
std::string selectedLabel; std::string selectedLabel;
LabelsVector selectedLabels; LabelsVector selectedLabels;
ModelCell *focusedModel = nullptr; ModelCell *focusedModel = nullptr;
std::vector<ModelButton*> modelButtons;
std::function<void()> refreshLabels = nullptr; std::function<void()> refreshLabels = nullptr;
void checkEvents() override void checkEvents() override
@@ -670,7 +703,7 @@ void ModelLabelsWindow::buildHead(Window *hdr)
mdlLayout->setLayout(l); mdlLayout->setLayout(l);
g_eeGeneral.modelSelectLayout = l; g_eeGeneral.modelSelectLayout = l;
storageDirty(EE_GENERAL); storageDirty(EE_GENERAL);
mdlselector->update(); mdlselector->reload();
return 0; return 0;
}); });
} }
+13 -18
View File
@@ -498,13 +498,15 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char *s,
// Resize and convert to LVGL image data format with alpha blending to // Resize and convert to LVGL image data format with alpha blending to
// background color // background color
void BitmapBuffer::resizeToLVGL(coord_t w, coord_t h, LcdFlags bgColor) void BitmapBuffer::resizeToLVGL(coord_t w, coord_t h)
{ {
// Scale values from ARGB4444 to RGB565 // Scale values from ARGB4444 to RGB565 with alpha
static uint8_t rbcnv[16] = {0, 2, 4, 6, 8, 10, 12, 14, static uint8_t rbcnv[16] = {0, 2, 4, 6, 8, 10, 12, 14,
17, 19, 21, 23, 25, 27, 29, 31}; 17, 19, 21, 23, 25, 27, 29, 31};
static uint8_t gcnv[16] = {0, 4, 8, 13, 17, 21, 25, 29, static uint8_t gcnv[16] = {0, 4, 8, 13, 17, 21, 25, 29,
34, 38, 42, 46, 50, 55, 59, 63}; 34, 38, 42, 46, 50, 55, 59, 63};
static uint8_t alpha[16] = {0, 17, 34, 51, 68, 85, 102, 119,
136, 153, 170, 187, 204, 221, 238, 255};
float vscale = float(h) / (float)height(); float vscale = float(h) / (float)height();
float hscale = float(w) / (float)width(); float hscale = float(w) / (float)width();
@@ -520,33 +522,26 @@ void BitmapBuffer::resizeToLVGL(coord_t w, coord_t h, LcdFlags bgColor)
scaledh = height() * scale; scaledh = height() * scale;
} }
pixel_t *ndata = uint8_t *ndata =
(pixel_t *)malloc(align32(scaledw * scaledh * sizeof(pixel_t))); (uint8_t *)malloc(align32(scaledw * scaledh * 3));
if (ndata) { if (ndata) {
RGB_SPLIT(COLOR_VAL(bgColor), bgRed, bgGreen, bgBlue); uint8_t *dst = ndata;
for (int i = 0; i < scaledh; i += 1) { for (int i = 0; i < scaledh; i += 1) {
pixel_t *dst = &ndata[i * scaledw];
pixel_t *src = &data[(coord_t)(i / scale) * width()]; pixel_t *src = &data[(coord_t)(i / scale) * width()];
for (int j = 0; j < scaledw; j += 1) { for (int j = 0; j < scaledw; j += 1) {
ARGB_SPLIT(src[(coord_t)(j / scale)], a, r, g, b); ARGB_SPLIT(src[(coord_t)(j / scale)], a, r, g, b);
r = rbcnv[r]; auto c = RGB_JOIN(rbcnv[r], gcnv[g], rbcnv[b]);
g = gcnv[g]; *dst++ = c & 0xFF;
b = rbcnv[b]; *dst++ = c >> 8;
if (a != OPACITY_MAX) { *dst++ = alpha[a];
uint8_t bgWeight = OPACITY_MAX - a;
r = (bgRed * bgWeight + r * a) / OPACITY_MAX;
g = (bgGreen * bgWeight + g * a) / OPACITY_MAX;
b = (bgBlue * bgWeight + b * a) / OPACITY_MAX;
}
*dst++ = RGB_JOIN(r, g, b);
} }
} }
delete data; delete data;
data = ndata; data = (pixel_t*)ndata;
_width = scaledw; _width = scaledw;
_height = scaledh; _height = scaledh;
data_end = data + (scaledw * scaledh); data_end = data + ((scaledw * scaledh * 3 + 1) / 2);
} }
} }
+1 -1
View File
@@ -140,7 +140,7 @@ class BitmapBuffer
static BitmapBuffer* loadBitmap(const char* filename, static BitmapBuffer* loadBitmap(const char* filename,
BitmapFormats fmt = BMP_INVALID); BitmapFormats fmt = BMP_INVALID);
void resizeToLVGL(coord_t w, coord_t h, LcdFlags bgColor); void resizeToLVGL(coord_t w, coord_t h);
uint8_t* to8bitMask(size_t* size) const; uint8_t* to8bitMask(size_t* size) const;
+1 -10
View File
@@ -95,8 +95,6 @@ const stbi_io_callbacks stbCallbacks = {stbc_read, stbc_skip, stbc_eof};
BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt) BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
{ {
// TRACE(" BitmapBuffer::load_stb(%s)", filename);
FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ); FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) { if (result != FR_OK) {
return nullptr; return nullptr;
@@ -104,14 +102,7 @@ BitmapBuffer *BitmapBuffer::loadBitmap(const char *filename, BitmapFormats fmt)
int x, y, nn; int x, y, nn;
stbi_info_from_callbacks(&stbCallbacks, &imgFile, &x, &y, &nn); stbi_info_from_callbacks(&stbCallbacks, &imgFile, &x, &y, &nn);
f_close(&imgFile); f_lseek(&imgFile, 0);
// TRACE(" BitmapBuffer::load_stb()----Info File %s, %d, %d, %d", filename,
// x, y, nn);
result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) {
return nullptr;
}
int w, h, n; int w, h, n;
unsigned char *img = unsigned char *img =
+4 -4
View File
@@ -245,8 +245,8 @@ void StaticImage::setZoom()
// Display image from file system with software scaling // Display image from file system with software scaling
// - uglier but much faster than LVGL scaling // - uglier but much faster than LVGL scaling
StaticBitmap::StaticBitmap(Window* parent, const rect_t& rect, StaticBitmap::StaticBitmap(Window* parent, const rect_t& rect,
LcdFlags bgColor, const char* filename) : const char* filename) :
Window(parent, rect), bgColor(bgColor) Window(parent, rect)
{ {
setWindowFlag(NO_FOCUS); setWindowFlag(NO_FOCUS);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE); lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
@@ -260,12 +260,12 @@ void StaticBitmap::setSource(const char *filename)
if (img) delete img; if (img) delete img;
img = BitmapBuffer::loadBitmap(filename, BMP_ARGB4444); img = BitmapBuffer::loadBitmap(filename, BMP_ARGB4444);
if (img) { if (img) {
img->resizeToLVGL(width(), height(), bgColor); img->resizeToLVGL(width(), height());
if (canvas) lv_obj_del(canvas); if (canvas) lv_obj_del(canvas);
canvas = lv_canvas_create(lvobj); canvas = lv_canvas_create(lvobj);
lv_obj_center(canvas); lv_obj_center(canvas);
lv_canvas_set_buffer(canvas, img->getData(), img->width(), img->height(), lv_canvas_set_buffer(canvas, img->getData(), img->width(), img->height(),
LV_IMG_CF_TRUE_COLOR); LV_IMG_CF_TRUE_COLOR_ALPHA);
} }
} }
} }
+1 -2
View File
@@ -163,7 +163,7 @@ class StaticBitmap : public Window
{ {
public: public:
StaticBitmap(Window *parent, const rect_t &rect, StaticBitmap(Window *parent, const rect_t &rect,
LcdFlags bgColor, const char *filename = nullptr); const char *filename = nullptr);
~StaticBitmap(); ~StaticBitmap();
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
@@ -174,7 +174,6 @@ class StaticBitmap : public Window
bool hasImage() const; bool hasImage() const;
protected: protected:
LcdFlags bgColor;
lv_obj_t *canvas = nullptr; lv_obj_t *canvas = nullptr;
BitmapBuffer *img = nullptr; BitmapBuffer *img = nullptr;
}; };