diff --git a/radio/src/gui/colorlcd/model/model_flightmodes.cpp b/radio/src/gui/colorlcd/model/model_flightmodes.cpp index 981625fd8..269baf0ca 100644 --- a/radio/src/gui/colorlcd/model/model_flightmodes.cpp +++ b/radio/src/gui/colorlcd/model/model_flightmodes.cpp @@ -219,7 +219,6 @@ class FlightModeBtn : public ListLineButton if (line) { if (!line->init) line->delayed_init(); - line->refresh(); } } @@ -257,6 +256,8 @@ class FlightModeBtn : public ListLineButton lv_obj_enable_style_refresh(true); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); + + refresh(); } bool isActive() const override { return (getFlightMode() == index); } @@ -497,7 +498,7 @@ void ModelFlightModesPage::build(Window* form) btn->setWidth(ListLineButton::GRP_W); btn->setPressHandler([=]() { - new FlightModeEdit(i); + (new FlightModeEdit(i))->setCloseHandler([=]() { btn->refresh(); }); return 0; }); } diff --git a/radio/src/gui/colorlcd/model/model_logical_switches.cpp b/radio/src/gui/colorlcd/model/model_logical_switches.cpp index 0ed8bcb93..617fe578c 100644 --- a/radio/src/gui/colorlcd/model/model_logical_switches.cpp +++ b/radio/src/gui/colorlcd/model/model_logical_switches.cpp @@ -323,7 +323,6 @@ class LogicalSwitchButton : public ListLineButton if (line) { if (!line->init) line->delayed_init(); - line->refresh(); } } @@ -377,6 +376,8 @@ class LogicalSwitchButton : public ListLineButton lv_obj_enable_style_refresh(true); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); + + refresh(); } bool isActive() const override @@ -598,7 +599,7 @@ void ModelLogicalSwitchesPage::plusPopup(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; @@ -618,30 +619,27 @@ void ModelLogicalSwitchesPage::build(Window* window) menu->addLine(STR_EDIT, [=]() { Window* lsWindow = new LogicalSwitchEditPage(i); lsWindow->setCloseHandler([=]() { - if (!isActive) + if (ls->func == LS_FUNC_NONE) rebuild(window); + else + button->refresh(); }); }); - if (isActive) { - menu->addLine(STR_COPY, [=]() { - clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH; - clipboard.data.csw = *ls; - }); - } + menu->addLine(STR_COPY, [=]() { + clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH; + clipboard.data.csw = *ls; + }); if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH) menu->addLine(STR_PASTE, [=]() { *ls = clipboard.data.csw; storageDirty(EE_MODEL); rebuild(window); }); - if (isActive || ls->v1 || ls->v2 || ls->delay || ls->duration || - ls->andsw) { - menu->addLine(STR_CLEAR, [=]() { - memset(ls, 0, sizeof(LogicalSwitchData)); - storageDirty(EE_MODEL); - rebuild(window); - }); - } + menu->addLine(STR_CLEAR, [=]() { + memset(ls, 0, sizeof(LogicalSwitchData)); + storageDirty(EE_MODEL); + rebuild(window); + }); return 0; }); diff --git a/radio/src/gui/colorlcd/model/model_mixer_scripts.cpp b/radio/src/gui/colorlcd/model/model_mixer_scripts.cpp index ee7bd28fd..a72971f02 100644 --- a/radio/src/gui/colorlcd/model/model_mixer_scripts.cpp +++ b/radio/src/gui/colorlcd/model/model_mixer_scripts.cpp @@ -201,7 +201,6 @@ class ScriptLineButton : public ListLineButton if (line) { if (!line->init) line->delayed_init(); - line->refresh(); } } @@ -259,6 +258,7 @@ class ScriptLineButton : public ListLineButton } lv_obj_update_layout(lvobj); + refresh(); } bool isActive() const override { return false; } diff --git a/radio/src/gui/colorlcd/model/model_outputs.cpp b/radio/src/gui/colorlcd/model/model_outputs.cpp index 1089eb1c4..0a9244a5f 100644 --- a/radio/src/gui/colorlcd/model/model_outputs.cpp +++ b/radio/src/gui/colorlcd/model/model_outputs.cpp @@ -51,7 +51,6 @@ class OutputLineButton : public ListLineButton if (line) { if (!line->init) line->delayed_init(); - line->refresh(); } } @@ -109,6 +108,8 @@ class OutputLineButton : public ListLineButton lv_obj_enable_style_refresh(true); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); + + refresh(); } public: @@ -200,9 +201,10 @@ class OutputLineButton : public ListLineButton void checkEvents() override { - ListLineButton::checkEvents(); if (!init) return; + ListLineButton::checkEvents(); + int newValue = channelOutputs[index]; if (value != newValue) { value = newValue; diff --git a/radio/src/gui/colorlcd/model/model_usbjoystick.cpp b/radio/src/gui/colorlcd/model/model_usbjoystick.cpp index 2f13a0b79..5288ad16a 100644 --- a/radio/src/gui/colorlcd/model/model_usbjoystick.cpp +++ b/radio/src/gui/colorlcd/model/model_usbjoystick.cpp @@ -386,7 +386,6 @@ class USBChannelLineButton : public ListLineButton if (line) { if (!line->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_btn_mode, ""); lv_label_set_text(m_btns, ""); + + refresh(); } void refresh() override @@ -591,5 +592,5 @@ void ModelUSBJoystickPage::editChannel(uint8_t channel, USBChannelLineButton* btn) { auto chedit = new USBChannelEditWindow(channel); - chedit->setCloseHandler([=]() { this->update(); }); + chedit->setCloseHandler([=]() { this->update(); btn->refresh(); }); } diff --git a/radio/src/gui/colorlcd/model/special_functions.cpp b/radio/src/gui/colorlcd/model/special_functions.cpp index 4d22be075..96a692eb5 100644 --- a/radio/src/gui/colorlcd/model/special_functions.cpp +++ b/radio/src/gui/colorlcd/model/special_functions.cpp @@ -95,7 +95,6 @@ void FunctionLineButton::on_draw(lv_event_t *e) if (line) { if (!line->init) line->delayed_init(); - line->refresh(); } } @@ -130,6 +129,8 @@ void FunctionLineButton::delayed_init() lv_obj_enable_style_refresh(true); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); + + refresh(); } void FunctionLineButton::refresh() @@ -754,16 +755,19 @@ void FunctionsPage::pasteSpecialFunction(Window *window, uint8_t index, } void FunctionsPage::editSpecialFunction(Window *window, uint8_t index, - ButtonBase *button) + FunctionLineButton *button) { auto edit = editPage(index); edit->setCloseHandler([=]() { CustomFunctionData *cfn = customFunctionData(index); if (cfn->swtch != 0) { focusIndex = index; - if (!button) - rebuild(window); + if (button) { + button->refresh(); + return; // Skip full rebuild + } } + rebuild(window); }); } diff --git a/radio/src/gui/colorlcd/model/special_functions.h b/radio/src/gui/colorlcd/model/special_functions.h index 3c245c456..b727cb6e7 100644 --- a/radio/src/gui/colorlcd/model/special_functions.h +++ b/radio/src/gui/colorlcd/model/special_functions.h @@ -144,7 +144,7 @@ class FunctionsPage : public PageTab void rebuild(Window* window); void newSF(Window* window, bool pasteSF); void editSpecialFunction(Window* window, uint8_t index, - ButtonBase* button); + FunctionLineButton* button); void pasteSpecialFunction(Window* window, uint8_t index, ButtonBase* button); void plusPopup(Window* window); diff --git a/radio/src/gui/colorlcd/widgets/outputs.cpp b/radio/src/gui/colorlcd/widgets/outputs.cpp index 084154d6c..28b9a98d2 100644 --- a/radio/src/gui/colorlcd/widgets/outputs.cpp +++ b/radio/src/gui/colorlcd/widgets/outputs.cpp @@ -51,12 +51,6 @@ class ChannelValue : public Window lv_style_set_width(&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); lv_obj_set_style_bg_opa(bar, LV_OPA_COVER, LV_PART_MAIN); lv_obj_clear_flag(bar, LV_OBJ_FLAG_CLICKABLE); @@ -104,8 +98,13 @@ class ChannelValue : public Window void checkEvents() override { 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(0, abs(value), lim), lim * 2); + + if (fillW != lastValue) { + lastValue = fillW; std::string s; if (g_eeGeneral.ppmunit == PPM_US) @@ -117,12 +116,7 @@ class ChannelValue : public Window lv_label_set_text(valueLabel, s.c_str()); - const int lim = (g_model.extendedLimits ? (1024 * LIMIT_EXT_PERCENT / 100) : 1024); - uint16_t w = width() - 2; - uint16_t fillW = divRoundClosest( - w * limit(0, abs(lastValue), lim), - lim * 2); - uint16_t x = lastValue > 0 ? w / 2 : w / 2 - fillW + 1; + uint16_t x = value > 0 ? w / 2 : w / 2 - fillW + 1; lv_obj_set_pos(bar, x, 0); lv_obj_set_size(bar, fillW, ROW_HEIGHT - 1);