feat(radio): sort global/special function names (#5429)

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
philmoz
2024-08-23 11:57:05 +10:00
committed by GitHub
co-authored by Peter Feerick
parent 2ef014db0f
commit e0a3097620
11 changed files with 973 additions and 47 deletions
@@ -150,6 +150,11 @@ void onCustomFunctionsMenu(const char * result)
}
#endif // PCBTARANIS
static bool isAssignableFunctionAvailableSorted(int value)
{
return isAssignableFunctionAvailable(cfn_sorted[value]);
}
void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomFunctionsContext * functionsContext)
{
int8_t sub = menuVerticalPosition - HEADER_LINE;
@@ -215,7 +220,7 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
if (CFN_SWITCH(cfn)) {
lcdDrawText(MODEL_SPECIAL_FUNC_2ND_COLUMN, y, funcGetLabel(func), attr);
if (active) {
CFN_FUNC(cfn) = checkIncDec(event, CFN_FUNC(cfn), 0, FUNC_MAX-1, eeFlags, isAssignableFunctionAvailable);
CFN_FUNC(cfn) = cfn_sorted[checkIncDec(event, getFuncSortIdx(CFN_FUNC(cfn)), 0, FUNC_MAX-1, eeFlags, isAssignableFunctionAvailableSorted)];
if (checkIncDec_Ret) CFN_RESET(cfn);
}
}
@@ -155,6 +155,11 @@ enum CustomFunctionsItems {
ITEM_CUSTOM_FUNCTIONS_LAST = ITEM_CUSTOM_FUNCTIONS_COUNT - 1
};
static bool isAssignableFunctionAvailableSorted(int value)
{
return isAssignableFunctionAvailable(cfn_sorted[value]);
}
void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomFunctionsContext * functionsContext)
{
int sub = menuVerticalPosition;
@@ -207,7 +212,7 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
if (CFN_SWITCH(cfn)) {
lcdDrawText(MODEL_SPECIAL_FUNC_2ND_COLUMN, y, funcGetLabel(func), attr);
if (active) {
func = CFN_FUNC(cfn) = checkIncDec(event, CFN_FUNC(cfn), 0, FUNC_MAX-1, eeFlags, isAssignableFunctionAvailable);
func = CFN_FUNC(cfn) = cfn_sorted[checkIncDec(event, getFuncSortIdx(CFN_FUNC(cfn)), 0, FUNC_MAX-1, eeFlags, isAssignableFunctionAvailableSorted)];
if (checkIncDec_Ret) CFN_RESET(cfn);
}
}
@@ -652,16 +652,16 @@ void FunctionEditPage::buildBody(Window *form)
line = form->newLine(grid);
new StaticText(line, rect_t{}, STR_FUNC);
auto functionChoice =
new Choice(line, rect_t{}, 0, FUNC_MAX - 1, GET_DEFAULT(CFN_FUNC(cfn)));
functionChoice->setTextHandler([=](int val) { return funcGetLabel(val); });
new Choice(line, rect_t{}, 0, FUNC_MAX - 1, GET_DEFAULT(getFuncSortIdx(CFN_FUNC(cfn))));
functionChoice->setTextHandler([=](int val) { return funcGetLabel(cfn_sorted[val]); });
functionChoice->setSetValueHandler([=](int32_t newValue) {
CFN_FUNC(cfn) = newValue;
CFN_FUNC(cfn) = cfn_sorted[newValue];
CFN_RESET(cfn);
SET_DIRTY();
updateSpecialFunctionOneWindow();
});
functionChoice->setAvailableHandler(
[=](int value) { return isAssignableFunctionAvailable(value); });
[=](int value) { return isAssignableFunctionAvailable(cfn_sorted[value]); });
specialFunctionOneWindow = new Window(form, rect_t{});
updateSpecialFunctionOneWindow();
+9
View File
@@ -593,6 +593,15 @@ bool isAssignableFunctionAvailable(int function, bool modelFunctions)
#if !defined(VIDEO_SWITCH)
case FUNC_LCD_TO_VIDEO:
return false;
#endif
#if !defined(DEBUG)
case FUNC_TEST:
return false;
#endif
#if !defined(COLORLCD)
case FUNC_DISABLE_TOUCH:
case FUNC_SET_SCREEN:
return false;
#endif
default:
return true;