diff --git a/radio/src/gui/colorlcd/curve_param.cpp b/radio/src/gui/colorlcd/curve_param.cpp index 34d983c9a..023f3f10b 100644 --- a/radio/src/gui/colorlcd/curve_param.cpp +++ b/radio/src/gui/colorlcd/curve_param.cpp @@ -20,14 +20,22 @@ */ #include "curve_param.h" + #include "gvar_numberedit.h" #include "model_curves.h" - #include "opentx.h" #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) { @@ -39,17 +47,15 @@ void CurveParam::value_changed(lv_event_t* e) } CurveParam::CurveParam(Window* parent, const rect_t& rect, CurveRef* ref) : - Window(parent, rect), - ref(ref) + Window(parent, rect), ref(ref) { 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_flex_cross_place(lvobj, LV_FLEX_ALIGN_CENTER, 0); lv_obj_set_size(lvobj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); - - new Choice(this, rect_t{}, _curve_type, 0, - CURVE_REF_CUSTOM, GET_DEFAULT(ref->type), - [=](int32_t newValue) { + + new Choice(this, rect_t{}, _curve_type, 0, CURVE_REF_CUSTOM, + GET_DEFAULT(ref->type), [=](int32_t newValue) { ref->type = newValue; ref->value = 0; 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, GET_SET_DEFAULT(ref->value)); - // CURVE_REF_CUSTOM 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->setLongPressHandler([ref](event_t event) { - // if no curve is specified then dont link to curve page - if (ref->value != 0) ModelCurvesPage::pushEditCurve(abs(ref->value) - 1); - }); + cust_choice->set_lv_LongPressHandler(LongPressHandler, &(ref->value)); update(); } @@ -88,30 +90,30 @@ void CurveParam::update() auto value_obj = value_edit->getLvObj(); auto func_obj = func_choice->getLvObj(); auto cust_obj = cust_choice->getLvObj(); - + lv_obj_add_flag(value_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); - - switch(ref->type) { - case CURVE_REF_DIFF: - case CURVE_REF_EXPO: - lv_obj_clear_flag(value_obj, LV_OBJ_FLAG_HIDDEN); - act_field = value_edit; - break; - case CURVE_REF_FUNC: - lv_obj_clear_flag(func_obj, LV_OBJ_FLAG_HIDDEN); - act_field = func_choice; - break; - - case CURVE_REF_CUSTOM: - lv_obj_clear_flag(cust_obj, LV_OBJ_FLAG_HIDDEN); - act_field = cust_choice; - break; + switch (ref->type) { + case CURVE_REF_DIFF: + case CURVE_REF_EXPO: + lv_obj_clear_flag(value_obj, LV_OBJ_FLAG_HIDDEN); + act_field = value_edit; + break; - default: - return; + case CURVE_REF_FUNC: + lv_obj_clear_flag(func_obj, LV_OBJ_FLAG_HIDDEN); + act_field = func_choice; + break; + + case CURVE_REF_CUSTOM: + lv_obj_clear_flag(cust_obj, LV_OBJ_FLAG_HIDDEN); + act_field = cust_choice; + break; + + default: + return; } auto act_obj = act_field->getLvObj(); @@ -120,4 +122,3 @@ void CurveParam::update() } lv_event_send(act_obj, LV_EVENT_VALUE_CHANGED, nullptr); } - diff --git a/radio/src/gui/colorlcd/curve_param.h b/radio/src/gui/colorlcd/curve_param.h index c6d8e7ace..e58b288f8 100644 --- a/radio/src/gui/colorlcd/curve_param.h +++ b/radio/src/gui/colorlcd/curve_param.h @@ -43,7 +43,8 @@ class CurveParam : public Window void update(); static void value_changed(lv_event_t* e); - -public: + static void LongPressHandler(void* data); + + public: CurveParam(Window* parent, const rect_t& rect, CurveRef* ref); }; diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index e19bf8ae8..bff752614 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -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, int vmax, std::function getValue, std::function setValue) : @@ -78,13 +89,7 @@ SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin, return std::string(getSwitchPositionName(value)); }); - setLongPressHandler([=](event_t) { - int16_t val = getValue(); - if (isValueAvailable && isValueAvailable(-val)) { - setValue(-val); - invalidate(); - } - }); + set_lv_LongPressHandler(LongPressHandler, this); setAvailableHandler(isSwitchAvailableInMixes); } diff --git a/radio/src/gui/colorlcd/switchchoice.h b/radio/src/gui/colorlcd/switchchoice.h index f2584de53..016778461 100644 --- a/radio/src/gui/colorlcd/switchchoice.h +++ b/radio/src/gui/colorlcd/switchchoice.h @@ -22,8 +22,8 @@ #ifndef _SWITCHCHOICE_H_ #define _SWITCHCHOICE_H_ -#include "form.h" #include "choiceex.h" +#include "form.h" class SwitchChoice : public ChoiceEx { @@ -32,9 +32,12 @@ class SwitchChoice : public ChoiceEx std::function getValue, std::function setValue); + static void LongPressHandler(void* data); + + protected: #if defined(DEBUG_WINDOWS) std::string getName() const override { return "SwitchChoice"; } #endif }; -#endif // _SWITCHCHOICE_H_ +#endif // _SWITCHCHOICE_H_ diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index dce24526c..39134ce1f 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit dce24526ce242947c58ad92b4cc38c8a3f645b40 +Subproject commit 39134ce1feb24fd350eed0ca7408a17a9bcaafa9