From 17fd06000cee9d49405f258ba39c667240feed44 Mon Sep 17 00:00:00 2001 From: Benign X <1341398182@qq.com> Date: Wed, 24 Jan 2024 19:38:48 +0800 Subject: [PATCH] refactor(indev_scroll): refactor code (#5456) --- src/indev/lv_indev_scroll.c | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/indev/lv_indev_scroll.c b/src/indev/lv_indev_scroll.c index 7352d4363..1823418ae 100644 --- a/src/indev/lv_indev_scroll.c +++ b/src/indev/lv_indev_scroll.c @@ -27,8 +27,6 @@ static void init_scroll_limits(lv_indev_t * indev); static int32_t find_snap_point_x(const lv_obj_t * obj, int32_t min, int32_t max, int32_t ofs); static int32_t find_snap_point_y(const lv_obj_t * obj, int32_t min, int32_t max, int32_t ofs); static void scroll_limit_diff(lv_indev_t * indev, int32_t * diff_x, int32_t * diff_y); -static int32_t scroll_throw_predict_y(lv_indev_t * indev); -static int32_t scroll_throw_predict_x(lv_indev_t * indev); static int32_t elastic_diff(lv_obj_t * scroll_obj, int32_t diff, int32_t scroll_start, int32_t scroll_end, lv_dir_t dir); @@ -146,7 +144,7 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev) } /*With snapping find the nearest snap point and scroll there*/ else { - int32_t diff_y = scroll_throw_predict_y(indev); + int32_t diff_y = lv_indev_scroll_throw_predict(indev, LV_DIR_VER); indev->pointer.scroll_throw_vect.y = 0; scroll_limit_diff(indev, NULL, &diff_y); int32_t y = find_snap_point_y(scroll_obj, LV_COORD_MIN, LV_COORD_MAX, diff_y); @@ -172,7 +170,7 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev) } /*With snapping find the nearest snap point and scroll there*/ else { - int32_t diff_x = scroll_throw_predict_x(indev); + int32_t diff_x = lv_indev_scroll_throw_predict(indev, LV_DIR_HOR); indev->pointer.scroll_throw_vect.x = 0; scroll_limit_diff(indev, &diff_x, NULL); int32_t x = find_snap_point_x(scroll_obj, LV_COORD_MIN, LV_COORD_MAX, diff_x); @@ -582,34 +580,6 @@ static void scroll_limit_diff(lv_indev_t * indev, int32_t * diff_x, int32_t * di } } -static int32_t scroll_throw_predict_y(lv_indev_t * indev) -{ - int32_t y = indev->pointer.scroll_throw_vect.y; - int32_t move = 0; - - int32_t scroll_throw = indev->scroll_throw; - - while(y) { - move += y; - y = y * (100 - scroll_throw) / 100; - } - return move; -} - -static int32_t scroll_throw_predict_x(lv_indev_t * indev) -{ - int32_t x = indev->pointer.scroll_throw_vect.x; - int32_t move = 0; - - int32_t scroll_throw = indev->scroll_throw; - - while(x) { - move += x; - x = x * (100 - scroll_throw) / 100; - } - return move; -} - static int32_t elastic_diff(lv_obj_t * scroll_obj, int32_t diff, int32_t scroll_start, int32_t scroll_end, lv_dir_t dir) {