diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index 7796ab5fd..4009139db 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -165,6 +165,11 @@ PACK(struct CustomFunctionData { }) clear); }); uint8_t active; + + bool isEmpty() const + { + return swtch == 0; + } }); /* diff --git a/radio/src/gui/colorlcd/model_curves.cpp b/radio/src/gui/colorlcd/model_curves.cpp index 13938195b..d1609d4e8 100644 --- a/radio/src/gui/colorlcd/model_curves.cpp +++ b/radio/src/gui/colorlcd/model_curves.cpp @@ -55,7 +55,7 @@ class CurveEditWindow : public Page { int8_t * points = curveAddress(index); // Curve editor - curveEdit = new CurveEdit(window, { LCD_W - curveWidth - PAGE_PADDING, PAGE_PADDING, curveWidth, curveWidth}, index); + curveEdit = new CurveEdit(window, { coord_t(LCD_W - curveWidth - PAGE_PADDING), PAGE_PADDING, curveWidth, curveWidth}, index); FormGridLayout grid; grid.setLabelWidth(PAGE_PADDING); diff --git a/radio/src/gui/colorlcd/model_logical_switches.cpp b/radio/src/gui/colorlcd/model_logical_switches.cpp index 1fd785844..07b8acbd0 100644 --- a/radio/src/gui/colorlcd/model_logical_switches.cpp +++ b/radio/src/gui/colorlcd/model_logical_switches.cpp @@ -237,8 +237,8 @@ static constexpr coord_t col3 = ((LCD_W - 100) / 3) * 2 + col1; class LogicalSwitchButton : public Button { public: - LogicalSwitchButton(Window * parent, const rect_t & rect, int lsIndex, std::function onPress): - Button(parent, rect, onPress), + LogicalSwitchButton(Window * parent, const rect_t & rect, int lsIndex): + Button(parent, rect), lsIndex(lsIndex), active(isActive()) { @@ -351,7 +351,7 @@ void ModelLogicalSwitchesPage::build(FormWindow * window, int8_t focusIndex) grid.spacer(PAGE_PADDING); grid.setLabelWidth(66); - for (uint8_t i=0; ifunc == LS_FUNC_NONE) { auto button = new TextButton(window, grid.getLabelSlot(), getSwitchPositionName(SWSRC_SW1+i)); @@ -363,32 +363,34 @@ void ModelLogicalSwitchesPage::build(FormWindow * window, int8_t focusIndex) } else { new StaticText(window, grid.getLabelSlot(), getSwitchPositionName(SWSRC_SW1 + i), BUTTON_BACKGROUND | CENTERED); - Button * button = new LogicalSwitchButton(window, grid.getFieldSlot(), i, - [=]() { - Menu * menu = new Menu(); - LogicalSwitchData * ls = lswAddress(i); - menu->addLine(STR_EDIT, [=]() { - editLogicalSwitch(window, i); - }); - if (ls->func) - 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, i); - }); - if (ls->func || ls->v1 || ls->v2 || ls->delay || ls->duration || ls->andsw) - menu->addLine(STR_CLEAR, [=]() { - memset(ls, 0, sizeof(LogicalSwitchData)); - storageDirty(EE_MODEL); - rebuild(window, i); - }); - return 0; - }); + + auto button = new LogicalSwitchButton(window, grid.getFieldSlot(), i); + button->setPressHandler([=]() { + Menu * menu = new Menu(); + LogicalSwitchData * ls = lswAddress(i); + menu->addLine(STR_EDIT, [=]() { + editLogicalSwitch(window, i); + }); + if (ls->func) + 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, i); + }); + if (ls->func || ls->v1 || ls->v2 || ls->delay || ls->duration || ls->andsw) + menu->addLine(STR_CLEAR, [=]() { + memset(ls, 0, sizeof(LogicalSwitchData)); + storageDirty(EE_MODEL); + rebuild(window, i); + }); + return 0; + }); + if (focusIndex == i) { button->setFocus(); } diff --git a/radio/src/gui/colorlcd/radio_sdmanager.cpp b/radio/src/gui/colorlcd/radio_sdmanager.cpp index 2684cbdaa..1eb32e855 100644 --- a/radio/src/gui/colorlcd/radio_sdmanager.cpp +++ b/radio/src/gui/colorlcd/radio_sdmanager.cpp @@ -156,7 +156,7 @@ void RadioSdManagerPage::build(FormWindow *window) files.sort(compare_nocase); for (auto name: directories) { - auto button = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t { + new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t { f_chdir(name.data()); window->clear(); build(window); diff --git a/radio/src/gui/colorlcd/special_functions.cpp b/radio/src/gui/colorlcd/special_functions.cpp index bdff2017c..62b8b6fe4 100644 --- a/radio/src/gui/colorlcd/special_functions.cpp +++ b/radio/src/gui/colorlcd/special_functions.cpp @@ -256,7 +256,7 @@ class SpecialFunctionButton : public Button { { const CustomFunctionData * cfn = &functions[index]; uint8_t func = CFN_FUNC(cfn); - if (!CFN_EMPTY(cfn) && + if (!cfn->isEmpty() && (HAS_ENABLE_PARAM(func) || HAS_REPEAT_PARAM(func) || (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC || func == FUNC_PLAY_SCRIPT))) { setHeight(getHeight() + 20); } @@ -292,7 +292,7 @@ class SpecialFunctionButton : public Button { uint8_t func = CFN_FUNC(cfn); drawSwitch(dc, col1, line1, CFN_SWITCH(cfn), 0); - if (CFN_EMPTY(cfn)) + if (cfn->isEmpty()) return; dc->drawTextAtIndex(col2, line1, STR_VFSWFUNC, func, 0); @@ -421,7 +421,7 @@ void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex) Window::clearFocus(); - char s[5] = "SF"; + char s[] = "SFxx"; if (functions == g_eeGeneral.customFn) s[0] = 'G'; @@ -429,71 +429,73 @@ void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex) for (uint8_t i = 0; i < MAX_SPECIAL_FUNCTIONS; i++) { CustomFunctionData * cfn = &functions[i]; - strAppendUnsigned(&s[2], i); - new StaticText(window, grid.getLabelSlot(), s, BUTTON_BACKGROUND | CENTERED); - Button * button = new SpecialFunctionButton(window, grid.getFieldSlot(), functions, i); - if (i == 0) - first = button; - - if (focusIndex == i) - button->setFocus(); - - button->setPressHandler([=]() -> uint8_t { - button->bringToTop(); - Menu * menu = new Menu(); - #warning "TODO When only EDIT available => directy open the edit window without the menu" - menu->addLine(STR_EDIT, [=]() { - editSpecialFunction(window, i); + if (cfn->swtch == 0) { + auto button = new TextButton(window, grid.getLabelSlot(), s); + button->setPressHandler([=]() { + editSpecialFunction(window, i); + return 0; }); - if (!CFN_EMPTY(cfn)) { - menu->addLine(STR_COPY, [=]() { - clipboard.type = CLIPBOARD_TYPE_CUSTOM_FUNCTION; - clipboard.data.cfn = *cfn; - }); - } - if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_FUNCTION) { - menu->addLine(STR_PASTE, [=]() { - *cfn = clipboard.data.cfn; - SET_DIRTY(); - rebuild(window, i); - }); - } - if (!CFN_EMPTY(cfn) && CFN_EMPTY(&functions[MAX_SPECIAL_FUNCTIONS - 1])) { - menu->addLine(STR_INSERT, [=]() { - memmove(cfn + 1, cfn, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData)); - memset(cfn, 0, sizeof(CustomFunctionData)); - SET_DIRTY(); - rebuild(window, i); - }); - } - if (!CFN_EMPTY(cfn)) { - menu->addLine(STR_CLEAR, [=]() { - memset(cfn, 0, sizeof(CustomFunctionData)); - SET_DIRTY(); - }); - } - for (int j = i; j < MAX_SPECIAL_FUNCTIONS; j++) { - if (!CFN_EMPTY(&functions[j])) { - menu->addLine(STR_DELETE, [=]() { - memmove(cfn, cfn + 1, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData)); - memset(&functions[MAX_SPECIAL_FUNCTIONS - 1], 0, sizeof(CustomFunctionData)); - SET_DIRTY(); - rebuild(window, i); + grid.spacer(button->height() + 5); + } + else { + new StaticText(window, grid.getLabelSlot(), s, BUTTON_BACKGROUND | CENTERED); + + auto button = new SpecialFunctionButton(window, grid.getFieldSlot(), functions, i); + button->setPressHandler([=]() { + button->bringToTop(); + Menu * menu = new Menu(); + menu->addLine(STR_EDIT, [=]() { + editSpecialFunction(window, i); }); - break; - } + menu->addLine(STR_COPY, [=]() { + clipboard.type = CLIPBOARD_TYPE_CUSTOM_FUNCTION; + clipboard.data.cfn = *cfn; + }); + if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_FUNCTION) { + menu->addLine(STR_PASTE, [=]() { + *cfn = clipboard.data.cfn; + SET_DIRTY(); + rebuild(window, i); + }); + } + if (functions[MAX_SPECIAL_FUNCTIONS - 1].isEmpty()) { + menu->addLine(STR_INSERT, [=]() { + memmove(cfn + 1, cfn, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData)); + memset(cfn, 0, sizeof(CustomFunctionData)); + SET_DIRTY(); + rebuild(window, i); + }); + } + menu->addLine(STR_CLEAR, [=]() { + memset(cfn, 0, sizeof(CustomFunctionData)); + SET_DIRTY(); + }); + for (int j = i; j < MAX_SPECIAL_FUNCTIONS; j++) { + if (!functions[j].isEmpty()) { + menu->addLine(STR_DELETE, [=]() { + memmove(cfn, cfn + 1, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData)); + memset(&functions[MAX_SPECIAL_FUNCTIONS - 1], 0, sizeof(CustomFunctionData)); + SET_DIRTY(); + rebuild(window, i); + }); + break; + } + } + return 0; + }); + + if (focusIndex == i) { + button->setFocus(); } - return 0; - }); - grid.spacer(button->height() + 5); + grid.spacer(button->height() + 5); + } } - FormField::link(FormField::getCurrentField(), first); - grid.nextLine(); + window->setLastField(); window->setInnerHeight(grid.getWindowHeight()); } diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index 50eb0980b..8d71d3f25 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit 50eb0980b37ffef097ef4fe6c8a27e1f694c2e55 +Subproject commit 8d71d3f25bbf5eb06b687cee2fbacf8f6bc37391