fix(color): Multiple fixes and improvements to switch and source popup menus (#4055)

* Fixes for switch and source select popup menus.
- Fix missing GV filter in source select
- Ensure all options are included in one of the filters
- Add misc filter to switch select (for TELE and ACT options)
- Show inverted and no-selection options when filter selected
- Make menu line height consistent.

* Fix selected item in list when filter applied.
This commit is contained in:
philmoz
2023-09-23 11:21:12 +10:00
committed by GitHub
parent c783f16b20
commit 55217dc303
8 changed files with 60 additions and 18 deletions
+22 -3
View File
@@ -40,20 +40,39 @@ class SourceChoiceMenuToolbar : public MenuToolbar
if (modelCustomScriptsEnabled()) if (modelCustomScriptsEnabled())
addButton(STR_CHAR_LUA, MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA); addButton(STR_CHAR_LUA, MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA);
#endif #endif
addButton(STR_CHAR_STICK, MIXSRC_FIRST_STICK, MIXSRC_LAST_STICK); #if defined(PCBHORUS)
auto lastSource = MIXSRC_LAST_SPACEMOUSE;
#elif defined(IMU)
auto lastSource = MIXSRC_TILT_Y;
#else
auto lastSource = MIXSRC_LAST_STICK;
#endif
addButton(STR_CHAR_STICK, MIXSRC_FIRST_STICK, lastSource, [=](int16_t index) {
if (index >= MIXSRC_FIRST_POT && index <= MIXSRC_LAST_POT)
return false;
#if MAX_AXIS > 0
if (index >= MIXSRC_FIRST_AXIS && index <= MIXSRC_LAST_AXIS)
return false;
#endif
return index >= MIXSRC_FIRST_STICK && index <= lastSource;
});
addButton(STR_CHAR_POT, MIXSRC_FIRST_POT, MIXSRC_LAST_POT); addButton(STR_CHAR_POT, MIXSRC_FIRST_POT, MIXSRC_LAST_POT);
addButton(STR_CHAR_FUNCTION, MIXSRC_MIN, MIXSRC_MAX); addButton(STR_CHAR_FUNCTION, MIXSRC_MIN, MIXSRC_LAST_TIMER, [=](int16_t index) {
return (index >= MIXSRC_MIN && index <= MIXSRC_MAX) || (index >= MIXSRC_TX_VOLTAGE && index <= MIXSRC_LAST_TIMER);
});
#if defined(HELI) #if defined(HELI)
if (modelHeliEnabled()) if (modelHeliEnabled())
addButton(STR_CHAR_CYC, MIXSRC_FIRST_HELI, MIXSRC_LAST_HELI); addButton(STR_CHAR_CYC, MIXSRC_FIRST_HELI, MIXSRC_LAST_HELI);
#endif #endif
addButton(STR_CHAR_TRIM, MIXSRC_FIRST_TRIM, MIXSRC_LAST_TRIM); addButton(STR_CHAR_TRIM, MIXSRC_FIRST_TRIM, MIXSRC_LAST_TRIM);
addButton(STR_CHAR_SWITCH, MIXSRC_FIRST_SWITCH, MIXSRC_LAST_SWITCH); addButton(STR_CHAR_SWITCH, MIXSRC_FIRST_SWITCH, MIXSRC_LAST_SWITCH);
if (modelLSEnabled())
addButton(STR_CHAR_SWITCH, MIXSRC_FIRST_LOGICAL_SWITCH, MIXSRC_LAST_LOGICAL_SWITCH);
addButton(STR_CHAR_TRAINER, MIXSRC_FIRST_TRAINER, MIXSRC_LAST_TRAINER); addButton(STR_CHAR_TRAINER, MIXSRC_FIRST_TRAINER, MIXSRC_LAST_TRAINER);
addButton(STR_CHAR_CHANNEL, MIXSRC_FIRST_CH, MIXSRC_LAST_CH); addButton(STR_CHAR_CHANNEL, MIXSRC_FIRST_CH, MIXSRC_LAST_CH);
#if defined(GVARS) #if defined(GVARS)
if (modelGVEnabled()) if (modelGVEnabled())
addButton(STR_CHAR_SLIDER, MIXSRC_LAST_GVAR, MIXSRC_FIRST_GVAR); addButton(STR_CHAR_SLIDER, MIXSRC_FIRST_GVAR, MIXSRC_LAST_GVAR);
#endif #endif
if (modelTelemetryEnabled()) if (modelTelemetryEnabled())
addButton(STR_CHAR_TELEMETRY, MIXSRC_FIRST_TELEM, MIXSRC_LAST_TELEM); addButton(STR_CHAR_TELEMETRY, MIXSRC_FIRST_TELEM, MIXSRC_LAST_TELEM);
+12 -3
View File
@@ -34,10 +34,19 @@ class SwitchChoiceMenuToolbar : public MenuToolbar
SwitchChoiceMenuToolbar(SwitchChoice* choice, Menu* menu) : SwitchChoiceMenuToolbar(SwitchChoice* choice, Menu* menu) :
MenuToolbar(choice, menu) MenuToolbar(choice, menu)
{ {
addButton(STR_CHAR_SWITCH, SWSRC_FIRST_SWITCH, SWSRC_LAST_SWITCH); addButton(STR_CHAR_SWITCH, SWSRC_FIRST_SWITCH, SWSRC_LAST_MULTIPOS_SWITCH);
addButton(STR_CHAR_TRIM, SWSRC_FIRST_TRIM, SWSRC_LAST_TRIM); addButton(STR_CHAR_TRIM, SWSRC_FIRST_TRIM, SWSRC_LAST_TRIM);
addButton(STR_CHAR_SWITCH, SWSRC_FIRST_LOGICAL_SWITCH, addButton(STR_CHAR_SWITCH, SWSRC_FIRST_LOGICAL_SWITCH, SWSRC_LAST_LOGICAL_SWITCH);
SWSRC_LAST_LOGICAL_SWITCH); addButton(STR_CHAR_TELEMETRY, SWSRC_FIRST_SENSOR, SWSRC_LAST_SENSOR);
#if defined(DEBUG_LATENCY)
auto lastSource = SWSRC_LATENCY_TOGGLE;
#else
auto lastSource = SWSRC_RADIO_ACTIVITY;
#endif
addButton(STR_CHAR_FUNCTION, SWSRC_TELEMETRY_STREAMING, lastSource, [=](int16_t index) {
index = abs(index);
return index == 0 || (index >= SWSRC_TELEMETRY_STREAMING && index <= lastSource && !(index >= SWSRC_FIRST_SENSOR && index <= SWSRC_LAST_SENSOR));
});
} }
}; };
@@ -511,6 +511,7 @@ void table_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
lv_obj_add_style(obj, &styles.pad_small, LV_PART_ITEMS); lv_obj_add_style(obj, &styles.pad_small, LV_PART_ITEMS);
lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED); lv_obj_add_style(obj, &styles.pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_EDITED); lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_ITEMS | LV_STATE_EDITED);
lv_obj_set_style_pad_ver(obj, 7, LV_PART_ITEMS);
} }
void etx_keyboard_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) void etx_keyboard_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
+2 -2
View File
@@ -32,9 +32,9 @@ constexpr uint32_t ALERT_MESSAGE_LEFT = ALERT_TITLE_LEFT;
constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 132; constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 132;
constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = INPUT_EDIT_CURVE_WIDTH; constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = INPUT_EDIT_CURVE_WIDTH;
constexpr coord_t MENUS_LINE_HEIGHT = 30; constexpr coord_t MENUS_LINE_HEIGHT = 35;
constexpr coord_t MENUS_WIDTH = 200; constexpr coord_t MENUS_WIDTH = 200;
constexpr coord_t MENUS_MAX_HEIGHT = LCD_H * 0.9; constexpr coord_t MENUS_MAX_HEIGHT = (MENUS_LINE_HEIGHT * 7);
constexpr rect_t MENUS_TOOLBAR_RECT = { 100, 51, 30, 209 }; constexpr rect_t MENUS_TOOLBAR_RECT = { 100, 51, 30, 209 };
+2 -2
View File
@@ -32,9 +32,9 @@ constexpr uint32_t ALERT_MESSAGE_LEFT = 15;
constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 176; constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 176;
constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = 132; constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = 132;
constexpr coord_t MENUS_LINE_HEIGHT = 40; constexpr coord_t MENUS_LINE_HEIGHT = 35;
constexpr coord_t MENUS_WIDTH = 200; constexpr coord_t MENUS_WIDTH = 200;
constexpr coord_t MENUS_MAX_HEIGHT = 7 * MENUS_LINE_HEIGHT - 1; constexpr coord_t MENUS_MAX_HEIGHT = (MENUS_LINE_HEIGHT * 10);
constexpr rect_t MENUS_TOOLBAR_RECT = { 35, (LCD_H - MENUS_MAX_HEIGHT) / 2, 50, MENUS_MAX_HEIGHT }; constexpr rect_t MENUS_TOOLBAR_RECT = { 35, (LCD_H - MENUS_MAX_HEIGHT) / 2, 50, MENUS_MAX_HEIGHT };
+12 -2
View File
@@ -194,9 +194,10 @@ void Choice::fillMenu(Menu *menu, const FilterFct& filter)
{ {
menu->removeLines(); menu->removeLines();
auto value = _getValue(); auto value = _getValue();
int count = 0; int count = 0;
int selectedIx = -1; int selectedIx = -1;
int selectedIx0 = -1;
for (int i = vmin; i <= vmax; ++i) { for (int i = vmin; i <= vmax; ++i) {
if (filter && !filter(i)) continue; if (filter && !filter(i)) continue;
if (isValueAvailable && !isValueAvailable(i)) continue; if (isValueAvailable && !isValueAvailable(i)) continue;
@@ -208,10 +209,19 @@ void Choice::fillMenu(Menu *menu, const FilterFct& filter)
menu->addLineBuffered(std::to_string(i), [=]() { setValue(i); }); menu->addLineBuffered(std::to_string(i), [=]() { setValue(i); });
} }
if (value == i) { selectedIx = count; } if (value == i) { selectedIx = count; }
if (i == 0) { selectedIx0 = count; }
++count; ++count;
} }
menu->updateLines(); menu->updateLines();
if (selectedIx >= 0) { menu->select(selectedIx); } // Force update - in case selected row is first row
menu->select(-1);
if (selectedIx >= 0)
menu->select(selectedIx);
else if (selectedIx0 >= 0)
menu->select(selectedIx0);
else {
menu->select(0);
}
} }
void Choice::openMenu() void Choice::openMenu()
+6 -4
View File
@@ -106,14 +106,16 @@ rect_t MenuToolbar::getButtonRect(size_t buttons)
} }
bool MenuToolbar::filterMenu(MenuToolbarButton* btn, int16_t filtermin, bool MenuToolbar::filterMenu(MenuToolbarButton* btn, int16_t filtermin,
int16_t filtermax) int16_t filtermax, const FilterFct& filterFunc)
{ {
btn->check(!btn->checked()); btn->check(!btn->checked());
Choice::FilterFct filter = nullptr; Choice::FilterFct filter = nullptr;
if (btn->checked()) { if (btn->checked()) {
filter = [=](int16_t index) { filter = [=](int16_t index) {
return index >= filtermin && index <= filtermax; if (filterFunc)
return filterFunc(index);
return index == 0 || (abs(index) >= filtermin && abs(index) <= filtermax);
}; };
} }
@@ -135,7 +137,7 @@ static int getFirstAvailable(int min, int max, IsValueAvailable isValueAvailable
} }
void MenuToolbar::addButton(const char* picto, int16_t filtermin, void MenuToolbar::addButton(const char* picto, int16_t filtermin,
int16_t filtermax) int16_t filtermax, const FilterFct& filterFunc)
{ {
int vmin = choice->vmin; int vmin = choice->vmin;
int vmax = choice->vmax; int vmax = choice->vmax;
@@ -150,7 +152,7 @@ void MenuToolbar::addButton(const char* picto, int16_t filtermin,
auto button = new MenuToolbarButton(this, r, picto); auto button = new MenuToolbarButton(this, r, picto);
button->setPressHandler( button->setPressHandler(
std::bind(&MenuToolbar::filterMenu, this, button, filtermin, filtermax)); std::bind(&MenuToolbar::filterMenu, this, button, filtermin, filtermax, filterFunc));
lv_group_add_obj(group, button->getLvObj()); lv_group_add_obj(group, button->getLvObj());
} }
+3 -2
View File
@@ -47,11 +47,12 @@ class MenuToolbar : public Window
protected: protected:
Choice* choice; Choice* choice;
Menu* menu; Menu* menu;
typedef std::function<bool(int16_t)> FilterFct;
lv_group_t* group; lv_group_t* group;
void addButton(const char* picto, int16_t filtermin, int16_t filtermax); void addButton(const char* picto, int16_t filtermin, int16_t filtermax, const FilterFct& filterFunc = nullptr);
bool filterMenu(MenuToolbarButton* btn, int16_t filtermin, int16_t filtermax); bool filterMenu(MenuToolbarButton* btn, int16_t filtermin, int16_t filtermax, const FilterFct& filterFunc = nullptr);
rect_t getButtonRect(size_t buttons); rect_t getButtonRect(size_t buttons);