From 25ce6e3ae9e144e2df5dad34475dda3542015f6a Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 1 Jul 2022 13:55:44 +0200 Subject: [PATCH] fix(scroll): do not fire scroll begin/end event on every scroll step fixes: #3436 --- src/core/lv_indev_scroll.c | 3 ++- src/core/lv_obj_scroll.c | 39 +++++++++++++++++++------------------- src/core/lv_obj_scroll.h | 13 +++++++++++++ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/core/lv_indev_scroll.c b/src/core/lv_indev_scroll.c index 96fa2f66d..c05e3459f 100644 --- a/src/core/lv_indev_scroll.c +++ b/src/core/lv_indev_scroll.c @@ -85,7 +85,8 @@ void _lv_indev_scroll_handler(_lv_indev_proc_t * proc) /*Respect the scroll limit area*/ scroll_limit_diff(proc, &diff_x, &diff_y); - lv_obj_scroll_by(scroll_obj, diff_x, diff_y, LV_ANIM_OFF); + _lv_obj_scroll_by_raw(scroll_obj, diff_x, diff_y); + if(proc->reset_query) return; proc->types.pointer.scroll_sum.x += diff_x; proc->types.pointer.scroll_sum.y += diff_y; } diff --git a/src/core/lv_obj_scroll.c b/src/core/lv_obj_scroll.c index 1aac616aa..02b982614 100644 --- a/src/core/lv_obj_scroll.c +++ b/src/core/lv_obj_scroll.c @@ -31,7 +31,6 @@ /********************** * STATIC PROTOTYPES **********************/ -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); @@ -352,7 +351,7 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t dx, lv_coord_t dy, lv_anim_enab res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, NULL); if(res != LV_RES_OK) return; - res = scroll_by_raw(obj, dx, dy); + res = _lv_obj_scroll_by_raw(obj, dx, dy); if(res != LV_RES_OK) return; res = lv_event_send(obj, LV_EVENT_SCROLL_END, NULL); @@ -410,6 +409,23 @@ void lv_obj_scroll_to_view_recursive(lv_obj_t * obj, lv_anim_enable_t anim_en) } } +lv_res_t _lv_obj_scroll_by_raw(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) +{ + if(x == 0 && y == 0) return LV_RES_OK; + + lv_obj_allocate_spec_attr(obj); + + obj->spec_attr->scroll.x += x; + obj->spec_attr->scroll.y += 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 res; + lv_obj_invalidate(obj); + return LV_RES_OK; +} + + bool lv_obj_is_scrolling(const lv_obj_t * obj) { lv_indev_t * indev = lv_indev_get_next(NULL); @@ -652,30 +668,15 @@ void lv_obj_readjust_scroll(lv_obj_t * obj, lv_anim_enable_t anim_en) * STATIC FUNCTIONS **********************/ -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 LV_RES_OK; - - lv_obj_allocate_spec_attr(obj); - - obj->spec_attr->scroll.x += x; - obj->spec_attr->scroll.y += 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 res; - lv_obj_invalidate(obj); - return LV_RES_OK; -} static void scroll_x_anim(void * obj, int32_t v) { - scroll_by_raw(obj, v + lv_obj_get_scroll_x(obj), 0); + _lv_obj_scroll_by_raw(obj, v + lv_obj_get_scroll_x(obj), 0); } static void scroll_y_anim(void * obj, int32_t v) { - scroll_by_raw(obj, 0, v + lv_obj_get_scroll_y(obj)); + _lv_obj_scroll_by_raw(obj, 0, v + lv_obj_get_scroll_y(obj)); } static void scroll_anim_ready_cb(lv_anim_t * a) diff --git a/src/core/lv_obj_scroll.h b/src/core/lv_obj_scroll.h index c9fdd720d..e1da245b7 100644 --- a/src/core/lv_obj_scroll.h +++ b/src/core/lv_obj_scroll.h @@ -15,6 +15,7 @@ extern "C" { *********************/ #include "../misc/lv_area.h" #include "../misc/lv_anim.h" +#include "../misc/lv_types.h" /********************* * DEFINES @@ -248,6 +249,18 @@ void lv_obj_scroll_to_view(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); */ void lv_obj_scroll_to_view_recursive(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + +/** + * Low level function to scroll by given x and y coordinates. + * `LV_EVENT_SCROLL` is sent. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @return `LV_RES_INV`: to object was deleted in `LV_EVENT_SCROLL`; + * `LV_RES_OK`: if the object is still valid + */ +lv_res_t _lv_obj_scroll_by_raw(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + /** * Tell whether an object is being scrolled or not at this moment * @param obj pointer to an object