1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

feat(dropdown): add lv_anim_enable_t parameter to lv_dropddown_set_selected (#7310)

This commit is contained in:
André Costa 2025-01-06 15:40:23 +01:00 committed by GitHub
parent f27c65bf4a
commit 25232d92e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 23 additions and 21 deletions

View File

@ -33,7 +33,7 @@
for (i = 0; i < ARRAY_SIZE(flex_align_map); i++) { \
if (flex_align == flex_align_map[i]) { \
lv_dropdown_set_selected(ui->ctrl_pad.tab.align.ddlist_align_##item, \
i); \
i, LV_ANIM_OFF); \
break; \
} \
} \
@ -114,7 +114,7 @@ void flex_loader_obj_update(lv_obj_t * obj, view_t * ui)
uint32_t i;
for(i = 0; i < ARRAY_SIZE(flex_flow_map); i++) {
if(flex_flow == flex_flow_map[i]) {
lv_dropdown_set_selected(ui->ctrl_pad.tab.flex.ddlist_flow, i);
lv_dropdown_set_selected(ui->ctrl_pad.tab.flex.ddlist_flow, i, LV_ANIM_OFF);
break;
}
}

View File

@ -209,7 +209,7 @@ static void obj_test_task_cb(lv_timer_t * tmr)
obj = lv_dropdown_create(main_page);
lv_dropdown_set_options(obj, "Zero\nOne\nTwo\nThree\nFour\nFive\nSix\nSeven\nEight");
lv_dropdown_open(obj);
lv_dropdown_set_selected(obj, 2);
lv_dropdown_set_selected(obj, 2, LV_ANIM_ON);
auto_delete(obj, LV_DEMO_STRESS_TIME_STEP * 3 + 11);
break;

View File

@ -87,7 +87,7 @@ the options string's contents must remain available for the life of the Drop-Dow
List and :cpp:func:`lv_dropdown_add_option` cannot be used.
You can select an option programmatically with
:cpp:expr:`lv_dropdown_set_selected(dropdown, id)`, where ``id`` is the index of
:cpp:expr:`lv_dropdown_set_selected(dropdown, id, LV_ANIM_ON/LV_ANIM_OFF)`, where ``id`` is the index of
the target option.
Get selected option

View File

@ -264,9 +264,9 @@ void pika_lvgl_dropdown_set_dir(PikaObj *self, int dir){
lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj");
lv_dropdown_set_dir(lv_obj, dir);
}
void pika_lvgl_dropdown_set_selected(PikaObj *self, int sel_opt){
void pika_lvgl_dropdown_set_selected(PikaObj *self, int sel_opt, int anim){
lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj");
lv_dropdown_set_selected(lv_obj, sel_opt);
lv_dropdown_set_selected(lv_obj, sel_opt, anim);
}
void pika_lvgl_dropdown_set_selected_highlight(PikaObj *self, int en){
lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj");
@ -361,4 +361,4 @@ void pika_lvgl_textarea_set_one_line(PikaObj* self, int en) {
lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj");
lv_textarea_set_one_line(lv_obj, en);
}
#endif
#endif

View File

@ -757,7 +757,7 @@ static void dropdown_value_changed_event_cb(lv_event_t * e)
static void dropdown_value_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
{
lv_dropdown_set_selected(observer->target, subject->value.num);
lv_dropdown_set_selected(observer->target, subject->value.num, LV_ANIM_OFF);
}
#endif /*LV_USE_DROPDOWN*/

View File

@ -174,10 +174,10 @@ static void value_changed_event_cb(lv_event_t * e)
const uint32_t year = (year_p[0] - '0') * 1000 + (year_p[1] - '0') * 100 + (year_p[2] - '0') * 10 +
(year_p[3] - '0');
lv_dropdown_set_selected(year_dd, year - cur_date->year);
lv_dropdown_set_selected(year_dd, year - cur_date->year, LV_ANIM_OFF);
lv_obj_t * month_dd = lv_obj_get_child(header, 1);
lv_dropdown_set_selected(month_dd, cur_date->month - 1);
lv_dropdown_set_selected(month_dd, cur_date->month - 1, LV_ANIM_OFF);
}
#endif /*LV_USE_CALENDAR_HEADER_ARROW*/

View File

@ -336,7 +336,7 @@ void lv_dropdown_clear_options(lv_obj_t * obj)
if(dropdown->list) lv_obj_invalidate(dropdown->list);
}
void lv_dropdown_set_selected(lv_obj_t * obj, uint32_t sel_opt)
void lv_dropdown_set_selected(lv_obj_t * obj, uint32_t sel_opt, lv_anim_enable_t anim)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
@ -347,7 +347,7 @@ void lv_dropdown_set_selected(lv_obj_t * obj, uint32_t sel_opt)
dropdown->sel_opt_id_orig = dropdown->sel_opt_id;
if(dropdown->list) {
position_to_selected(obj, LV_ANIM_OFF);
position_to_selected(obj, anim);
}
lv_obj_invalidate(obj);

View File

@ -36,8 +36,8 @@ enum {
LV_PROPERTY_ID(DROPDOWN, TEXT, LV_PROPERTY_TYPE_TEXT, 0),
LV_PROPERTY_ID(DROPDOWN, OPTIONS, LV_PROPERTY_TYPE_TEXT, 1),
LV_PROPERTY_ID(DROPDOWN, OPTION_COUNT, LV_PROPERTY_TYPE_INT, 2),
LV_PROPERTY_ID(DROPDOWN, SELECTED, LV_PROPERTY_TYPE_INT, 3),
// LV_PROPERTY_ID(DROPDOWN, SELECTED_STR, LV_PROPERTY_TYPE_TEXT, 4),
LV_PROPERTY_ID2(DROPDOWN, SELECTED, LV_PROPERTY_TYPE_INT, LV_PROPERTY_TYPE_BOOL, 3),
LV_PROPERTY_ID(DROPDOWN, DIR, LV_PROPERTY_TYPE_INT, 5),
LV_PROPERTY_ID(DROPDOWN, SYMBOL, LV_PROPERTY_TYPE_TEXT, 6),
LV_PROPERTY_ID(DROPDOWN, SELECTED_HIGHLIGHT, LV_PROPERTY_TYPE_INT, 7),
@ -108,8 +108,9 @@ void lv_dropdown_clear_options(lv_obj_t * obj);
* Set the selected option
* @param obj pointer to drop-down list object
* @param sel_opt id of the selected option (0 ... number of option - 1);
* @param anim LV_ANIM_ON: set the selected option with an animation; LV_ANIM_OFF: set the option immediately
*/
void lv_dropdown_set_selected(lv_obj_t * obj, uint32_t sel_opt);
void lv_dropdown_set_selected(lv_obj_t * obj, uint32_t sel_opt, lv_anim_enable_t anim);
/**
* Set the direction of the a drop-down list

View File

@ -118,7 +118,7 @@ void test_dropdown_set_options(void)
void test_dropdown_select(void)
{
lv_obj_t * dd1 = lv_dropdown_create(lv_screen_active());
lv_dropdown_set_selected(dd1, 2);
lv_dropdown_set_selected(dd1, 2, LV_ANIM_OFF);
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
@ -132,7 +132,7 @@ void test_dropdown_select(void)
TEST_ASSERT_EQUAL_STRING("Opt", buf);
/*Out of range*/
lv_dropdown_set_selected(dd1, 3);
lv_dropdown_set_selected(dd1, 3, LV_ANIM_OFF);
TEST_ASSERT_EQUAL(2, lv_dropdown_get_selected(dd1));
}
@ -324,12 +324,12 @@ void test_dropdown_render_1(void)
lv_obj_t * dd1 = lv_dropdown_create(lv_screen_active());
lv_obj_set_pos(dd1, 10, 10);
lv_dropdown_set_selected(dd1, 1);
lv_dropdown_set_selected(dd1, 1, LV_ANIM_OFF);
lv_obj_t * dd2 = lv_dropdown_create(lv_screen_active());
lv_obj_set_pos(dd2, 200, 10);
lv_obj_set_width(dd2, 200);
lv_dropdown_set_selected(dd2, 2);
lv_dropdown_set_selected(dd2, 2, LV_ANIM_OFF);
lv_dropdown_open(dd2);
TEST_ASSERT_TRUE(lv_dropdown_get_selected_highlight(dd2));
lv_dropdown_set_selected_highlight(dd2, false);
@ -343,7 +343,7 @@ void test_dropdown_render_1(void)
lv_dropdown_set_text(dd3, "A text");
TEST_ASSERT_EQUAL_STRING("A text", lv_dropdown_get_text(dd3));
lv_dropdown_set_selected(dd3, 2);
lv_dropdown_set_selected(dd3, 2, LV_ANIM_OFF);
TEST_ASSERT_EQUAL(LV_DIR_BOTTOM, lv_dropdown_get_dir(dd3));
lv_dropdown_set_dir(dd3, LV_DIR_LEFT);
@ -358,7 +358,7 @@ void test_dropdown_render_1(void)
lv_obj_t * list = lv_dropdown_get_list(dd3);
lv_obj_set_style_text_line_space(list, 5, 0);
lv_obj_set_style_bg_color(list, lv_color_hex3(0xf00), LV_PART_SELECTED | LV_STATE_CHECKED);
lv_dropdown_set_selected(dd3, 3);
lv_dropdown_set_selected(dd3, 3, LV_ANIM_OFF);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/dropdown_1.png");
}
@ -475,7 +475,8 @@ void test_dropdown_properties(void)
TEST_ASSERT_EQUAL(2, lv_obj_get_property(obj, LV_PROPERTY_DROPDOWN_OPTION_COUNT).num);
prop.id = LV_PROPERTY_DROPDOWN_SELECTED;
prop.num = 1;
prop.arg1.num = 1;
prop.arg2.enable = LV_ANIM_OFF;
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
TEST_ASSERT_EQUAL_INT(1, lv_dropdown_get_selected(obj));
TEST_ASSERT_EQUAL_INT(1, lv_obj_get_property(obj, LV_PROPERTY_DROPDOWN_SELECTED).num);