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:
+12
-2
@@ -194,9 +194,10 @@ void Choice::fillMenu(Menu *menu, const FilterFct& filter)
|
||||
{
|
||||
menu->removeLines();
|
||||
auto value = _getValue();
|
||||
|
||||
|
||||
int count = 0;
|
||||
int selectedIx = -1;
|
||||
int selectedIx0 = -1;
|
||||
for (int i = vmin; i <= vmax; ++i) {
|
||||
if (filter && !filter(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); });
|
||||
}
|
||||
if (value == i) { selectedIx = count; }
|
||||
if (i == 0) { selectedIx0 = count; }
|
||||
++count;
|
||||
}
|
||||
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()
|
||||
|
||||
+6
-4
@@ -106,14 +106,16 @@ rect_t MenuToolbar::getButtonRect(size_t buttons)
|
||||
}
|
||||
|
||||
bool MenuToolbar::filterMenu(MenuToolbarButton* btn, int16_t filtermin,
|
||||
int16_t filtermax)
|
||||
int16_t filtermax, const FilterFct& filterFunc)
|
||||
{
|
||||
btn->check(!btn->checked());
|
||||
|
||||
Choice::FilterFct filter = nullptr;
|
||||
if (btn->checked()) {
|
||||
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,
|
||||
int16_t filtermax)
|
||||
int16_t filtermax, const FilterFct& filterFunc)
|
||||
{
|
||||
int vmin = choice->vmin;
|
||||
int vmax = choice->vmax;
|
||||
@@ -150,7 +152,7 @@ void MenuToolbar::addButton(const char* picto, int16_t filtermin,
|
||||
auto button = new MenuToolbarButton(this, r, picto);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
+3
-2
@@ -47,11 +47,12 @@ class MenuToolbar : public Window
|
||||
protected:
|
||||
Choice* choice;
|
||||
Menu* menu;
|
||||
typedef std::function<bool(int16_t)> FilterFct;
|
||||
|
||||
lv_group_t* group;
|
||||
|
||||
void addButton(const char* picto, int16_t filtermin, int16_t filtermax);
|
||||
bool filterMenu(MenuToolbarButton* btn, 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, const FilterFct& filterFunc = nullptr);
|
||||
|
||||
rect_t getButtonRect(size_t buttons);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user