acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_btnmatrix_1.c (1158B)

      1 #include "../../lv_examples.h"
      2 #if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES
      3 
      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 
     17 static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
     18                                   "6", "7", "8", "9", "0", "\n",
     19                                   "Action1", "Action2", ""
     20                                  };
     21 
     22 void lv_example_btnmatrix_1(void)
     23 {
     24     lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
     25     lv_btnmatrix_set_map(btnm1, btnm_map);
     26     lv_btnmatrix_set_btn_width(btnm1, 10, 2);        /*Make "Action1" twice as wide as "Action2"*/
     27     lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
     28     lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED);
     29     lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
     30     lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
     31 }
     32 
     33 #endif