diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index 3adf72183..a5ab375d7 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -188,6 +188,10 @@ void lv_obj_move_to_index(lv_obj_t * obj, int32_t index) { LV_ASSERT_OBJ(obj, MY_CLASS); + if(index < 0) { + index = lv_obj_get_child_cnt(lv_obj_get_parent(obj)) + index; + } + const int32_t old_index = lv_obj_get_index(obj); lv_obj_t * parent = lv_obj_get_parent(obj); diff --git a/src/core/lv_obj_tree.h b/src/core/lv_obj_tree.h index 1c714c420..bee9e1604 100644 --- a/src/core/lv_obj_tree.h +++ b/src/core/lv_obj_tree.h @@ -97,8 +97,8 @@ void lv_obj_swap(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2); * moves the object to the given index in its parent. * When used in listboxes, it can be used to sort the listbox items. * @param obj pointer to the object to be moved. - * @param index new index in parent. - * @note to move to the foreground: lv_obj_move_to_index(obj, 0) + * @param index new index in parent. -1 to count from the back + * @note to move to the background: lv_obj_move_to_index(obj, 0) * @note to move forward (up): lv_obj_move_to_index(obj, lv_obj_get_index(obj) - 1) */ void lv_obj_move_to_index(struct _lv_obj_t * obj, int32_t index); diff --git a/src/widgets/lv_dropdown.c b/src/widgets/lv_dropdown.c index 724b25500..6b7906ffd 100644 --- a/src/widgets/lv_dropdown.c +++ b/src/widgets/lv_dropdown.c @@ -422,6 +422,8 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) lv_dropdown_t * dropdown = (lv_dropdown_t *)dropdown_obj; lv_obj_add_state(dropdown_obj, LV_STATE_CHECKED); + lv_obj_set_parent(dropdown->list, lv_obj_get_screen(dropdown_obj)); + lv_obj_move_to_index(dropdown->list, -1); lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_HIDDEN); /*To allow styling the list*/ diff --git a/tests/src/test_cases/test_dropdown.c b/tests/src/test_cases/test_dropdown.c index 8429df887..07a258693 100644 --- a/tests/src/test_cases/test_dropdown.c +++ b/tests/src/test_cases/test_dropdown.c @@ -4,15 +4,16 @@ #include "unity/unity.h" #include "lv_test_indev.h" -void test_dropdown_create_delete(void); -void test_dropdown_set_options(void); -void test_dropdown_select(void); -void test_dropdown_click(void); -void test_dropdown_keypad(void); -void test_dropdown_encoder(void); -void test_dropdown_render_1(void); -void test_dropdown_render_2(void); +void setUp(void) +{ + /* Function run before every test */ +} +void tearDown(void) +{ + /* Function run after every test */ + lv_obj_clean(lv_scr_act()); +} void test_dropdown_create_delete(void) { lv_dropdown_create(lv_scr_act()); @@ -422,6 +423,23 @@ void test_dropdown_render_2(void) TEST_ASSERT_EQUAL_SCREENSHOT("dropdown_2.png"); } +/* See #2893 */ +void test_dropdown_should_list_on_top(void) +{ + lv_obj_t * cont1 = lv_obj_create(lv_scr_act()); + lv_obj_set_size(cont1, 200, 100); + + lv_obj_t * dd = lv_dropdown_create(cont1); + + lv_obj_t * cont2 = lv_obj_create(lv_scr_act()); + lv_obj_set_size(cont2, 200, 100); + lv_obj_set_pos(cont2, 0, 100); + + lv_dropdown_open(dd); + lv_obj_t * list = lv_dropdown_get_list(dd); + TEST_ASSERT_EQUAL_PTR(lv_scr_act(), lv_obj_get_parent(list)); + TEST_ASSERT_EQUAL_INT(2, lv_obj_get_index(list)); +} #endif