diff --git a/radio/src/gui/colorlcd/libui/textedit.cpp b/radio/src/gui/colorlcd/libui/textedit.cpp index 1d128237e..2c8bf0006 100644 --- a/radio/src/gui/colorlcd/libui/textedit.cpp +++ b/radio/src/gui/colorlcd/libui/textedit.cpp @@ -178,15 +178,18 @@ void TextEdit::preview(bool edited, char* text, uint8_t length) } ModelTextEdit::ModelTextEdit(Window* parent, const rect_t& rect, char* value, - uint8_t length) : + uint8_t length, std::function updateHandler) : TextEdit(parent, rect, value, length, - []() { storageDirty(EE_MODEL); }) + [=]() { + if (updateHandler) updateHandler(); + storageDirty(EE_MODEL); + }) { } RadioTextEdit::RadioTextEdit(Window* parent, const rect_t& rect, char* value, uint8_t length) : TextEdit(parent, rect, value, length, - []() { storageDirty(EE_GENERAL); }) + []() { storageDirty(EE_GENERAL); }) { } diff --git a/radio/src/gui/colorlcd/libui/textedit.h b/radio/src/gui/colorlcd/libui/textedit.h index 55e69f9fa..706f64b15 100644 --- a/radio/src/gui/colorlcd/libui/textedit.h +++ b/radio/src/gui/colorlcd/libui/textedit.h @@ -27,7 +27,7 @@ class TextEdit : public TextButton { public: TextEdit(Window* parent, const rect_t& rect, char* text, uint8_t length, - std::function updateHandler = nullptr); + std::function updateHandler = nullptr); #if defined(DEBUG_WINDOWS) std::string getName() const override { return "TextEdit \"" + text + "\""; } @@ -51,7 +51,7 @@ class ModelTextEdit : public TextEdit { public: ModelTextEdit(Window* parent, const rect_t& rect, char* value, - uint8_t length); + uint8_t length, std::function updateHandler = nullptr); }; class RadioTextEdit : public TextEdit diff --git a/radio/src/gui/colorlcd/model/input_edit.cpp b/radio/src/gui/colorlcd/model/input_edit.cpp index 01299c881..9f3270063 100644 --- a/radio/src/gui/colorlcd/model/input_edit.cpp +++ b/radio/src/gui/colorlcd/model/input_edit.cpp @@ -36,9 +36,16 @@ InputEditWindow::InputEditWindow(int8_t input, uint8_t index) : Page(ICON_MODEL_INPUTS), input(input), index(index) { - std::string title2(getSourceString(MIXSRC_FIRST_INPUT + input)); header->setTitle(STR_MENUINPUTS); - header->setTitle2(title2); + headerSwitchName = header->setTitle2(""); + + etx_txt_color(headerSwitchName->getLvObj(), COLOR_THEME_ACTIVE_INDEX, + LV_STATE_USER_1); + etx_font(headerSwitchName->getLvObj(), FONT_BOLD_INDEX, LV_STATE_USER_1); + + active = !isActive(); + + setTitle(); auto body_obj = body->getLvObj(); #if PORTRAIT_LCD // portrait @@ -75,6 +82,17 @@ InputEditWindow::InputEditWindow(int8_t input, uint8_t index) : CurveEdit::SetCurrentSource(expoAddress(index)->srcRaw); } +bool InputEditWindow::isActive() +{ + ExpoData* input = expoAddress(index); + return getSwitch(input->swtch); +} + +void InputEditWindow::setTitle() +{ + headerSwitchName->setText(getSourceString(MIXSRC_FIRST_INPUT + input)); +} + static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; @@ -88,9 +106,12 @@ void InputEditWindow::buildBody(Window* form) // Input Name auto line = form->newLine(grid); - auto inputName = g_model.inputNames[input->chn]; new StaticText(line, rect_t{}, STR_INPUTNAME); - new ModelTextEdit(line, rect_t{}, inputName, LEN_INPUT_NAME); + new ModelTextEdit(line, rect_t{}, g_model.inputNames[input->chn], + LEN_INPUT_NAME, + [=]() { + setTitle(); + }); // Line Name line = form->newLine(grid); @@ -110,7 +131,7 @@ void InputEditWindow::buildBody(Window* form) new SourceNumberEdit(line, -100, 100, GET_DEFAULT(input->weight), [=](int32_t newValue) { input->weight = newValue; - preview->update(); + updatePreview = true; SET_DIRTY(); }, MIXSRC_FIRST); gvar->setSuffix("%"); @@ -121,7 +142,7 @@ void InputEditWindow::buildBody(Window* form) gvar = new SourceNumberEdit(line, -100, 100, GET_DEFAULT(input->offset), [=](int32_t newValue) { input->offset = newValue; - preview->update(); + updatePreview = true; SET_DIRTY(); }, MIXSRC_FIRST); gvar->setSuffix("%"); @@ -130,7 +151,12 @@ void InputEditWindow::buildBody(Window* form) line = form->newLine(grid); new StaticText(line, rect_t{}, STR_SWITCH); new SwitchChoice(line, rect_t{}, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, - GET_SET_DEFAULT(input->swtch)); + GET_DEFAULT(input->swtch), + [=](int newValue) { + input->swtch = newValue; + updatePreview = true; + SET_DIRTY(); + }); // Curve line = form->newLine(grid); @@ -139,13 +165,11 @@ void InputEditWindow::buildBody(Window* form) new CurveParam(line, rect_t{}, &input->curve, [=](int32_t newValue) { input->curve.value = newValue; - if (preview) - preview->update(); + updatePreview = true; SET_DIRTY(); }, MIXSRC_FIRST, [=]() { - if (preview) - preview->update(); + updatePreview = true; }); lv_obj_set_style_grid_cell_x_align(param->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); @@ -172,7 +196,6 @@ void InputEditWindow::checkEvents() { ExpoData* input = expoAddress(index); - bool updatePreview = false; getvalue_t val; SourceNumVal v; @@ -203,8 +226,26 @@ void InputEditWindow::checkEvents() } } - if (updatePreview) - preview->update(); + bool sw = getSwitch(input->swtch); + if (sw != lastSwitchState) { + updatePreview = true; + lastSwitchState = sw; + } + + if (updatePreview) { + updatePreview = false; + if (preview) preview->update(); + } + + bool act = isActive(); + if (active != act) { + active = act; + if (active) { + lv_obj_add_state(headerSwitchName->getLvObj(), LV_STATE_USER_1); + } else { + lv_obj_clear_state(headerSwitchName->getLvObj(), LV_STATE_USER_1); + } + } Page::checkEvents(); } diff --git a/radio/src/gui/colorlcd/model/input_edit.h b/radio/src/gui/colorlcd/model/input_edit.h index 2349f53de..210799bed 100644 --- a/radio/src/gui/colorlcd/model/input_edit.h +++ b/radio/src/gui/colorlcd/model/input_edit.h @@ -39,12 +39,18 @@ class InputEditWindow : public Page uint8_t input; uint8_t index; Curve* preview = nullptr; + bool updatePreview = false; getvalue_t lastWeightVal = 0; getvalue_t lastOffsetVal = 0; getvalue_t lastCurveVal = 0; + bool lastSwitchState = false; + bool active = false; + StaticText * headerSwitchName = nullptr; + void setTitle(); void buildBody(Window *window); + bool isActive(); void checkEvents() override; void deleteLater(bool detach = true, bool trash = true) override; }; diff --git a/radio/src/gui/colorlcd/model/model_setup.cpp b/radio/src/gui/colorlcd/model/model_setup.cpp index fea59d407..38e9b9a70 100644 --- a/radio/src/gui/colorlcd/model/model_setup.cpp +++ b/radio/src/gui/colorlcd/model/model_setup.cpp @@ -58,21 +58,6 @@ ModelSetupPage::ModelSetupPage() : { } -struct ModelNameEdit : public ModelTextEdit { - ModelNameEdit(Window *parent, const rect_t &rect) : - ModelTextEdit(parent, rect, g_model.header.name, - sizeof(g_model.header.name)) - { - setChangeHandler([=]() { - auto model = modelslist.getCurrentModel(); - if (model) { - model->setModelName(g_model.header.name); - } - SET_DIRTY(); - }); - } -}; - static void viewOption(Window* parent, coord_t x, coord_t y, std::function getValue, std::function setValue, bool globalState) @@ -297,7 +282,15 @@ static SetupLineDef setupLines[] = { // Model name STR_MODELNAME, [](Window* parent, coord_t x, coord_t y) { - new ModelNameEdit(parent, {x, y, ModelSetupPage::NAM_W, 0}); + new ModelTextEdit(parent, {x, y, ModelSetupPage::NAM_W, 0}, + g_model.header.name, sizeof(g_model.header.name), + [=]() { + auto model = modelslist.getCurrentModel(); + if (model) { + model->setModelName(g_model.header.name); + } + SET_DIRTY(); + }); } }, {