fix(slider): edit mode

This commit is contained in:
Raphael Coeffic
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent 6177a94486
commit 85e9f1d7ca
4 changed files with 18 additions and 63 deletions
+7 -12
View File
@@ -49,8 +49,11 @@ void FormField::setEditMode(bool newEditMode)
void FormField::onClicked() void FormField::onClicked()
{ {
setEditMode(!editMode); lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
invalidate(); if(indev_type != LV_INDEV_TYPE_POINTER) {
setEditMode(!editMode);
invalidate();
}
} }
void FormField::onCancel() void FormField::onCancel()
@@ -63,16 +66,8 @@ void FormField::onCancel()
} }
} }
FormGroup::Line::Line(FormGroup* parent, lv_obj_t* obj, FormGroup::Line::Line(Window* parent, lv_obj_t* obj, FlexGridLayout* layout) :
FlexGridLayout* layout) : Window(parent, obj), layout(layout)
Window(parent, obj), layout(layout), group(parent)
{
construct();
}
FormGroup::Line::Line(Window* parent, lv_obj_t* obj, FlexGridLayout* layout,
FormGroup* group) :
Window(parent, obj), layout(layout), group(group)
{ {
construct(); construct();
} }
+4 -5
View File
@@ -83,17 +83,16 @@ class FormGroup : public Window
public: public:
class Line : public Window class Line : public Window
{ {
FlexGridLayout* layout; FlexGridLayout *layout;
FormGroup* group; FormGroup *group;
void construct(); void construct();
public: public:
Line(FormGroup *parent, lv_obj_t *obj, FlexGridLayout* layout); Line(Window *parent, lv_obj_t *obj, FlexGridLayout *layout = nullptr);
Line(Window *parent, lv_obj_t *obj, FlexGridLayout* layout, FormGroup* group);
protected: protected:
void addChild(Window* window) override; void addChild(Window *window) override;
}; };
FormGroup(Window *parent, const rect_t &rect, WindowFlags windowflags = 0, FormGroup(Window *parent, const rect_t &rect, WindowFlags windowflags = 0,
+3 -35
View File
@@ -22,19 +22,14 @@
#include "LvglWrapper.h" #include "LvglWrapper.h"
static void slider_changed_cb(lv_event_t * e) static void slider_changed_cb(lv_event_t* e)
{ {
lv_obj_t * target = lv_event_get_target(e); lv_obj_t* target = lv_event_get_target(e);
auto code = lv_event_get_code(e); auto code = lv_event_get_code(e);
Slider* sl = (Slider*)lv_obj_get_user_data(target); Slider* sl = (Slider*)lv_obj_get_user_data(target);
if (code == LV_EVENT_VALUE_CHANGED) { if (code == LV_EVENT_VALUE_CHANGED) {
// if (!lv_slider_is_dragged(target)) { if (sl != nullptr) sl->setValue(lv_slider_get_value(target));
if (sl != nullptr)
sl->setValue(lv_slider_get_value(target));
// }
} else if (code == LV_EVENT_PRESSED) {
sl->setEditMode(true);
} }
} }
@@ -100,36 +95,9 @@ Slider::Slider(Window* parent, const rect_t& rect, int32_t vmin, int32_t vmax,
lv_obj_add_style(lvobj, &style_edit, LV_PART_KNOB | LV_STATE_FOCUSED | LV_STATE_EDITED); lv_obj_add_style(lvobj, &style_edit, LV_PART_KNOB | LV_STATE_FOCUSED | LV_STATE_EDITED);
} }
void Slider::paint(BitmapBuffer * dc)
{
}
int Slider::value(coord_t x) const int Slider::value(coord_t x) const
{ {
return vmin + ((vmax - vmin) * x + (rect.w / 2)) / rect.w; return vmin + ((vmax - vmin) * x + (rect.w / 2)) / rect.w;
} }
#if defined(HARDWARE_KEYS)
void Slider::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (editMode) {
if (event == EVT_ROTARY_RIGHT) {
setValue(_getValue() + ROTARY_ENCODER_SPEED());
lv_slider_set_value(lvobj, _getValue(), LV_ANIM_OFF);
onKeyPress();
return;
}
else if (event == EVT_ROTARY_LEFT) {
setValue(_getValue() - ROTARY_ENCODER_SPEED());
lv_slider_set_value(lvobj, _getValue(), LV_ANIM_OFF);
onKeyPress();
return;
} else if (event == EVT_KEY_FIRST(KEY_EXIT))
return;
}
FormField::onEvent(event);
}
#endif
+3 -10
View File
@@ -33,21 +33,14 @@ class Slider : public FormField
void setValue(int value) void setValue(int value)
{ {
if (_setValue != nullptr) if (_setValue != nullptr) _setValue(limit(vmin, value, vmax));
_setValue(limit(vmin, value, vmax));
} }
void paint(BitmapBuffer* dc) override;
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
#endif
protected: protected:
int value(coord_t x) const;
int vmin; int vmin;
int vmax; int vmax;
bool sliding = false;
std::function<int()> _getValue; std::function<int()> _getValue;
std::function<void(int)> _setValue; std::function<void(int)> _setValue;
int value(coord_t x) const;
}; };