feat(events): add event trickle mechanism to propagate events to children (#8415)
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_VG_LITE - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled

Co-authored-by: Gauthier Provost <gpr@interel.com>
This commit is contained in:
Gauthier Provost
2025-07-03 19:20:41 +08:00
committed by GitHub
parent dec36ddb69
commit 6ec45fa613
15 changed files with 234 additions and 2 deletions
+96
View File
@@ -0,0 +1,96 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../../lvgl_private.h"
#include "unity/unity.h"
static uint32_t event_count = 0;
static lv_obj_t * last_target = NULL;
static void test_event_cb(lv_event_t * e)
{
event_count++;
last_target = lv_event_get_current_target_obj(e);
}
void test_event_trickle_basic(void)
{
/*Create a parent container*/
lv_obj_t * parent = lv_obj_create(lv_screen_active());
lv_obj_add_flag(parent, LV_OBJ_FLAG_EVENT_TRICKLE);
lv_obj_add_event_cb(parent, test_event_cb, LV_EVENT_CLICKED, NULL);
/*Create children*/
lv_obj_t * child1 = lv_obj_create(parent);
lv_obj_add_event_cb(child1, test_event_cb, LV_EVENT_CLICKED, NULL);
lv_obj_t * child2 = lv_obj_create(parent);
lv_obj_add_event_cb(child2, test_event_cb, LV_EVENT_CLICKED, NULL);
/*Reset counters*/
event_count = 0;
last_target = NULL;
/*Send event to parent - should trickle down to children*/
lv_obj_send_event(parent, LV_EVENT_CLICKED, NULL);
/*Should have received 3 events: parent + 2 children*/
TEST_ASSERT_EQUAL(3, event_count);
/*Clean up*/
lv_obj_delete(parent);
}
void test_event_trickle_stop(void)
{
/*Create a parent container*/
lv_obj_t * parent = lv_obj_create(lv_screen_active());
lv_obj_add_flag(parent, LV_OBJ_FLAG_EVENT_TRICKLE);
/*Add event handler that stops trickle down*/
lv_obj_add_event_cb(parent, test_event_cb, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(parent, (lv_event_cb_t)lv_event_stop_trickling, LV_EVENT_CLICKED, NULL);
/*Create children*/
lv_obj_t * child1 = lv_obj_create(parent);
lv_obj_add_event_cb(child1, test_event_cb, LV_EVENT_CLICKED, NULL);
/*Reset counters*/
event_count = 0;
last_target = NULL;
/*Send event to parent - should NOT trickle down due to stop*/
lv_obj_send_event(parent, LV_EVENT_CLICKED, NULL);
/*Should have received only 1 event: parent only*/
TEST_ASSERT_EQUAL(1, event_count); /* parent event handler + stop handler */
/*Clean up*/
lv_obj_delete(parent);
}
void test_event_trickle_disabled(void)
{
/*Create a parent container WITHOUT trickle down flag*/
lv_obj_t * parent = lv_obj_create(lv_screen_active());
lv_obj_add_event_cb(parent, test_event_cb, LV_EVENT_CLICKED, NULL);
/*Create children*/
lv_obj_t * child1 = lv_obj_create(parent);
lv_obj_add_event_cb(child1, test_event_cb, LV_EVENT_CLICKED, NULL);
/*Reset counters*/
event_count = 0;
last_target = NULL;
/*Send event to parent - should NOT trickle down*/
lv_obj_send_event(parent, LV_EVENT_CLICKED, NULL);
/*Should have received only 1 event: parent only*/
TEST_ASSERT_EQUAL(1, event_count);
/*Clean up*/
lv_obj_delete(parent);
}
#endif