diff --git a/docs/overview/scroll.md b/docs/overview/scroll.md index 6064fce8f..c820831e0 100644 --- a/docs/overview/scroll.md +++ b/docs/overview/scroll.md @@ -55,8 +55,8 @@ or on the object's or any parent's main part to make a scrollbar inherit the bas ### Events The following events are related to scrolling: -- `LV_EVENT_SCROLL_BEGIN` Scrolling begins -- `LV_EVENT_SCROLL_END` Scrolling ends +- `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` Scroll happened. Triggered on every position change. Scroll events diff --git a/src/core/lv_event.h b/src/core/lv_event.h index 038570b72..d5a9eb6ba 100644 --- a/src/core/lv_event.h +++ b/src/core/lv_event.h @@ -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_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_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, /**< Scrolling*/ LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */ diff --git a/src/core/lv_obj_scroll.c b/src/core/lv_obj_scroll.c index cb43511bd..1aac616aa 100644 --- a/src/core/lv_obj_scroll.c +++ b/src/core/lv_obj_scroll.c @@ -31,7 +31,7 @@ /********************** * 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_y_anim(void * obj, int32_t v); static void scroll_anim_ready_cb(lv_anim_t * a); @@ -345,14 +345,18 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t dx, lv_coord_t dy, lv_anim_enab } else { /*Remove pending animations*/ - bool y_del = lv_anim_del(obj, scroll_y_anim); - bool x_del = lv_anim_del(obj, scroll_x_anim); - scroll_by_raw(obj, dx, dy); - if(y_del || x_del) { - lv_res_t res; - res = lv_event_send(obj, LV_EVENT_SCROLL_END, NULL); - if(res != LV_RES_OK) return; - } + lv_anim_del(obj, scroll_y_anim); + lv_anim_del(obj, scroll_x_anim); + + 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); + if(res != LV_RES_OK) return; } } @@ -648,9 +652,9 @@ void lv_obj_readjust_scroll(lv_obj_t * obj, lv_anim_enable_t anim_en) * 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); @@ -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_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); + return LV_RES_OK; } static void scroll_x_anim(void * obj, int32_t v)