Add sesitivty setter
This commit is contained in:
@@ -107,6 +107,7 @@ lv_obj_t * lv_rotary_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->max_value = copy_ext->max_value;
|
||||
ext->dragging = copy_ext->dragging;
|
||||
ext->sym = copy_ext->sym;
|
||||
ext->sensitivity = copy_ext->sensitivity;
|
||||
lv_style_list_copy(&ext->style_knob, ©_ext->style_knob);
|
||||
|
||||
lv_obj_refresh_style(rotary, LV_OBJ_PART_ALL);
|
||||
@@ -191,6 +192,20 @@ void lv_rotary_set_symmetric(lv_obj_t * rotary, bool en)
|
||||
lv_obj_invalidate(rotary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sesitivity of rotary knob increments
|
||||
* position.
|
||||
* @param rotary pointer to a rotary object
|
||||
* @param sensitivity increment multiplier
|
||||
*/
|
||||
void lv_rotary_set_sensitivity(lv_obj_t * rotary, uint16_t sensitivity)
|
||||
{
|
||||
LV_ASSERT_OBJ(rotary, LV_OBJX_NAME);
|
||||
|
||||
lv_rotary_ext_t *ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary);
|
||||
ext->sensitivity = sensitivity;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -321,13 +336,13 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par
|
||||
ext->last_drag_x = p.x;
|
||||
if (ext->knob_area.y1 < p.y && p.y < ext->knob_area.y2) {
|
||||
if (drag_x_diff > 0 && p.x < ext->knob_area.x2) {
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff, LV_ANIM_ON);
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON);
|
||||
res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
else if (drag_x_diff < 0 && p.x > ext->knob_area.x1) {
|
||||
ext->last_drag_x = p.x;
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff, LV_ANIM_ON);
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON);
|
||||
res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
@@ -352,12 +367,12 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par
|
||||
char c = *((char *)param);
|
||||
|
||||
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + 1, LV_ANIM_ON);
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + ext->sensitivity, LV_ANIM_ON);
|
||||
res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) - 1, LV_ANIM_ON);
|
||||
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) - ext->sensitivity, LV_ANIM_ON);
|
||||
res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
|
||||
@@ -67,9 +67,11 @@ typedef struct {
|
||||
int16_t cur_value; /*Current value of the rotary*/
|
||||
int16_t min_value; /*Minimum value of the rotary*/
|
||||
int16_t max_value; /*Maximum value of the rotary*/
|
||||
uint16_t dragging :1;
|
||||
lv_coord_t last_drag_x; /*Last drag x coordintate of the rotary*/
|
||||
uint16_t sym :1;
|
||||
uint16_t dragging :1;
|
||||
uint16_t sym :1;
|
||||
uint16_t sensitivity :1;
|
||||
|
||||
} lv_rotary_ext_t;
|
||||
|
||||
/** Built-in styles of rotary*/
|
||||
@@ -121,6 +123,14 @@ void lv_rotary_set_range(lv_obj_t * rotary, int16_t min, int16_t max);
|
||||
*/
|
||||
void lv_rotary_set_symmetric(lv_obj_t * rotary, bool en);
|
||||
|
||||
/**
|
||||
* Set the sesitivity of rotary knob increments
|
||||
* position.
|
||||
* @param rotary pointer to a rotary object
|
||||
* @param sensitivity increment multiplier
|
||||
*/
|
||||
void lv_rotary_set_sensitivity(lv_obj_t * rotary, uint16_t sensitivity);
|
||||
|
||||
/**
|
||||
* Set the start angle of rotary indicator. 0 deg: right, 90 bottom, etc.
|
||||
* @param arc pointer to an arc object
|
||||
|
||||
Reference in New Issue
Block a user