mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 19:15:38 +08:00
refactor(objid): rename lv_obj_get_child_by_id to lv_obj_find_by_id for consistency
This commit is contained in:
committed by
Liam Howatt
parent
626d6b51ad
commit
56c44bfdc4
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user