fix(indev): fix scroll_obj not send LV_EVENT_INDEV_RESET (#7767)

Signed-off-by: yushuailong1 <yushuailong1@xiaomi.com>
This commit is contained in:
yushuailong
2025-02-20 12:19:38 +08:00
committed by GitHub
parent 28f902d702
commit 884589e12b
2 changed files with 79 additions and 18 deletions

View File

@@ -1756,29 +1756,29 @@ static void indev_reset_core(lv_indev_t * indev, lv_obj_t * obj)
if(obj == NULL || indev->pointer.last_pressed == obj) { if(obj == NULL || indev->pointer.last_pressed == obj) {
indev->pointer.last_pressed = NULL; indev->pointer.last_pressed = NULL;
} }
if(obj == NULL || indev->pointer.act_obj == obj) {
if(indev->pointer.act_obj) { if(indev->pointer.act_obj) {
/* Avoid recursive calls */ /* Avoid recursive calls */
act_obj = indev->pointer.act_obj; act_obj = indev->pointer.act_obj;
indev->pointer.act_obj = NULL; indev->pointer.act_obj = NULL;
lv_obj_send_event(act_obj, LV_EVENT_INDEV_RESET, indev); lv_obj_send_event(act_obj, LV_EVENT_INDEV_RESET, indev);
lv_indev_send_event(indev, LV_EVENT_INDEV_RESET, act_obj); lv_indev_send_event(indev, LV_EVENT_INDEV_RESET, act_obj);
act_obj = NULL; act_obj = NULL;
}
} }
if(obj == NULL || indev->pointer.last_obj == obj) { if(obj == NULL || indev->pointer.last_obj == obj) {
indev->pointer.last_obj = NULL; indev->pointer.last_obj = NULL;
} }
if(obj == NULL || indev->pointer.scroll_obj == obj) {
if(indev->pointer.scroll_obj) { if(indev->pointer.scroll_obj) {
/* Avoid recursive calls */ /* Avoid recursive calls */
scroll_obj = indev->pointer.scroll_obj; scroll_obj = indev->pointer.scroll_obj;
indev->pointer.scroll_obj = NULL; indev->pointer.scroll_obj = NULL;
lv_obj_send_event(scroll_obj, LV_EVENT_INDEV_RESET, indev); lv_obj_send_event(scroll_obj, LV_EVENT_INDEV_RESET, indev);
lv_indev_send_event(indev, LV_EVENT_INDEV_RESET, act_obj); lv_indev_send_event(indev, LV_EVENT_INDEV_RESET, scroll_obj);
scroll_obj = NULL; scroll_obj = NULL;
}
} }
if(obj == NULL || indev->pointer.last_hovered == obj) { if(obj == NULL || indev->pointer.last_hovered == obj) {
indev->pointer.last_hovered = NULL; indev->pointer.last_hovered = NULL;
} }

View File

@@ -0,0 +1,61 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../lv_test_indev.h"
#include "unity/unity.h"
static uint32_t indev_reset_count = 0;
void setUp(void)
{
/* Function run before every test */
indev_reset_count = 0;
}
void tearDown(void)
{
/* Function run after every test */
lv_obj_clean(lv_screen_active());
}
static void event_cb(lv_event_t * e)
{
lv_obj_t * scroll_obj = lv_event_get_target(e);
lv_obj_t * act_obj = lv_obj_get_child(scroll_obj, 0);
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_SCROLL && act_obj) {
lv_obj_delete(act_obj);
}
else if(code == LV_EVENT_INDEV_RESET) {
indev_reset_count += 1;
}
}
void test_indev_wait_release(void)
{
lv_obj_t * scroll_obj = lv_obj_create(lv_screen_active());
lv_obj_set_size(scroll_obj, 300, 300);
lv_obj_align(scroll_obj, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_add_event_cb(scroll_obj, event_cb, LV_EVENT_ALL, NULL);
lv_obj_t * act_obj = lv_obj_create(scroll_obj);
lv_obj_set_size(act_obj, 400, 200);
lv_obj_align(act_obj, LV_ALIGN_LEFT_MID, 0, 0);
lv_test_mouse_move_to(200, 200);
lv_test_mouse_press();
lv_test_indev_wait(50);
lv_test_mouse_move_by(-20, 0);
lv_test_mouse_press();
lv_test_indev_wait(50);
lv_test_mouse_move_by(-20, 0);
lv_test_mouse_press();
lv_test_indev_wait(50);
lv_test_mouse_release();
TEST_ASSERT_EQUAL_UINT32(1, indev_reset_count);
}
#endif