refactor(objid): rename lv_obj_get_child_by_id to lv_obj_find_by_id for consistency

This commit is contained in:
Gabor Kiss-Vamosi
2025-02-13 12:26:22 +01:00
committed by Liam Howatt
parent 626d6b51ad
commit 56c44bfdc4
9 changed files with 44 additions and 36 deletions
@@ -24,7 +24,7 @@ Once enabled, several things change:
- these two API functions become available:
- :cpp:expr:`lv_obj_get_id(widget)`,
- :cpp:expr:`lv_obj_get_child_by_id(widget, id)`;
- :cpp:expr:`lv_obj_find_by_id(widget, id)`;
- several more Widget-ID-related API functions become available if
:c:macro:`LV_USE_OBJ_ID_BUILTIN` is non-zero (more on this below);
@@ -182,7 +182,7 @@ state of the Widget Tree when :cpp:expr:`lv_obj_dump_tree(widget)` was called.
For example, if a pointer to a deleted Widget is stored in a Timer's
:cpp:expr:`timer->user_data` field when the timer event callback is called, attempted
use of that pointer will likly cause a crash because the pointer is not valid any
use of that pointer will likely cause a crash because the pointer is not valid any
more. However, a timely dump of the Widget Tree right before that point will show
that the Widget no longer exists.
@@ -190,7 +190,7 @@ that the Widget no longer exists.
Find child by ID
----------------
:cpp:expr:`lv_obj_get_child_by_id(widget, id)` will perform a recursive walk through
:cpp:expr:`lv_obj_find_by_id(widget, id)` will perform a recursive walk through
``widget``\ 's children and return the first child encountered having the given ID.
+2 -2
View File
@@ -436,7 +436,7 @@ void * lv_obj_get_id(const lv_obj_t * obj)
return obj->id;
}
lv_obj_t * lv_obj_get_child_by_id(const lv_obj_t * obj, const void * id)
lv_obj_t * lv_obj_find_by_id(const lv_obj_t * obj, const void * id)
{
LV_LOG_WARN("DEPRECATED: IDs are used only to print the widget trees. To find a widget use obj_name");
@@ -453,7 +453,7 @@ lv_obj_t * lv_obj_get_child_by_id(const lv_obj_t * obj, const void * id)
/*Search children*/
for(i = 0; i < child_cnt; i++) {
lv_obj_t * child = obj->spec_attr->children[i];
lv_obj_t * found = lv_obj_get_child_by_id(child, id);
lv_obj_t * found = lv_obj_find_by_id(child, id);
if(found != NULL) return found;
}
+1 -1
View File
@@ -407,7 +407,7 @@ void * lv_obj_get_id(const lv_obj_t * obj);
* @param id the id of the child object
* @return pointer to the child object or NULL if not found
*/
lv_obj_t * lv_obj_get_child_by_id(const lv_obj_t * obj, const void * id);
lv_obj_t * lv_obj_find_by_id(const lv_obj_t * obj, const void * id);
/**
* Assign id to object if not previously assigned.
+2
View File
@@ -77,6 +77,8 @@ extern "C" {
#define _lv_disp_refr_timer lv_disp_refr_timer
#define _lv_disp_get_refr_timer lv_disp_get_refr_timer
#define lv_obj_get_child_by_id lv_obj_find_by_id
#define _lv_inv_area lv_inv_area
#define lv_chart_set_all_value lv_chart_set_all_values
#define lv_calendar_set_showed_date lv_calendar_set_month_shown
+3 -1
View File
@@ -57,7 +57,9 @@ void lv_xml_obj_apply(lv_xml_parser_state_t * state, const char ** attrs)
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
#if LV_USE_OBJ_NAME
if(lv_streq("name", name)) lv_obj_set_name(item, value);
#endif
if(lv_streq("x", name)) lv_obj_set_x(item, lv_xml_to_size(value));
else if(lv_streq("y", name)) lv_obj_set_y(item, lv_xml_to_size(value));
else if(lv_streq("width", name)) lv_obj_set_width(item, lv_xml_to_size(value));
+2 -2
View File
@@ -122,7 +122,7 @@ const lv_obj_class_t lv_dropdown_class = {
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
.base_class = &lv_obj_class,
.name = "dropdown",
.name = "lv_dropdown",
#if LV_USE_OBJ_PROPERTY
.prop_index_start = LV_PROPERTY_DROPDOWN_START,
.prop_index_end = LV_PROPERTY_DROPDOWN_END,
@@ -142,7 +142,7 @@ const lv_obj_class_t lv_dropdownlist_class = {
.event_cb = lv_dropdown_list_event,
.instance_size = sizeof(lv_dropdown_list_t),
.base_class = &lv_obj_class,
.name = "dropdown-list",
.name = "lv_dropdown-list",
};
/**********************
+24 -24
View File
@@ -196,28 +196,28 @@ void test_obj_get_by_name(void)
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW);
lv_obj_t * cont1 = lv_obj_create(lv_screen_active());
lv_obj_set_name_static(cont1, "first_static");
lv_obj_set_name(cont1, "first_non_static");
lv_obj_set_name_static(cont1, "first");
lv_obj_t * cont0 = lv_obj_create(lv_screen_active());
lv_obj_set_name_static(cont0, "zero_static");
lv_obj_set_name(cont0, "zero_non_static");
lv_obj_set_name_static(cont0, "zero");
lv_obj_t * cont1 = lv_obj_create(lv_screen_active());
lv_obj_set_flex_flow(cont1, LV_FLEX_FLOW_COLUMN);
lv_obj_set_name(cont1, "first_non_static");
lv_obj_set_name(cont1, "first");
lv_obj_t * cont2 = lv_obj_create(lv_screen_active());
lv_obj_set_flex_flow(cont2, LV_FLEX_FLOW_COLUMN);
lv_obj_set_name(cont2, "second_non_static");
lv_obj_set_name(cont2, "second");
lv_obj_t * cont3 = lv_obj_create(lv_screen_active());
lv_obj_t * cont4 = lv_obj_create(lv_screen_active());
lv_obj_set_name_static(cont4, "forth_static");
lv_obj_set_name_static(cont4, "forth");
lv_obj_set_name_static(cont3, "third_static");
lv_obj_set_name_static(cont3, "third");
lv_obj_t * root_label = lv_label_create(lv_screen_active());
lv_label_set_text(root_label, "Root");
lv_obj_set_name(root_label, "my_label");
lv_slider_create(cont2);
lv_slider_create(cont1);
lv_obj_t * btn = lv_button_create(cont2);
lv_switch_create(cont2);
lv_obj_t * btn = lv_button_create(cont1);
lv_switch_create(cont1);
lv_obj_t * hello_label = lv_label_create(btn);
lv_label_set_text(hello_label, "Hello");
@@ -230,28 +230,28 @@ void test_obj_get_by_name(void)
* Get by name
*------------*/
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "second");
TEST_ASSERT_EQUAL(cont2, found_obj);
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "first");
TEST_ASSERT_EQUAL(cont1, found_obj);
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "lv_obj_3");
TEST_ASSERT_EQUAL(cont3, found_obj);
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "lv_obj_2");
TEST_ASSERT_EQUAL(cont2, found_obj);
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "fifth");
TEST_ASSERT_EQUAL(NULL, found_obj);
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "second/lv_button_1/my_label");
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "first/lv_button_0/my_label");
TEST_ASSERT_EQUAL(hello_label, found_obj);
/*"hello" label doesn't have children*/
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "second/lv_button_1/my_label/no_child");
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "first/lv_button_0/my_label/no_child");
TEST_ASSERT_EQUAL(NULL, found_obj);
/*Non existing child*/
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "second/lv_button_1/other_label");
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "first/lv_button_0/other_label");
TEST_ASSERT_EQUAL(NULL, found_obj);
/*Extra slash*/
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "second//lv_button_1/other_label");
found_obj = lv_obj_get_child_by_name(lv_screen_active(), "first//lv_button_0/other_label");
TEST_ASSERT_EQUAL(NULL, found_obj);
/*Empty*/
@@ -262,13 +262,13 @@ void test_obj_get_by_name(void)
* Find by name
*------------*/
found_obj = lv_obj_find_by_name(lv_screen_active(), "lv_obj_3");
TEST_ASSERT_EQUAL(cont3, found_obj);
found_obj = lv_obj_find_by_name(lv_screen_active(), "lv_obj_2");
TEST_ASSERT_EQUAL(cont2, found_obj);
found_obj = lv_obj_find_by_name(lv_screen_active(), "my_label");
TEST_ASSERT_EQUAL(root_label, found_obj);
found_obj = lv_obj_find_by_name(cont2, "my_label");
found_obj = lv_obj_find_by_name(cont1, "my_label");
TEST_ASSERT_EQUAL(hello_label, found_obj);
}
+2 -2
View File
@@ -37,8 +37,8 @@ void test_obj_id_get_child(void)
lv_obj_set_id(child, (void *)(lv_uintptr_t)1);
lv_obj_set_id(grandchild, (void *)(lv_uintptr_t)2);
TEST_ASSERT_EQUAL_PTR(child, lv_obj_get_child_by_id(NULL, (void *)(lv_uintptr_t)1));
TEST_ASSERT_EQUAL_PTR(grandchild, lv_obj_get_child_by_id(NULL, (void *)(lv_uintptr_t)2));
TEST_ASSERT_EQUAL_PTR(child, lv_obj_find_by_id(NULL, (void *)(lv_uintptr_t)1));
TEST_ASSERT_EQUAL_PTR(grandchild, lv_obj_find_by_id(NULL, (void *)(lv_uintptr_t)2));
}
#endif
+5 -1
View File
@@ -35,12 +35,16 @@ void test_xml_widget_direct_create(void)
"range_max", "100",
"mode", "symmetrical",
"value", "50",
"name", "my_slider",
NULL, NULL,
};
slider = lv_xml_create(lv_screen_active(), "lv_slider", attrs);
lv_obj_set_pos(slider, 10, 200);
#if LV_USE_OBJ_NAME
lv_obj_t * same_slider = lv_obj_get_child_by_name(lv_screen_active(), "my_slider");
TEST_ASSERT_EQUAL_PTR(slider, same_slider);
#endif
TEST_ASSERT_EQUAL_SCREENSHOT("xml/widget_create_1.png");
}