1 #include "../../lv_examples.h"
2 #if LV_USE_LIST && LV_BUILD_EXAMPLES
3 static lv_obj_t * list1;
4
event_handler(lv_event_t * e)5 static void event_handler(lv_event_t * e)
6 {
7 lv_event_code_t code = lv_event_get_code(e);
8 lv_obj_t * obj = lv_event_get_target(e);
9 if(code == LV_EVENT_CLICKED) {
10 LV_LOG_USER("Clicked: %s", lv_list_get_btn_text(list1, obj));
11 }
12 }
13
lv_example_list_1(void)14 void lv_example_list_1(void)
15 {
16 /*Create a list*/
17 list1 = lv_list_create(lv_scr_act());
18 lv_obj_set_size(list1, 180, 220);
19 lv_obj_center(list1);
20
21 /*Add buttons to the list*/
22 lv_obj_t * btn;
23
24 lv_list_add_text(list1, "File");
25 btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "New");
26 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
27 btn = lv_list_add_btn(list1, LV_SYMBOL_DIRECTORY, "Open");
28 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
29 btn = lv_list_add_btn(list1, LV_SYMBOL_SAVE, "Save");
30 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
31 btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Delete");
32 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
33 btn = lv_list_add_btn(list1, LV_SYMBOL_EDIT, "Edit");
34 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
35
36 lv_list_add_text(list1, "Connectivity");
37 btn = lv_list_add_btn(list1, LV_SYMBOL_BLUETOOTH, "Bluetooth");
38 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
39 btn = lv_list_add_btn(list1, LV_SYMBOL_GPS, "Navigation");
40 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
41 btn = lv_list_add_btn(list1, LV_SYMBOL_USB, "USB");
42 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
43 btn = lv_list_add_btn(list1, LV_SYMBOL_BATTERY_FULL, "Battery");
44 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
45
46 lv_list_add_text(list1, "Exit");
47 btn = lv_list_add_btn(list1, LV_SYMBOL_OK, "Apply");
48 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
49 btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Close");
50 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
51 }
52
53 #endif
54