fix: Re-add Switch and Curve long press functionality (#2332)

* Restore go to edit curve on lobg press from inputs tab.

* Restore long press functionaliy for switches SA_UP -> !SA_UP

* chore: Auto-formatting and bump libopenui

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
eshifri
2022-09-20 19:45:29 +10:00
committed by GitHub
co-authored by Peter Feerick
parent 07aa46d884
commit 7e540594fa
5 changed files with 56 additions and 46 deletions
+31 -30
View File
@@ -20,14 +20,22 @@
*/ */
#include "curve_param.h" #include "curve_param.h"
#include "gvar_numberedit.h" #include "gvar_numberedit.h"
#include "model_curves.h" #include "model_curves.h"
#include "opentx.h" #include "opentx.h"
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
static const char *_curve_type[] = {"Diff", "Expo", "Func", "Cstm"}; static const char* _curve_type[] = {"Diff", "Expo", "Func", "Cstm"};
void CurveParam::LongPressHandler(void* data)
{
int8_t* value = (int8_t*)data;
if (*value != 0) {
ModelCurvesPage::pushEditCurve(abs(*value) - 1);
}
}
void CurveParam::value_changed(lv_event_t* e) void CurveParam::value_changed(lv_event_t* e)
{ {
@@ -39,17 +47,15 @@ void CurveParam::value_changed(lv_event_t* e)
} }
CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref) : CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref) :
Window(parent, rect), Window(parent, rect), ref(ref)
ref(ref)
{ {
lv_obj_set_flex_flow(lvobj, LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_flex_flow(lvobj, LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_style_pad_column(lvobj, lv_dpx(4), 0); lv_obj_set_style_pad_column(lvobj, lv_dpx(4), 0);
lv_obj_set_style_flex_cross_place(lvobj, LV_FLEX_ALIGN_CENTER, 0); lv_obj_set_style_flex_cross_place(lvobj, LV_FLEX_ALIGN_CENTER, 0);
lv_obj_set_size(lvobj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); lv_obj_set_size(lvobj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
new Choice(this, rect_t{}, _curve_type, 0, new Choice(this, rect_t{}, _curve_type, 0, CURVE_REF_CUSTOM,
CURVE_REF_CUSTOM, GET_DEFAULT(ref->type), GET_DEFAULT(ref->type), [=](int32_t newValue) {
[=](int32_t newValue) {
ref->type = newValue; ref->type = newValue;
ref->value = 0; ref->value = 0;
SET_DIRTY(); SET_DIRTY();
@@ -68,15 +74,11 @@ CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref) :
func_choice = new Choice(this, rect_t{}, STR_VCURVEFUNC, 0, CURVE_BASE - 1, func_choice = new Choice(this, rect_t{}, STR_VCURVEFUNC, 0, CURVE_BASE - 1,
GET_SET_DEFAULT(ref->value)); GET_SET_DEFAULT(ref->value));
// CURVE_REF_CUSTOM // CURVE_REF_CUSTOM
cust_choice = new ChoiceEx(this, rect_t{}, -MAX_CURVES, MAX_CURVES, cust_choice = new ChoiceEx(this, rect_t{}, -MAX_CURVES, MAX_CURVES,
GET_SET_DEFAULT(ref->value)); GET_SET_DEFAULT(ref->value));
cust_choice->setTextHandler([](int value) { return getCurveString(value); }); cust_choice->setTextHandler([](int value) { return getCurveString(value); });
cust_choice->setLongPressHandler([ref](event_t event) { cust_choice->set_lv_LongPressHandler(LongPressHandler, &(ref->value));
// if no curve is specified then dont link to curve page
if (ref->value != 0) ModelCurvesPage::pushEditCurve(abs(ref->value) - 1);
});
update(); update();
} }
@@ -93,25 +95,25 @@ void CurveParam::update()
lv_obj_add_flag(func_obj, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(func_obj, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(cust_obj, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(cust_obj, LV_OBJ_FLAG_HIDDEN);
switch(ref->type) { switch (ref->type) {
case CURVE_REF_DIFF: case CURVE_REF_DIFF:
case CURVE_REF_EXPO: case CURVE_REF_EXPO:
lv_obj_clear_flag(value_obj, LV_OBJ_FLAG_HIDDEN); lv_obj_clear_flag(value_obj, LV_OBJ_FLAG_HIDDEN);
act_field = value_edit; act_field = value_edit;
break; break;
case CURVE_REF_FUNC: case CURVE_REF_FUNC:
lv_obj_clear_flag(func_obj, LV_OBJ_FLAG_HIDDEN); lv_obj_clear_flag(func_obj, LV_OBJ_FLAG_HIDDEN);
act_field = func_choice; act_field = func_choice;
break; break;
case CURVE_REF_CUSTOM: case CURVE_REF_CUSTOM:
lv_obj_clear_flag(cust_obj, LV_OBJ_FLAG_HIDDEN); lv_obj_clear_flag(cust_obj, LV_OBJ_FLAG_HIDDEN);
act_field = cust_choice; act_field = cust_choice;
break; break;
default: default:
return; return;
} }
auto act_obj = act_field->getLvObj(); auto act_obj = act_field->getLvObj();
@@ -120,4 +122,3 @@ void CurveParam::update()
} }
lv_event_send(act_obj, LV_EVENT_VALUE_CHANGED, nullptr); lv_event_send(act_obj, LV_EVENT_VALUE_CHANGED, nullptr);
} }
+2 -1
View File
@@ -43,7 +43,8 @@ class CurveParam : public Window
void update(); void update();
static void value_changed(lv_event_t* e); static void value_changed(lv_event_t* e);
static void LongPressHandler(void* data);
public: public:
CurveParam(Window* parent, const rect_t& rect, CurveRef* ref); CurveParam(Window* parent, const rect_t& rect, CurveRef* ref);
}; };
+12 -7
View File
@@ -41,6 +41,17 @@ class SwitchChoiceMenuToolbar : public MenuToolbar
} }
}; };
void SwitchChoice::LongPressHandler(void* data)
{
SwitchChoice* swch = (SwitchChoice*)data;
if (!swch) return;
int16_t val = swch->_getValue();
if (swch->isValueAvailable && swch->isValueAvailable(-val)) {
swch->setValue(-val);
swch->invalidate();
}
}
SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin, SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
int vmax, std::function<int16_t()> getValue, int vmax, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue) : std::function<void(int16_t)> setValue) :
@@ -78,13 +89,7 @@ SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
return std::string(getSwitchPositionName(value)); return std::string(getSwitchPositionName(value));
}); });
setLongPressHandler([=](event_t) { set_lv_LongPressHandler(LongPressHandler, this);
int16_t val = getValue();
if (isValueAvailable && isValueAvailable(-val)) {
setValue(-val);
invalidate();
}
});
setAvailableHandler(isSwitchAvailableInMixes); setAvailableHandler(isSwitchAvailableInMixes);
} }
+5 -2
View File
@@ -22,8 +22,8 @@
#ifndef _SWITCHCHOICE_H_ #ifndef _SWITCHCHOICE_H_
#define _SWITCHCHOICE_H_ #define _SWITCHCHOICE_H_
#include "form.h"
#include "choiceex.h" #include "choiceex.h"
#include "form.h"
class SwitchChoice : public ChoiceEx class SwitchChoice : public ChoiceEx
{ {
@@ -32,9 +32,12 @@ class SwitchChoice : public ChoiceEx
std::function<int16_t()> getValue, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue); std::function<void(int16_t)> setValue);
static void LongPressHandler(void* data);
protected:
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override { return "SwitchChoice"; } std::string getName() const override { return "SwitchChoice"; }
#endif #endif
}; };
#endif // _SWITCHCHOICE_H_ #endif // _SWITCHCHOICE_H_