1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

feat(event): add LV_EVENT_SCROLL_THROW_BEGIN

This commit is contained in:
Gabor Kiss-Vamosi 2022-09-05 10:09:30 +02:00
parent 7040518d2d
commit 0c7f69ac91
4 changed files with 16 additions and 6 deletions

View File

@ -75,6 +75,7 @@ The following event codes exist:
- `LV_EVENT_CLICKED` Called on release if an object did not scroll (regardless of long press)
- `LV_EVENT_RELEASED` Called in every case when an object has been released
- `LV_EVENT_SCROLL_BEGIN` Scrolling begins. The event parameter is `NULL` or an `lv_anim_t *` with a scroll animation descriptor that can be modified if required.
- `LV_EVENT_SCROLL_THROW_BEGIN` Sent once when the object is released while scrolling but the "momentum" still keeps the content scrolling.
- `LV_EVENT_SCROLL_END` Scrolling ends.
- `LV_EVENT_SCROLL` An object was scrolled
- `LV_EVENT_GESTURE` A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());`

View File

@ -42,7 +42,8 @@ typedef enum {
LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/
LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/
LV_EVENT_SCROLL_BEGIN, /**< Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified*/
LV_EVENT_SCROLL_END, /**< Scrolling ends*/
LV_EVENT_SCROLL_THROW_BEGIN,
LV_EVENT_SCROLL_END, /**< Scrolling ends*/
LV_EVENT_SCROLL, /**< Scrolling*/
LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */
LV_EVENT_KEY, /**< A key is sent to the object. Get the key with `lv_indev_get_key(lv_indev_get_act());`*/

View File

@ -982,6 +982,9 @@ static void indev_proc_release(_lv_indev_proc_t * proc)
lv_event_send(indev_obj_act, LV_EVENT_CLICKED, indev_act);
if(indev_reset_check(proc)) return;
} else {
lv_event_send(scroll_obj, LV_EVENT_SCROLL_THROW_BEGIN, indev_act);
if(indev_reset_check(proc)) return;
}
proc->types.pointer.act_obj = NULL;
@ -990,8 +993,6 @@ static void indev_proc_release(_lv_indev_proc_t * proc)
}
/*The reset can be set in the Call the ancestor's event handler function.
* In case of reset query ignore the remaining parts.*/
if(scroll_obj) {
_lv_indev_scroll_throw_handler(proc);
if(indev_reset_check(proc)) return;

View File

@ -99,7 +99,6 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
if(scroll_obj == NULL) return;
if(proc->types.pointer.scroll_dir == LV_DIR_NONE) return;
lv_indev_t * indev_act = lv_indev_get_act();
lv_coord_t scroll_throw = indev_act->driver->scroll_throw;
@ -124,7 +123,8 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
proc->types.pointer.scroll_throw_vect.y = elastic_diff(scroll_obj, proc->types.pointer.scroll_throw_vect.y, st, sb,
LV_DIR_VER);
lv_obj_scroll_by(scroll_obj, 0, proc->types.pointer.scroll_throw_vect.y, LV_ANIM_OFF);
_lv_obj_scroll_by_raw(scroll_obj, 0, proc->types.pointer.scroll_throw_vect.y);
if(proc->reset_query) return;
}
/*With snapping find the nearest snap point and scroll there*/
else {
@ -133,6 +133,7 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
scroll_limit_diff(proc, NULL, &diff_y);
lv_coord_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(proc->reset_query) return;
}
}
else if(proc->types.pointer.scroll_dir == LV_DIR_HOR) {
@ -148,7 +149,8 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
proc->types.pointer.scroll_throw_vect.x = elastic_diff(scroll_obj, proc->types.pointer.scroll_throw_vect.x, sl, sr,
LV_DIR_HOR);
lv_obj_scroll_by(scroll_obj, proc->types.pointer.scroll_throw_vect.x, 0, LV_ANIM_OFF);
_lv_obj_scroll_by_raw(scroll_obj, proc->types.pointer.scroll_throw_vect.x, 0);
if(proc->reset_query) return;
}
/*With snapping find the nearest snap point and scroll there*/
else {
@ -157,6 +159,7 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
scroll_limit_diff(proc, &diff_x, NULL);
lv_coord_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(proc->reset_query) return;
}
}
@ -170,9 +173,11 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
if(st > 0 || sb > 0) {
if(st < 0) {
lv_obj_scroll_by(scroll_obj, 0, st, LV_ANIM_ON);
if(proc->reset_query) return;
}
else if(sb < 0) {
lv_obj_scroll_by(scroll_obj, 0, -sb, LV_ANIM_ON);
if(proc->reset_query) return;
}
}
}
@ -184,9 +189,11 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc)
if(sl > 0 || sr > 0) {
if(sl < 0) {
lv_obj_scroll_by(scroll_obj, sl, 0, LV_ANIM_ON);
if(proc->reset_query) return;
}
else if(sr < 0) {
lv_obj_scroll_by(scroll_obj, -sr, 0, LV_ANIM_ON);
if(proc->reset_query) return;
}
}
}