Important: unclear posts may not receive useful answers.
Before posting
- Get familiar with Markdown to format and structure your post
- Be sure to update lvgl from the latest version from the
master
branch.- Be sure you have checked the FAQ and read the relevant part of the documentation.
- If applicable use the Simulator to eliminate hardware related issues.
Delete this section if you read and applied the mentioned points.
Description
What MCU/Processor/Board and compiler are you using?
What LVGL version are you using?
8.3.2
What do you want to achieve?
Add icons in every dropdown list items
What have you tried so far?
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
/*You code here*/
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.
Hi all, I would like to know how to add an image in every dropdown list items. Reading the doc of the widget from here:
https://docs.lvgl.io/8.3/widgets/core/dropdown.html
seems not possible when adding the options (lv_dropdown_add_option)
Could be possible during the LV_EVENT_DRAW_PART_BEGIN event?
I’ve tried the following code but with no luck…
lv_obj_t * dropdown_list = lv_dropdown_get_list(dropdown);
lv_obj_add_event_cb(dropdown_list, dropdown_list_callback, LV_EVENT_ALL, NULL);
then in the dropdown_list_callback:
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if (code == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_t * list1 = lv_obj_get_parent(obj);
lv_obj_t *icon = lv_img_create(list1);
lv_img_set_src(icon, my_icon);
lv_obj_align(icon, LV_ALIGN_LEFT_MID, 10, 0);
LV_LOG_USER("Clicked: %s", lv_list_get_btn_text(list1, obj));
uint32_t i;
for(i = 0; i < lv_obj_get_child_cnt(obj); i++) {
lv_obj_t * child = lv_obj_get_child(obj, i);
lv_obj_t *icon = lv_img_create(child);
lv_img_set_src(icon, LV_SYMBOL_WIFI);
lv_obj_align(icon, LV_ALIGN_LEFT_MID, 10, 0);
}
}
Many thanks!