2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-14 14:56:34 +01:00
|
|
|
#if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-04-14 15:31:54 +02:00
|
|
|
static void event_cb(lv_event_t * e)
|
2021-02-27 20:34:08 +01:00
|
|
|
{
|
2021-04-14 15:31:54 +02:00
|
|
|
lv_obj_t * dropdown = lv_event_get_target(e);
|
2021-04-19 11:15:28 +02:00
|
|
|
char buf[64];
|
|
|
|
lv_dropdown_get_selected_str(dropdown, buf, sizeof(buf));
|
|
|
|
LV_LOG_USER("'%s' is selected", buf);
|
2021-02-27 20:34:08 +01:00
|
|
|
}
|
|
|
|
|
2021-02-08 09:53:03 +01:00
|
|
|
/**
|
|
|
|
* Create a menu from a drop-down list and show some drop-down list features and styling
|
|
|
|
*/
|
|
|
|
void lv_example_dropdown_3(void)
|
|
|
|
{
|
|
|
|
/*Create a drop down list*/
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * dropdown = lv_dropdown_create(lv_screen_active());
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(dropdown, LV_ALIGN_TOP_LEFT, 10, 10);
|
2021-02-27 20:34:08 +01:00
|
|
|
lv_dropdown_set_options(dropdown, "New project\n"
|
2022-02-13 13:59:17 -05:00
|
|
|
"New file\n"
|
|
|
|
"Save\n"
|
|
|
|
"Save as ...\n"
|
|
|
|
"Open project\n"
|
|
|
|
"Recent projects\n"
|
|
|
|
"Preferences\n"
|
|
|
|
"Exit");
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
/*Set a fixed text to display on the button of the drop-down list*/
|
2021-02-27 20:34:08 +01:00
|
|
|
lv_dropdown_set_text(dropdown, "Menu");
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-02-27 20:34:08 +01:00
|
|
|
/*Use a custom image as down icon and flip it when the list is opened*/
|
2023-11-15 14:08:03 +01:00
|
|
|
LV_IMAGE_DECLARE(img_caret_down);
|
2021-02-27 20:34:08 +01:00
|
|
|
lv_dropdown_set_symbol(dropdown, &img_caret_down);
|
2023-09-18 22:57:30 +02:00
|
|
|
lv_obj_set_style_transform_rotation(dropdown, 1800, LV_PART_INDICATOR | LV_STATE_CHECKED);
|
2021-02-27 20:34:08 +01:00
|
|
|
|
2021-03-15 02:03:27 +08:00
|
|
|
/*In a menu we don't need to show the last clicked item*/
|
2021-02-27 20:34:08 +01:00
|
|
|
lv_dropdown_set_selected_highlight(dropdown, false);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2023-02-20 20:50:58 +01:00
|
|
|
lv_obj_add_event(dropdown, event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|