2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-14 14:56:34 +01:00
|
|
|
#if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-04-14 15:31:54 +02:00
|
|
|
static void event_handler(lv_event_t * e)
|
2021-02-08 09:53:03 +01:00
|
|
|
{
|
2021-04-14 15:31:54 +02:00
|
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
|
|
lv_obj_t * obj = lv_event_get_target(e);
|
|
|
|
if(code == LV_EVENT_VALUE_CHANGED) {
|
2021-02-24 09:55:47 +01:00
|
|
|
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
|
2021-02-08 09:53:03 +01:00
|
|
|
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
|
|
|
|
|
2021-02-14 14:56:34 +01:00
|
|
|
LV_LOG_USER("%s was pressed\n", txt);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
|
|
|
|
"6", "7", "8", "9", "0", "\n",
|
|
|
|
"Action1", "Action2", ""};
|
|
|
|
|
|
|
|
void lv_example_btnmatrix_1(void)
|
|
|
|
{
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_btnmatrix_set_map(btnm1, btnm_map);
|
|
|
|
lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/
|
|
|
|
lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
|
|
|
|
lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
|
2021-04-19 11:15:28 +02:00
|
|
|
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|