1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

Send event on if the value really does change

This commit is contained in:
Adam Martini 2020-06-25 23:05:48 -07:00
parent 7ce9a969c8
commit 8bcbceef08
2 changed files with 22 additions and 16 deletions

View File

@ -166,18 +166,18 @@ void lv_rotary_set_type(lv_obj_t * rotary, lv_rotary_type_t type)
* @param value new value * @param value new value
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
*/ */
void lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim) bool lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim)
{ {
LV_ASSERT_OBJ(rotary, LV_OBJX_NAME); LV_ASSERT_OBJ(rotary, LV_OBJX_NAME);
lv_rotary_ext_t * ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary); lv_rotary_ext_t * ext = (lv_rotary_ext_t *)lv_obj_get_ext_attr(rotary);
if(ext->cur_value == value) return; if(ext->cur_value == value) return false;
int16_t new_value; int16_t new_value;
new_value = value > ext->max_value ? ext->max_value : value; new_value = value > ext->max_value ? ext->max_value : value;
new_value = new_value < ext->min_value ? ext->min_value : new_value; new_value = new_value < ext->min_value ? ext->min_value : new_value;
if(ext->cur_value == new_value) return; if(ext->cur_value == new_value) return false;
ext->cur_value = new_value; ext->cur_value = new_value;
int16_t bg_midpoint, range_midpoint, bg_end = ext->arc.bg_angle_end; int16_t bg_midpoint, range_midpoint, bg_end = ext->arc.bg_angle_end;
@ -216,6 +216,7 @@ void lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim
ext->arc.bg_angle_start, bg_end) ext->arc.bg_angle_start, bg_end)
); );
} }
return true;
} }
/** /**
@ -420,18 +421,20 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par
if (ext->knob_area.y1 < p.y && p.y < ext->knob_area.y2) { if (ext->knob_area.y1 < p.y && p.y < ext->knob_area.y2) {
if (drag_x_diff > 0 && p.x < ext->knob_area.x2) { if (drag_x_diff > 0 && p.x < ext->knob_area.x2) {
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON); if (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); res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
}
else if (drag_x_diff < 0 && p.x > ext->knob_area.x1) { else if (drag_x_diff < 0 && p.x > ext->knob_area.x1) {
ext->last_drag_x = p.x; ext->last_drag_x = p.x;
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + drag_x_diff * ext->sensitivity, LV_ANIM_ON); if (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); res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
} }
} }
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
ext->dragging = false; ext->dragging = false;
@ -450,16 +453,18 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par
char c = *((char *)param); char c = *((char *)param);
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + ext->sensitivity, LV_ANIM_ON); if (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); res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
}
else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) - ext->sensitivity, LV_ANIM_ON); if (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); res = lv_event_send(rotary, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
} }
}
else if(sign == LV_SIGNAL_CLEANUP) { else if(sign == LV_SIGNAL_CLEANUP) {
lv_obj_clean_style_list(rotary, LV_ROTARY_PART_KNOB); lv_obj_clean_style_list(rotary, LV_ROTARY_PART_KNOB);
} }

View File

@ -114,8 +114,9 @@ void lv_rotary_set_type(lv_obj_t * rotary, lv_rotary_type_t type);
* @param rotary pointer to a rotary object * @param rotary pointer to a rotary object
* @param value new value * @param value new value
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
* @return true if value changed, otw false
*/ */
void lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim); bool lv_rotary_set_value(lv_obj_t * rotary, int16_t value, lv_anim_enable_t anim);
/** /**
* Set minimum and the maximum values of a rotary * Set minimum and the maximum values of a rotary