fix(scroll): send LV_EVENT_SCROLL_BEGIN/END with no animation too

This commit is contained in:
Gabor Kiss-Vamosi
2022-04-14 13:37:48 +02:00
parent b6e76e28cf
commit 777fe1ea70
3 changed files with 20 additions and 15 deletions

View File

@@ -55,8 +55,8 @@ or on the object's or any parent's main part to make a scrollbar inherit the bas
### Events ### Events
The following events are related to scrolling: The following events are related to scrolling:
- `LV_EVENT_SCROLL_BEGIN` Scrolling begins - `LV_EVENT_SCROLL_BEGIN` Scrolling begins. The event parameter is `NULL` or an `lv_anim_t *` with a scroll animation descriptor that can be modified if required.
- `LV_EVENT_SCROLL_END` Scrolling ends - `LV_EVENT_SCROLL_END` Scrolling ends.
- `LV_EVENT_SCROLL` Scroll happened. Triggered on every position change. - `LV_EVENT_SCROLL` Scroll happened. Triggered on every position change.
Scroll events Scroll events

View File

@@ -41,7 +41,7 @@ typedef enum {
LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `long_press_time` in every `long_press_repeat_time` ms. Not called if scrolled.*/ LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `long_press_time` in every `long_press_repeat_time` ms. Not called if scrolled.*/
LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/ LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/
LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/ LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/
LV_EVENT_SCROLL_BEGIN, /**< Scrolling begins*/ LV_EVENT_SCROLL_BEGIN, /**< Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified*/
LV_EVENT_SCROLL_END, /**< Scrolling ends*/ LV_EVENT_SCROLL_END, /**< Scrolling ends*/
LV_EVENT_SCROLL, /**< Scrolling*/ LV_EVENT_SCROLL, /**< Scrolling*/
LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */ LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */

View File

@@ -31,7 +31,7 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void scroll_by_raw(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); static lv_res_t scroll_by_raw(lv_obj_t * obj, lv_coord_t x, lv_coord_t y);
static void scroll_x_anim(void * obj, int32_t v); static void scroll_x_anim(void * obj, int32_t v);
static void scroll_y_anim(void * obj, int32_t v); static void scroll_y_anim(void * obj, int32_t v);
static void scroll_anim_ready_cb(lv_anim_t * a); static void scroll_anim_ready_cb(lv_anim_t * a);
@@ -345,15 +345,19 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t dx, lv_coord_t dy, lv_anim_enab
} }
else { else {
/*Remove pending animations*/ /*Remove pending animations*/
bool y_del = lv_anim_del(obj, scroll_y_anim); lv_anim_del(obj, scroll_y_anim);
bool x_del = lv_anim_del(obj, scroll_x_anim); lv_anim_del(obj, scroll_x_anim);
scroll_by_raw(obj, dx, dy);
if(y_del || x_del) {
lv_res_t res; lv_res_t res;
res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, NULL);
if(res != LV_RES_OK) return;
res = scroll_by_raw(obj, dx, dy);
if(res != LV_RES_OK) return;
res = lv_event_send(obj, LV_EVENT_SCROLL_END, NULL); res = lv_event_send(obj, LV_EVENT_SCROLL_END, NULL);
if(res != LV_RES_OK) return; if(res != LV_RES_OK) return;
} }
}
} }
void lv_obj_scroll_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en) void lv_obj_scroll_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en)
@@ -648,9 +652,9 @@ void lv_obj_readjust_scroll(lv_obj_t * obj, lv_anim_enable_t anim_en)
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static void scroll_by_raw(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) static lv_res_t scroll_by_raw(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
{ {
if(x == 0 && y == 0) return; if(x == 0 && y == 0) return LV_RES_OK;
lv_obj_allocate_spec_attr(obj); lv_obj_allocate_spec_attr(obj);
@@ -659,8 +663,9 @@ static void scroll_by_raw(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
lv_obj_move_children_by(obj, x, y, true); lv_obj_move_children_by(obj, x, y, true);
lv_res_t res = lv_event_send(obj, LV_EVENT_SCROLL, NULL); lv_res_t res = lv_event_send(obj, LV_EVENT_SCROLL, NULL);
if(res != LV_RES_OK) return; if(res != LV_RES_OK) return res;
lv_obj_invalidate(obj); lv_obj_invalidate(obj);
return LV_RES_OK;
} }
static void scroll_x_anim(void * obj, int32_t v) static void scroll_x_anim(void * obj, int32_t v)