1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

refactor(indev_scroll): refactor code (#5456)

This commit is contained in:
Benign X 2024-01-24 19:38:48 +08:00 committed by GitHub
parent 0fe187e905
commit 17fd06000c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)
{