refactor(indev_scroll): refactor code (#5456)
This commit is contained in:
@@ -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_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 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 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,
|
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);
|
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*/
|
/*With snapping find the nearest snap point and scroll there*/
|
||||||
else {
|
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;
|
indev->pointer.scroll_throw_vect.y = 0;
|
||||||
scroll_limit_diff(indev, NULL, &diff_y);
|
scroll_limit_diff(indev, NULL, &diff_y);
|
||||||
int32_t y = find_snap_point_y(scroll_obj, LV_COORD_MIN, LV_COORD_MAX, 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*/
|
/*With snapping find the nearest snap point and scroll there*/
|
||||||
else {
|
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;
|
indev->pointer.scroll_throw_vect.x = 0;
|
||||||
scroll_limit_diff(indev, &diff_x, NULL);
|
scroll_limit_diff(indev, &diff_x, NULL);
|
||||||
int32_t x = find_snap_point_x(scroll_obj, LV_COORD_MIN, LV_COORD_MAX, diff_x);
|
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,
|
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)
|
lv_dir_t dir)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user