1 #include "../../lv_examples.h"
2 #if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES
3 
event_cb(lv_event_t * e)4 static void event_cb(lv_event_t * e)
5 {
6     lv_obj_t * dropdown = lv_event_get_target(e);
7     char buf[64];
8     lv_dropdown_get_selected_str(dropdown, buf, sizeof(buf));
9     LV_LOG_USER("'%s' is selected", buf);
10 }
11 
12 /**
13  * Create a menu from a drop-down list and show some drop-down list features and styling
14  */
lv_example_dropdown_3(void)15 void lv_example_dropdown_3(void)
16 {
17     /*Create a drop down list*/
18     lv_obj_t * dropdown = lv_dropdown_create(lv_scr_act());
19     lv_obj_align(dropdown, LV_ALIGN_TOP_LEFT, 10, 10);
20     lv_dropdown_set_options(dropdown, "New project\n"
21                                       "New file\n"
22                                       "Save\n"
23                                       "Save as ...\n"
24                                       "Open project\n"
25                                       "Recent projects\n"
26                                       "Preferences\n"
27                                       "Exit");
28 
29     /*Set a fixed text to display on the button of the drop-down list*/
30     lv_dropdown_set_text(dropdown, "Menu");
31 
32     /*Use a custom image as down icon and flip it when the list is opened*/
33     LV_IMG_DECLARE(img_caret_down)
34     lv_dropdown_set_symbol(dropdown, &img_caret_down);
35     lv_obj_set_style_transform_angle(dropdown, 1800, LV_PART_INDICATOR | LV_STATE_CHECKED);
36 
37     /*In a menu we don't need to show the last clicked item*/
38     lv_dropdown_set_selected_highlight(dropdown, false);
39 
40     lv_obj_add_event_cb(dropdown, event_cb, LV_EVENT_VALUE_CHANGED, NULL);
41 }
42 
43 #endif
44