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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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<int16_t()> getValue,
|
||||
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));
|
||||
});
|
||||
|
||||
setLongPressHandler([=](event_t) {
|
||||
int16_t val = getValue();
|
||||
if (isValueAvailable && isValueAvailable(-val)) {
|
||||
setValue(-val);
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
set_lv_LongPressHandler(LongPressHandler, this);
|
||||
|
||||
setAvailableHandler(isSwitchAvailableInMixes);
|
||||
}
|
||||
|
||||
@@ -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<int16_t()> getValue,
|
||||
std::function<void(int16_t)> 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_
|
||||
|
||||
Vendored
+1
-1
Submodule radio/src/thirdparty/libopenui updated: dce24526ce...39134ce1fe
Reference in New Issue
Block a user