mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(indev): start scroll_throw animation using lv_anim_start (#4827)
Signed-off-by: YanXiaowei <yanxiaowei@xiaomi.com> Co-authored-by: YanXiaowei <yanxiaowei@xiaomi.com>
This commit is contained in:
parent
bf1d0d3235
commit
afda43b037
@ -73,6 +73,18 @@ static void indev_read_core(lv_indev_t * indev, lv_indev_data_t * data);
|
||||
static void indev_reset_core(lv_indev_t * indev, lv_obj_t * obj);
|
||||
static lv_result_t send_event(lv_event_code_t code, void * param);
|
||||
|
||||
static void indev_scroll_throw_anim_start(lv_indev_t * indev);
|
||||
static void indev_scroll_throw_anim_cb(void * var, int32_t v);
|
||||
static void indev_scroll_throw_anim_ready_cb(lv_anim_t * anim);
|
||||
static inline void indev_scroll_throw_anim_reset(lv_indev_t * indev)
|
||||
{
|
||||
if(indev) {
|
||||
indev->pointer.scroll_throw_vect.x = 0;
|
||||
indev->pointer.scroll_throw_vect.y = 0;
|
||||
indev->scroll_throw_anim = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
@ -1056,8 +1068,12 @@ static void indev_proc_press(lv_indev_t * indev)
|
||||
|
||||
/*The last object might have scroll throw. Stop it manually*/
|
||||
if(new_obj_searched && indev->pointer.last_obj) {
|
||||
indev->pointer.scroll_throw_vect.x = 0;
|
||||
indev->pointer.scroll_throw_vect.y = 0;
|
||||
|
||||
/*Attempt to stop scroll throw animation firstly*/
|
||||
if(!indev->scroll_throw_anim || !lv_anim_delete(indev, indev_scroll_throw_anim_cb)) {
|
||||
indev_scroll_throw_anim_reset(indev);
|
||||
}
|
||||
|
||||
_lv_indev_scroll_throw_handler(indev);
|
||||
if(indev_reset_check(indev)) return;
|
||||
}
|
||||
@ -1233,7 +1249,10 @@ static void indev_proc_release(lv_indev_t * indev)
|
||||
}
|
||||
|
||||
if(scroll_obj) {
|
||||
_lv_indev_scroll_throw_handler(indev);
|
||||
if(!indev->scroll_throw_anim) {
|
||||
indev_scroll_throw_anim_start(indev);
|
||||
}
|
||||
|
||||
if(indev_reset_check(indev)) return;
|
||||
}
|
||||
}
|
||||
@ -1477,3 +1496,44 @@ static lv_result_t send_event(lv_event_code_t code, void * param)
|
||||
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
|
||||
static void indev_scroll_throw_anim_cb(void * var, int32_t v)
|
||||
{
|
||||
LV_ASSERT_NULL(var);
|
||||
LV_UNUSED(v);
|
||||
lv_indev_t * indev = (lv_indev_t *)var;
|
||||
|
||||
_lv_indev_scroll_throw_handler(indev);
|
||||
|
||||
if(indev->pointer.scroll_dir == LV_DIR_NONE || indev->pointer.scroll_obj == NULL) {
|
||||
if(indev->scroll_throw_anim) {
|
||||
/*hacky*/
|
||||
LV_LOG_INFO("stop animation");
|
||||
lv_anim_set_time(indev->scroll_throw_anim, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void indev_scroll_throw_anim_ready_cb(lv_anim_t * anim)
|
||||
{
|
||||
if(anim) {
|
||||
indev_scroll_throw_anim_reset((lv_indev_t *)anim->var);
|
||||
}
|
||||
}
|
||||
|
||||
static void indev_scroll_throw_anim_start(lv_indev_t * indev)
|
||||
{
|
||||
LV_ASSERT_NULL(indev);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, indev);
|
||||
lv_anim_set_time(&a, 1024);
|
||||
lv_anim_set_values(&a, 0, 1024);
|
||||
lv_anim_set_exec_cb(&a, indev_scroll_throw_anim_cb);
|
||||
lv_anim_set_ready_cb(&a, indev_scroll_throw_anim_ready_cb);
|
||||
lv_anim_set_deleted_cb(&a, indev_scroll_throw_anim_ready_cb);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||
|
||||
indev->scroll_throw_anim = lv_anim_start(&a);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ extern "C" {
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_indev.h"
|
||||
#include "../misc/lv_anim.h"
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@ -103,6 +104,7 @@ struct _lv_indev_t {
|
||||
here by the buttons*/
|
||||
|
||||
lv_event_list_t event_list;
|
||||
lv_anim_t * scroll_throw_anim;
|
||||
};
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
|
@ -118,8 +118,7 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
|
||||
if(scroll_obj == NULL) return;
|
||||
if(indev->pointer.scroll_dir == LV_DIR_NONE) return;
|
||||
|
||||
lv_indev_t * indev_act = lv_indev_active();
|
||||
int32_t scroll_throw = indev_act->scroll_throw;
|
||||
int32_t scroll_throw = indev->scroll_throw;
|
||||
|
||||
if(lv_obj_has_flag(scroll_obj, LV_OBJ_FLAG_SCROLL_MOMENTUM) == false) {
|
||||
indev->pointer.scroll_throw_vect.y = 0;
|
||||
@ -217,7 +216,7 @@ void _lv_indev_scroll_throw_handler(lv_indev_t * indev)
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_send_event(scroll_obj, LV_EVENT_SCROLL_END, indev_act);
|
||||
lv_obj_send_event(scroll_obj, LV_EVENT_SCROLL_END, indev);
|
||||
if(indev->reset_query) return;
|
||||
|
||||
indev->pointer.scroll_dir = LV_DIR_NONE;
|
||||
@ -270,8 +269,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();
|
||||
int32_t scroll_limit = indev_act->scroll_limit;
|
||||
int32_t scroll_limit = indev->scroll_limit;
|
||||
|
||||
/*Go until find a scrollable object in the current direction
|
||||
*More precisely:
|
||||
@ -595,8 +593,7 @@ static int32_t scroll_throw_predict_y(lv_indev_t * indev)
|
||||
int32_t y = indev->pointer.scroll_throw_vect.y;
|
||||
int32_t move = 0;
|
||||
|
||||
lv_indev_t * indev_act = lv_indev_active();
|
||||
int32_t scroll_throw = indev_act->scroll_throw;
|
||||
int32_t scroll_throw = indev->scroll_throw;
|
||||
|
||||
while(y) {
|
||||
move += y;
|
||||
@ -610,8 +607,7 @@ static int32_t scroll_throw_predict_x(lv_indev_t * indev)
|
||||
int32_t x = indev->pointer.scroll_throw_vect.x;
|
||||
int32_t move = 0;
|
||||
|
||||
lv_indev_t * indev_act = lv_indev_active();
|
||||
int32_t scroll_throw = indev_act->scroll_throw;
|
||||
int32_t scroll_throw = indev->scroll_throw;
|
||||
|
||||
while(x) {
|
||||
move += x;
|
||||
|
Loading…
x
Reference in New Issue
Block a user