fix(color): high CPU usage on several pages (#6174)

This commit is contained in:
philmoz
2025-05-02 10:01:59 +10:00
committed by GitHub
parent 031455773c
commit 3a1fde4336
8 changed files with 43 additions and 43 deletions
@@ -219,7 +219,6 @@ class FlightModeBtn : public ListLineButton
if (line) { if (line) {
if (!line->init) if (!line->init)
line->delayed_init(); line->delayed_init();
line->refresh();
} }
} }
@@ -257,6 +256,8 @@ class FlightModeBtn : public ListLineButton
lv_obj_enable_style_refresh(true); lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
refresh();
} }
bool isActive() const override { return (getFlightMode() == index); } bool isActive() const override { return (getFlightMode() == index); }
@@ -497,7 +498,7 @@ void ModelFlightModesPage::build(Window* form)
btn->setWidth(ListLineButton::GRP_W); btn->setWidth(ListLineButton::GRP_W);
btn->setPressHandler([=]() { btn->setPressHandler([=]() {
new FlightModeEdit(i); (new FlightModeEdit(i))->setCloseHandler([=]() { btn->refresh(); });
return 0; return 0;
}); });
} }
@@ -323,7 +323,6 @@ class LogicalSwitchButton : public ListLineButton
if (line) { if (line) {
if (!line->init) if (!line->init)
line->delayed_init(); line->delayed_init();
line->refresh();
} }
} }
@@ -377,6 +376,8 @@ class LogicalSwitchButton : public ListLineButton
lv_obj_enable_style_refresh(true); lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
refresh();
} }
bool isActive() const override bool isActive() const override
@@ -598,7 +599,7 @@ void ModelLogicalSwitchesPage::plusPopup(Window* window)
void ModelLogicalSwitchesPage::build(Window* window) void ModelLogicalSwitchesPage::build(Window* window)
{ {
window->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_TINY); window->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_OUTLINE);
bool hasEmptySwitch = false; bool hasEmptySwitch = false;
@@ -618,30 +619,27 @@ void ModelLogicalSwitchesPage::build(Window* window)
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT, [=]() {
Window* lsWindow = new LogicalSwitchEditPage(i); Window* lsWindow = new LogicalSwitchEditPage(i);
lsWindow->setCloseHandler([=]() { lsWindow->setCloseHandler([=]() {
if (!isActive) if (ls->func == LS_FUNC_NONE)
rebuild(window); rebuild(window);
else
button->refresh();
}); });
}); });
if (isActive) { menu->addLine(STR_COPY, [=]() {
menu->addLine(STR_COPY, [=]() { clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH;
clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH; clipboard.data.csw = *ls;
clipboard.data.csw = *ls; });
});
}
if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH)
menu->addLine(STR_PASTE, [=]() { menu->addLine(STR_PASTE, [=]() {
*ls = clipboard.data.csw; *ls = clipboard.data.csw;
storageDirty(EE_MODEL); storageDirty(EE_MODEL);
rebuild(window); rebuild(window);
}); });
if (isActive || ls->v1 || ls->v2 || ls->delay || ls->duration || menu->addLine(STR_CLEAR, [=]() {
ls->andsw) { memset(ls, 0, sizeof(LogicalSwitchData));
menu->addLine(STR_CLEAR, [=]() { storageDirty(EE_MODEL);
memset(ls, 0, sizeof(LogicalSwitchData)); rebuild(window);
storageDirty(EE_MODEL); });
rebuild(window);
});
}
return 0; return 0;
}); });
@@ -201,7 +201,6 @@ class ScriptLineButton : public ListLineButton
if (line) { if (line) {
if (!line->init) if (!line->init)
line->delayed_init(); line->delayed_init();
line->refresh();
} }
} }
@@ -259,6 +258,7 @@ class ScriptLineButton : public ListLineButton
} }
lv_obj_update_layout(lvobj); lv_obj_update_layout(lvobj);
refresh();
} }
bool isActive() const override { return false; } bool isActive() const override { return false; }
@@ -51,7 +51,6 @@ class OutputLineButton : public ListLineButton
if (line) { if (line) {
if (!line->init) if (!line->init)
line->delayed_init(); line->delayed_init();
line->refresh();
} }
} }
@@ -109,6 +108,8 @@ class OutputLineButton : public ListLineButton
lv_obj_enable_style_refresh(true); lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
refresh();
} }
public: public:
@@ -200,9 +201,10 @@ class OutputLineButton : public ListLineButton
void checkEvents() override void checkEvents() override
{ {
ListLineButton::checkEvents();
if (!init) return; if (!init) return;
ListLineButton::checkEvents();
int newValue = channelOutputs[index]; int newValue = channelOutputs[index];
if (value != newValue) { if (value != newValue) {
value = newValue; value = newValue;
@@ -386,7 +386,6 @@ class USBChannelLineButton : public ListLineButton
if (line) { if (line) {
if (!line->init) if (!line->init)
line->delayed_init(); line->delayed_init();
line->refresh();
} }
} }
@@ -427,6 +426,8 @@ class USBChannelLineButton : public ListLineButton
lv_label_set_text(m_param, ""); lv_label_set_text(m_param, "");
lv_label_set_text(m_btn_mode, ""); lv_label_set_text(m_btn_mode, "");
lv_label_set_text(m_btns, ""); lv_label_set_text(m_btns, "");
refresh();
} }
void refresh() override void refresh() override
@@ -591,5 +592,5 @@ void ModelUSBJoystickPage::editChannel(uint8_t channel,
USBChannelLineButton* btn) USBChannelLineButton* btn)
{ {
auto chedit = new USBChannelEditWindow(channel); auto chedit = new USBChannelEditWindow(channel);
chedit->setCloseHandler([=]() { this->update(); }); chedit->setCloseHandler([=]() { this->update(); btn->refresh(); });
} }
@@ -95,7 +95,6 @@ void FunctionLineButton::on_draw(lv_event_t *e)
if (line) { if (line) {
if (!line->init) if (!line->init)
line->delayed_init(); line->delayed_init();
line->refresh();
} }
} }
@@ -130,6 +129,8 @@ void FunctionLineButton::delayed_init()
lv_obj_enable_style_refresh(true); lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
refresh();
} }
void FunctionLineButton::refresh() void FunctionLineButton::refresh()
@@ -754,16 +755,19 @@ void FunctionsPage::pasteSpecialFunction(Window *window, uint8_t index,
} }
void FunctionsPage::editSpecialFunction(Window *window, uint8_t index, void FunctionsPage::editSpecialFunction(Window *window, uint8_t index,
ButtonBase *button) FunctionLineButton *button)
{ {
auto edit = editPage(index); auto edit = editPage(index);
edit->setCloseHandler([=]() { edit->setCloseHandler([=]() {
CustomFunctionData *cfn = customFunctionData(index); CustomFunctionData *cfn = customFunctionData(index);
if (cfn->swtch != 0) { if (cfn->swtch != 0) {
focusIndex = index; focusIndex = index;
if (!button) if (button) {
rebuild(window); button->refresh();
return; // Skip full rebuild
}
} }
rebuild(window);
}); });
} }
@@ -144,7 +144,7 @@ class FunctionsPage : public PageTab
void rebuild(Window* window); void rebuild(Window* window);
void newSF(Window* window, bool pasteSF); void newSF(Window* window, bool pasteSF);
void editSpecialFunction(Window* window, uint8_t index, void editSpecialFunction(Window* window, uint8_t index,
ButtonBase* button); FunctionLineButton* button);
void pasteSpecialFunction(Window* window, uint8_t index, void pasteSpecialFunction(Window* window, uint8_t index,
ButtonBase* button); ButtonBase* button);
void plusPopup(Window* window); void plusPopup(Window* window);
+8 -14
View File
@@ -51,12 +51,6 @@ class ChannelValue : public Window
lv_style_set_width(&style, lv_pct(100)); lv_style_set_width(&style, lv_pct(100));
lv_style_set_height(&style, lv_pct(100)); lv_style_set_height(&style, lv_pct(100));
// lv_color_t color;
// color.full = txtColor >> 16u;
// lv_style_set_text_color(&style, color);
// color.full = barColor >> 16u;
// lv_style_set_bg_color(&style, color);
bar = lv_obj_create(lvobj); bar = lv_obj_create(lvobj);
lv_obj_set_style_bg_opa(bar, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_bg_opa(bar, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_clear_flag(bar, LV_OBJ_FLAG_CLICKABLE); lv_obj_clear_flag(bar, LV_OBJ_FLAG_CLICKABLE);
@@ -104,8 +98,13 @@ class ChannelValue : public Window
void checkEvents() override void checkEvents() override
{ {
int16_t value = channelOutputs[channel]; int16_t value = channelOutputs[channel];
if (value != lastValue) {
lastValue = value; const int lim = (g_model.extendedLimits ? (1024 * LIMIT_EXT_PERCENT / 100) : 1024);
uint16_t w = width() - 2;
uint16_t fillW = divRoundClosest(w * limit<int16_t>(0, abs(value), lim), lim * 2);
if (fillW != lastValue) {
lastValue = fillW;
std::string s; std::string s;
if (g_eeGeneral.ppmunit == PPM_US) if (g_eeGeneral.ppmunit == PPM_US)
@@ -117,12 +116,7 @@ class ChannelValue : public Window
lv_label_set_text(valueLabel, s.c_str()); lv_label_set_text(valueLabel, s.c_str());
const int lim = (g_model.extendedLimits ? (1024 * LIMIT_EXT_PERCENT / 100) : 1024); uint16_t x = value > 0 ? w / 2 : w / 2 - fillW + 1;
uint16_t w = width() - 2;
uint16_t fillW = divRoundClosest(
w * limit<int16_t>(0, abs(lastValue), lim),
lim * 2);
uint16_t x = lastValue > 0 ? w / 2 : w / 2 - fillW + 1;
lv_obj_set_pos(bar, x, 0); lv_obj_set_pos(bar, x, 0);
lv_obj_set_size(bar, fillW, ROW_HEIGHT - 1); lv_obj_set_size(bar, fillW, ROW_HEIGHT - 1);