Fixes bug where multiple events with same callback couldn't be removed in single call. (#8706)

This commit is contained in:
Master Chou
2025-08-22 08:25:36 +08:00
committed by GitHub
parent 989ac6cc15
commit ca7345d8da
2 changed files with 40 additions and 2 deletions
+5 -2
View File
@@ -142,8 +142,11 @@ uint32_t lv_obj_remove_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb)
uint32_t event_cnt = lv_obj_get_event_count(obj);
uint32_t removed_count = 0;
uint32_t i;
for(i = 0; i < event_cnt; i++) {
int32_t i;
if(event_cnt == 0) return 0;
for(i = event_cnt - 1; i >= 0; i--) {
lv_event_dsc_t * dsc = lv_obj_get_event_dsc(obj, i);
if(dsc && dsc->cb == event_cb) {
lv_obj_remove_event(obj, i);
+35
View File
@@ -142,4 +142,39 @@ void test_event_delete_obj_in_recursive_event_call(void)
lv_test_mouse_click_at(30, 30);
}
// Test event callback function
static void test_event_cb_1(lv_event_t * e)
{
LV_UNUSED(e);
}
void test_event_remove_event_cb(void)
{
lv_obj_t * obj = lv_obj_create(lv_screen_active());
// Register the same callback function twice with different event types
lv_obj_add_event_cb(obj, test_event_cb_1, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(obj, test_event_cb_1, LV_EVENT_PRESSED, NULL);
// Check event count after adding
uint32_t event_count_after_add = lv_obj_get_event_count(obj);
// Verify that 2 events were added
TEST_ASSERT_EQUAL_UINT32(2, event_count_after_add);
// Remove all events with test_event_cb_1 callback
uint32_t removed_count = lv_obj_remove_event_cb(obj, test_event_cb_1);
// Verify that 2 events were removed
TEST_ASSERT_EQUAL_UINT32(2, removed_count);
// Check event count after removal
uint32_t event_count_after_remove = lv_obj_get_event_count(obj);
// Verify that all events were removed
TEST_ASSERT_EQUAL_UINT32(0, event_count_after_remove);
lv_obj_delete(obj);
}
#endif