1 #include "../../lv_examples.h"
2 #if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES
3
event_handler(lv_event_t * e)4 static void event_handler(lv_event_t * e)
5 {
6 lv_event_code_t code = lv_event_get_code(e);
7 lv_obj_t * obj = lv_event_get_target(e);
8 if(code == LV_EVENT_VALUE_CHANGED) {
9 uint32_t id = lv_btnmatrix_get_selected_btn(obj);
10 const char * txt = lv_btnmatrix_get_btn_text(obj, id);
11
12 LV_LOG_USER("%s was pressed\n", txt);
13 }
14 }
15
16 static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
17 "6", "7", "8", "9", "0", "\n",
18 "Action1", "Action2", ""
19 };
20
lv_example_btnmatrix_1(void)21 void lv_example_btnmatrix_1(void)
22 {
23 lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
24 lv_btnmatrix_set_map(btnm1, btnm_map);
25 lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/
26 lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
27 lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED);
28 lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
29 lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
30 }
31
32 #endif
33