fix(dropdown) be sure the list is the top object on the screen

fixes #2893
This commit is contained in:
Gabor Kiss-Vamosi
2021-12-13 20:26:24 +01:00
parent 6de89e4b7b
commit cb7fc2bb59
4 changed files with 34 additions and 10 deletions

View File

@@ -188,6 +188,10 @@ void lv_obj_move_to_index(lv_obj_t * obj, int32_t index)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); 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); const int32_t old_index = lv_obj_get_index(obj);
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_t * parent = lv_obj_get_parent(obj);

View File

@@ -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. * moves the object to the given index in its parent.
* When used in listboxes, it can be used to sort the listbox items. * When used in listboxes, it can be used to sort the listbox items.
* @param obj pointer to the object to be moved. * @param obj pointer to the object to be moved.
* @param index new index in parent. * @param index new index in parent. -1 to count from the back
* @note to move to the foreground: lv_obj_move_to_index(obj, 0) * @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) * @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); void lv_obj_move_to_index(struct _lv_obj_t * obj, int32_t index);

View File

@@ -422,6 +422,8 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
lv_dropdown_t * dropdown = (lv_dropdown_t *)dropdown_obj; lv_dropdown_t * dropdown = (lv_dropdown_t *)dropdown_obj;
lv_obj_add_state(dropdown_obj, LV_STATE_CHECKED); 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); lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_HIDDEN);
/*To allow styling the list*/ /*To allow styling the list*/

View File

@@ -4,15 +4,16 @@
#include "unity/unity.h" #include "unity/unity.h"
#include "lv_test_indev.h" #include "lv_test_indev.h"
void test_dropdown_create_delete(void); void setUp(void)
void test_dropdown_set_options(void); {
void test_dropdown_select(void); /* Function run before every test */
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 tearDown(void)
{
/* Function run after every test */
lv_obj_clean(lv_scr_act());
}
void test_dropdown_create_delete(void) void test_dropdown_create_delete(void)
{ {
lv_dropdown_create(lv_scr_act()); lv_dropdown_create(lv_scr_act());
@@ -422,6 +423,23 @@ void test_dropdown_render_2(void)
TEST_ASSERT_EQUAL_SCREENSHOT("dropdown_2.png"); 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 #endif