long press or long touch open selection menu on the inverted switch
This commit is contained in:
@@ -120,7 +120,11 @@ void SwitchChoice::onEvent(event_t event)
|
||||
{
|
||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
||||
|
||||
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
int16_t val = getValue();
|
||||
setValue(-val);
|
||||
}
|
||||
else if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
editMode = true;
|
||||
invalidate();
|
||||
openMenu();
|
||||
@@ -132,11 +136,28 @@ void SwitchChoice::onEvent(event_t event)
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool SwitchChoice::onTouchEnd(coord_t, coord_t)
|
||||
bool SwitchChoice::onTouchStart(coord_t x, coord_t y)
|
||||
{
|
||||
if (!duration10ms) {
|
||||
duration10ms = get_tmr10ms();
|
||||
}
|
||||
return FormField::onTouchStart(x, y);
|
||||
}
|
||||
|
||||
bool SwitchChoice::onTouchEnd(coord_t x, coord_t y)
|
||||
{
|
||||
setFocus(SET_FOCUS_DEFAULT);
|
||||
|
||||
touchDuration10ms = get_tmr10ms() - duration10ms;
|
||||
duration10ms = 0;
|
||||
if (isLongPress()) {
|
||||
int16_t val = getValue();
|
||||
setValue(-val);
|
||||
}
|
||||
|
||||
setEditMode(true);
|
||||
openMenu();
|
||||
return true;
|
||||
|
||||
return true; // FormField::onTouchEnd(x, y);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "form.h"
|
||||
|
||||
constexpr int LONG_PRESS_10MS = 100;
|
||||
|
||||
class Menu;
|
||||
bool isSwitchAvailableInMixes(int swtch);
|
||||
|
||||
@@ -41,6 +43,10 @@ class SwitchChoice : public FormField
|
||||
getValue(std::move(getValue)),
|
||||
setValue(std::move(setValue))
|
||||
{
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
duration10ms = 0;
|
||||
touchDuration10ms = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
@@ -55,8 +61,14 @@ class SwitchChoice : public FormField
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
bool onTouchStart(coord_t x, coord_t y) override;
|
||||
inline bool isLongPress(tmr10ms_t longPressDuration = LONG_PRESS_10MS)
|
||||
{
|
||||
return (touchDuration10ms > longPressDuration) ? true : false;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
void setAvailableHandler(std::function<bool(int)> handler)
|
||||
{
|
||||
isValueAvailable = std::move(handler);
|
||||
@@ -65,6 +77,10 @@ class SwitchChoice : public FormField
|
||||
protected:
|
||||
int16_t vmin;
|
||||
int16_t vmax;
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
tmr10ms_t duration10ms;
|
||||
tmr10ms_t touchDuration10ms;
|
||||
#endif
|
||||
std::function<int16_t()> getValue;
|
||||
std::function<void(int16_t)> setValue;
|
||||
std::function<bool(int)> isValueAvailable = isSwitchAvailableInMixes;
|
||||
|
||||
Reference in New Issue
Block a user