mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
31 lines
1.0 KiB
C
31 lines
1.0 KiB
C
#include "../../../lvgl.h"
|
|
#if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES
|
|
|
|
static void event_handler(lv_obj_t * obj, lv_event_t event)
|
|
{
|
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
|
uint32_t id = lv_btnmatrix_get_active_btn(obj);
|
|
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
|
|
|
|
LV_LOG_USER("%s was pressed\n", txt);
|
|
}
|
|
}
|
|
|
|
|
|
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)
|
|
{
|
|
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act(), NULL);
|
|
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);
|
|
lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 0);
|
|
lv_obj_add_event_cb(btnm1, event_handler, NULL);
|
|
}
|
|
|
|
#endif
|