aboutsummaryrefslogtreecommitdiff
path: root/src/indev/lv_indev_scroll.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/indev/lv_indev_scroll.c')
-rw-r--r--src/indev/lv_indev_scroll.c136
1 files changed, 68 insertions, 68 deletions
diff --git a/src/indev/lv_indev_scroll.c b/src/indev/lv_indev_scroll.c
index f564e0e22..b645565fa 100644
--- a/src/indev/lv_indev_scroll.c
+++ b/src/indev/lv_indev_scroll.c
@@ -24,13 +24,13 @@
**********************/
static lv_obj_t * find_scroll_obj(lv_indev_t * indev);
static void init_scroll_limits(lv_indev_t * indev);
-static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coord_t max, lv_coord_t ofs);
-static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coord_t max, lv_coord_t ofs);
-static void scroll_limit_diff(lv_indev_t * indev, lv_coord_t * diff_x, lv_coord_t * diff_y);
-static lv_coord_t scroll_throw_predict_y(lv_indev_t * indev);
-static lv_coord_t scroll_throw_predict_x(lv_indev_t * indev);
-static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_t scroll_start, lv_coord_t scroll_end,
- lv_dir_t dir);
+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);
/**********************
* STATIC VARIABLES
@@ -85,16 +85,16 @@ void _lv_indev_scroll_handler(lv_indev_t * indev)
}
- lv_coord_t diff_x = 0;
- lv_coord_t diff_y = 0;
+ int32_t diff_x = 0;
+ int32_t diff_y = 0;
if(indev->pointer.scroll_dir == LV_DIR_HOR) {
- lv_coord_t sr = lv_obj_get_scroll_right(scroll_obj);
- lv_coord_t sl = lv_obj_get_scroll_left(scroll_obj);
+ int32_t sr = lv_obj_get_scroll_right(scroll_obj);
+ int32_t sl = lv_obj_get_scroll_left(scroll_obj);
diff_x = elastic_diff(scroll_obj, indev->pointer.vect.x, sl, sr, LV_DIR_HOR);
}
else {
- lv_coord_t st = lv_obj_get_scroll_top(scroll_obj);
- lv_coord_t sb = lv_obj_get_scroll_bottom(scroll_obj);
+ int32_t st = lv_obj_get_scroll_top(scroll_obj);
+ int32_t sb = lv_obj_get_scroll_bottom(scroll_obj);
diff_y = elastic_diff(scroll_obj, indev->pointer.vect.y, st, sb, LV_DIR_VER);
}
@@ -121,7 +121,7 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
if(indev->pointer.scroll_dir == LV_DIR_NONE) return;
lv_indev_t * indev_act = lv_indev_active();
- lv_coord_t scroll_throw = indev_act->scroll_throw;
+ int32_t scroll_throw = indev_act->scroll_throw;
if(lv_obj_has_flag(scroll_obj, LV_OBJ_FLAG_SCROLL_MOMENTUM) == false) {
indev->pointer.scroll_throw_vect.y = 0;
@@ -138,8 +138,8 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
indev->pointer.scroll_throw_vect.y =
indev->pointer.scroll_throw_vect.y * (100 - scroll_throw) / 100;
- lv_coord_t sb = lv_obj_get_scroll_bottom(scroll_obj);
- lv_coord_t st = lv_obj_get_scroll_top(scroll_obj);
+ int32_t sb = lv_obj_get_scroll_bottom(scroll_obj);
+ int32_t st = lv_obj_get_scroll_top(scroll_obj);
indev->pointer.scroll_throw_vect.y = elastic_diff(scroll_obj, indev->pointer.scroll_throw_vect.y, st, sb,
LV_DIR_VER);
@@ -149,10 +149,10 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
}
/*With snapping find the nearest snap point and scroll there*/
else {
- lv_coord_t diff_y = scroll_throw_predict_y(indev);
+ int32_t diff_y = scroll_throw_predict_y(indev);
indev->pointer.scroll_throw_vect.y = 0;
scroll_limit_diff(indev, NULL, &diff_y);
- lv_coord_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);
lv_obj_scroll_by(scroll_obj, 0, diff_y + y, LV_ANIM_ON);
if(indev->reset_query) return;
}
@@ -164,8 +164,8 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
indev->pointer.scroll_throw_vect.x =
indev->pointer.scroll_throw_vect.x * (100 - scroll_throw) / 100;
- lv_coord_t sl = lv_obj_get_scroll_left(scroll_obj);
- lv_coord_t sr = lv_obj_get_scroll_right(scroll_obj);
+ int32_t sl = lv_obj_get_scroll_left(scroll_obj);
+ int32_t sr = lv_obj_get_scroll_right(scroll_obj);
indev->pointer.scroll_throw_vect.x = elastic_diff(scroll_obj, indev->pointer.scroll_throw_vect.x, sl, sr,
LV_DIR_HOR);
@@ -175,10 +175,10 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
}
/*With snapping find the nearest snap point and scroll there*/
else {
- lv_coord_t diff_x = scroll_throw_predict_x(indev);
+ int32_t diff_x = scroll_throw_predict_x(indev);
indev->pointer.scroll_throw_vect.x = 0;
scroll_limit_diff(indev, &diff_x, NULL);
- lv_coord_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);
lv_obj_scroll_by(scroll_obj, x + diff_x, 0, LV_ANIM_ON);
if(indev->reset_query) return;
}
@@ -189,8 +189,8 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
/*Revert if scrolled in*/
/*If vertically scrollable and not controlled by snap*/
if(align_y == LV_SCROLL_SNAP_NONE) {
- lv_coord_t st = lv_obj_get_scroll_top(scroll_obj);
- lv_coord_t sb = lv_obj_get_scroll_bottom(scroll_obj);
+ int32_t st = lv_obj_get_scroll_top(scroll_obj);
+ int32_t sb = lv_obj_get_scroll_bottom(scroll_obj);
if(st > 0 || sb > 0) {
if(st < 0) {
lv_obj_scroll_by(scroll_obj, 0, st, LV_ANIM_ON);
@@ -205,8 +205,8 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
/*If horizontally scrollable and not controlled by snap*/
if(align_x == LV_SCROLL_SNAP_NONE) {
- lv_coord_t sl = lv_obj_get_scroll_left(scroll_obj);
- lv_coord_t sr = lv_obj_get_scroll_right(scroll_obj);
+ int32_t sl = lv_obj_get_scroll_left(scroll_obj);
+ int32_t sr = lv_obj_get_scroll_right(scroll_obj);
if(sl > 0 || sr > 0) {
if(sl < 0) {
lv_obj_scroll_by(scroll_obj, sl, 0, LV_ANIM_ON);
@@ -233,10 +233,10 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
* @param dir `LV_DIR_VER` or `LV_DIR_HOR`
* @return the difference compared to the current position when the throw would be finished
*/
-lv_coord_t lv_indev_scroll_throw_predict(lv_indev_t * indev, lv_dir_t dir)
+int32_t lv_indev_scroll_throw_predict(lv_indev_t * indev, lv_dir_t dir)
{
if(indev == NULL) return 0;
- lv_coord_t v;
+ int32_t v;
switch(dir) {
case LV_DIR_VER:
v = indev->pointer.scroll_throw_vect_ori.y;
@@ -248,8 +248,8 @@ lv_coord_t lv_indev_scroll_throw_predict(lv_indev_t * indev, lv_dir_t dir)
return 0;
}
- lv_coord_t scroll_throw = indev->scroll_throw;
- lv_coord_t sum = 0;
+ int32_t scroll_throw = indev->scroll_throw;
+ int32_t sum = 0;
while(v) {
sum += v;
v = v * (100 - scroll_throw) / 100;
@@ -273,7 +273,7 @@ static lv_obj_t * find_scroll_obj(lv_indev_t * indev)
lv_obj_t * obj_candidate = NULL;
lv_dir_t dir_candidate = LV_DIR_NONE;
lv_indev_t * indev_act = lv_indev_active();
- lv_coord_t scroll_limit = indev_act->scroll_limit;
+ int32_t scroll_limit = indev_act->scroll_limit;
/*Go until find a scrollable object in the current direction
*More precisely:
@@ -344,10 +344,10 @@ static lv_obj_t * find_scroll_obj(lv_indev_t * indev)
if((scroll_dir & LV_DIR_BOTTOM) == 0) down_en = false;
/*The object is scrollable to a direction if its content overflow in that direction.*/
- lv_coord_t st = lv_obj_get_scroll_top(obj_act);
- lv_coord_t sb = lv_obj_get_scroll_bottom(obj_act);
- lv_coord_t sl = lv_obj_get_scroll_left(obj_act);
- lv_coord_t sr = lv_obj_get_scroll_right(obj_act);
+ int32_t st = lv_obj_get_scroll_top(obj_act);
+ int32_t sb = lv_obj_get_scroll_bottom(obj_act);
+ int32_t sl = lv_obj_get_scroll_left(obj_act);
+ int32_t sr = lv_obj_get_scroll_right(obj_act);
/*If this object is scrollable into the current scroll direction then save it as a candidate.
*It's important only to be scrollable on the current axis (hor/ver) because if the scroll
@@ -419,7 +419,7 @@ static void init_scroll_limits(lv_indev_t * indev)
indev->pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, obj->coords.y2, 0);
break;
case LV_SCROLL_SNAP_CENTER: {
- lv_coord_t y_mid = obj->coords.y1 + lv_area_get_height(&obj->coords) / 2;
+ int32_t y_mid = obj->coords.y1 + lv_area_get_height(&obj->coords) / 2;
indev->pointer.scroll_area.y1 = find_snap_point_y(obj, y_mid + 1, LV_COORD_MAX, 0);
indev->pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, y_mid - 1, 0);
break;
@@ -440,7 +440,7 @@ static void init_scroll_limits(lv_indev_t * indev)
indev->pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, obj->coords.x2, 0);
break;
case LV_SCROLL_SNAP_CENTER: {
- lv_coord_t x_mid = obj->coords.x1 + lv_area_get_width(&obj->coords) / 2;
+ int32_t x_mid = obj->coords.x1 + lv_area_get_width(&obj->coords) / 2;
indev->pointer.scroll_area.x1 = find_snap_point_x(obj, x_mid + 1, LV_COORD_MAX, 0);
indev->pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, x_mid - 1, 0);
break;
@@ -468,15 +468,15 @@ static void init_scroll_limits(lv_indev_t * indev)
* what if children are already moved by this value
* @return the distance of the snap point.
*/
-static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coord_t max, lv_coord_t ofs)
+static int32_t find_snap_point_x(const lv_obj_t * obj, int32_t min, int32_t max, int32_t ofs)
{
lv_scroll_snap_t align = lv_obj_get_scroll_snap_x(obj);
if(align == LV_SCROLL_SNAP_NONE) return 0;
- lv_coord_t dist = LV_COORD_MAX;
+ int32_t dist = LV_COORD_MAX;
- lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
- lv_coord_t pad_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
+ int32_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
+ int32_t pad_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
uint32_t i;
uint32_t child_cnt = lv_obj_get_child_cnt(obj);
@@ -484,8 +484,8 @@ static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coo
lv_obj_t * child = obj->spec_attr->children[i];
if(lv_obj_has_flag_any(child, LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue;
if(lv_obj_has_flag(child, LV_OBJ_FLAG_SNAPPABLE)) {
- lv_coord_t x_child = 0;
- lv_coord_t x_parent = 0;
+ int32_t x_child = 0;
+ int32_t x_parent = 0;
switch(align) {
case LV_SCROLL_SNAP_START:
x_child = child->coords.x1;
@@ -505,7 +505,7 @@ static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coo
x_child += ofs;
if(x_child >= min && x_child <= max) {
- lv_coord_t x = x_child - x_parent;
+ int32_t x = x_child - x_parent;
if(LV_ABS(x) < LV_ABS(dist)) dist = x;
}
}
@@ -523,15 +523,15 @@ static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coo
* what if children are already moved by this value
* @return the distance of the snap point.
*/
-static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coord_t max, lv_coord_t ofs)
+static int32_t find_snap_point_y(const lv_obj_t * obj, int32_t min, int32_t max, int32_t ofs)
{
lv_scroll_snap_t align = lv_obj_get_scroll_snap_y(obj);
if(align == LV_SCROLL_SNAP_NONE) return 0;
- lv_coord_t dist = LV_COORD_MAX;
+ int32_t dist = LV_COORD_MAX;
- lv_coord_t pad_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
- lv_coord_t pad_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
+ int32_t pad_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
+ int32_t pad_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
uint32_t i;
uint32_t child_cnt = lv_obj_get_child_cnt(obj);
@@ -539,8 +539,8 @@ static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coo
lv_obj_t * child = obj->spec_attr->children[i];
if(lv_obj_has_flag_any(child, LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue;
if(lv_obj_has_flag(child, LV_OBJ_FLAG_SNAPPABLE)) {
- lv_coord_t y_child = 0;
- lv_coord_t y_parent = 0;
+ int32_t y_child = 0;
+ int32_t y_parent = 0;
switch(align) {
case LV_SCROLL_SNAP_START:
y_child = child->coords.y1;
@@ -560,7 +560,7 @@ static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coo
y_child += ofs;
if(y_child >= min && y_child <= max) {
- lv_coord_t y = y_child - y_parent;
+ int32_t y = y_child - y_parent;
if(LV_ABS(y) < LV_ABS(dist)) dist = y;
}
}
@@ -569,7 +569,7 @@ static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coo
return dist == LV_COORD_MAX ? 0 : -dist;
}
-static void scroll_limit_diff(lv_indev_t * indev, lv_coord_t * diff_x, lv_coord_t * diff_y)
+static void scroll_limit_diff(lv_indev_t * indev, int32_t * diff_x, int32_t * diff_y)
{
if(diff_y) {
if(indev->pointer.scroll_sum.y + *diff_y < indev->pointer.scroll_area.y1) {
@@ -594,13 +594,13 @@ static void scroll_limit_diff(lv_indev_t * indev, lv_coord_t * diff_x, lv_coord_
-static lv_coord_t scroll_throw_predict_y(lv_indev_t * indev)
+static int32_t scroll_throw_predict_y(lv_indev_t * indev)
{
- lv_coord_t y = indev->pointer.scroll_throw_vect.y;
- lv_coord_t move = 0;
+ int32_t y = indev->pointer.scroll_throw_vect.y;
+ int32_t move = 0;
lv_indev_t * indev_act = lv_indev_active();
- lv_coord_t scroll_throw = indev_act->scroll_throw;
+ int32_t scroll_throw = indev_act->scroll_throw;
while(y) {
move += y;
@@ -610,13 +610,13 @@ static lv_coord_t scroll_throw_predict_y(lv_indev_t * indev)
}
-static lv_coord_t scroll_throw_predict_x(lv_indev_t * indev)
+static int32_t scroll_throw_predict_x(lv_indev_t * indev)
{
- lv_coord_t x = indev->pointer.scroll_throw_vect.x;
- lv_coord_t move = 0;
+ int32_t x = indev->pointer.scroll_throw_vect.x;
+ int32_t move = 0;
lv_indev_t * indev_act = lv_indev_active();
- lv_coord_t scroll_throw = indev_act->scroll_throw;
+ int32_t scroll_throw = indev_act->scroll_throw;
while(x) {
move += x;
@@ -625,8 +625,8 @@ static lv_coord_t scroll_throw_predict_x(lv_indev_t * indev)
return move;
}
-static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_t scroll_start, lv_coord_t scroll_end,
- lv_dir_t dir)
+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)
{
if(lv_obj_has_flag(scroll_obj, LV_OBJ_FLAG_SCROLL_ELASTIC)) {
/*If there is snapping in the current direction don't use the elastic factor because
@@ -635,12 +635,12 @@ static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_
snap = dir == LV_DIR_HOR ? lv_obj_get_scroll_snap_x(scroll_obj) : lv_obj_get_scroll_snap_y(scroll_obj);
lv_obj_t * act_obj = lv_indev_get_active_obj();
- lv_coord_t snap_point = 0;
- lv_coord_t act_obj_point = 0;
+ int32_t snap_point = 0;
+ int32_t act_obj_point = 0;
if(dir == LV_DIR_HOR) {
- lv_coord_t pad_left = lv_obj_get_style_pad_left(scroll_obj, LV_PART_MAIN);
- lv_coord_t pad_right = lv_obj_get_style_pad_right(scroll_obj, LV_PART_MAIN);
+ int32_t pad_left = lv_obj_get_style_pad_left(scroll_obj, LV_PART_MAIN);
+ int32_t pad_right = lv_obj_get_style_pad_right(scroll_obj, LV_PART_MAIN);
switch(snap) {
case LV_SCROLL_SNAP_CENTER:
@@ -658,8 +658,8 @@ static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_
}
}
else {
- lv_coord_t pad_top = lv_obj_get_style_pad_top(scroll_obj, LV_PART_MAIN);
- lv_coord_t pad_bottom = lv_obj_get_style_pad_bottom(scroll_obj, LV_PART_MAIN);
+ int32_t pad_top = lv_obj_get_style_pad_top(scroll_obj, LV_PART_MAIN);
+ int32_t pad_bottom = lv_obj_get_style_pad_bottom(scroll_obj, LV_PART_MAIN);
switch(snap) {
case LV_SCROLL_SNAP_CENTER: