fix(color): Long press and filtering in Switch Choice popup (#4362)

This commit is contained in:
philmoz
2023-11-27 22:02:41 +10:00
committed by GitHub
parent 2c3686882c
commit 3971a70d26
4 changed files with 15 additions and 5 deletions
+10 -3
View File
@@ -76,13 +76,13 @@ class SwitchChoiceMenuToolbar : public MenuToolbar
invertBtn->setPressHandler([=]() { invertBtn->setPressHandler([=]() {
lv_obj_clear_state(invertBtn->getLvObj(), LV_STATE_FOCUSED); lv_obj_clear_state(invertBtn->getLvObj(), LV_STATE_FOCUSED);
longPress(); invertChoice();
return choice->inverted; return choice->inverted;
}); });
#endif #endif
} }
void longPress() void invertChoice()
{ {
SwitchChoice* switchChoice = (SwitchChoice*)choice; SwitchChoice* switchChoice = (SwitchChoice*)choice;
switchChoice->inverted = !switchChoice->inverted; switchChoice->inverted = !switchChoice->inverted;
@@ -94,6 +94,14 @@ class SwitchChoiceMenuToolbar : public MenuToolbar
#endif #endif
} }
void longPress()
{
lv_indev_t* indev = lv_indev_get_act();
if (indev->driver->type == LV_INDEV_TYPE_KEYPAD) {
invertChoice();
}
}
protected: protected:
MenuToolbarButton* invertBtn = nullptr; MenuToolbarButton* invertBtn = nullptr;
}; };
@@ -153,7 +161,6 @@ SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
val = swtch; val = swtch;
} }
if (val && (!isValueAvailable || isValueAvailable(val))) { if (val && (!isValueAvailable || isValueAvailable(val))) {
// if (filtered) fillMenu(menu);
tb->resetFilter(); tb->resetFilter();
menu->select(getIndexFromValue(val)); menu->select(getIndexFromValue(val));
} }
+2 -1
View File
@@ -39,12 +39,13 @@ class SwitchChoice : public Choice
protected: protected:
friend SwitchChoiceMenuToolbar; friend SwitchChoiceMenuToolbar;
bool inverted = false;
bool inMenu = false; bool inMenu = false;
void setValue(int value) override; void setValue(int value) override;
int getIntValue() const override; int getIntValue() const override;
void invertChoice();
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "SwitchChoice"; } std::string getName() const override { return "SwitchChoice"; }
#endif #endif
+1 -1
View File
@@ -201,7 +201,7 @@ void Choice::fillMenu(Menu* menu, const FilterFct& filter)
selectedIx0 = -1; 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(inverted ? -i : i)) continue;
if (textHandler) { if (textHandler) {
menu->addLineBuffered(textHandler(i), [=]() { setValue(i); }); menu->addLineBuffered(textHandler(i), [=]() { setValue(i); });
} else if (unsigned(i - vmin) < values.size()) { } else if (unsigned(i - vmin) < values.size()) {
+2
View File
@@ -181,6 +181,8 @@ class Choice : public ChoiceBase
protected: protected:
friend class MenuToolbar; friend class MenuToolbar;
bool inverted = false;
std::string getLabelText() override; std::string getLabelText() override;
std::vector<std::string> values; std::vector<std::string> values;
int vmin = 0; int vmin = 0;