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_3.c (2209B)
1 #include "../../lv_examples.h" 2 #if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES 3 4 static void event_cb(lv_event_t * e) 5 { 6 lv_obj_t * obj = lv_event_get_target(e); 7 uint32_t id = lv_btnmatrix_get_selected_btn(obj); 8 bool prev = id == 0 ? true : false; 9 bool next = id == 6 ? true : false; 10 if(prev || next) { 11 /*Find the checked button*/ 12 uint32_t i; 13 for(i = 1; i < 7; i++) { 14 if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break; 15 } 16 17 if(prev && i > 1) i--; 18 else if(next && i < 5) i++; 19 20 lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED); 21 } 22 } 23 24 /** 25 * Make a button group (pagination) 26 */ 27 void lv_example_btnmatrix_3(void) 28 { 29 static lv_style_t style_bg; 30 lv_style_init(&style_bg); 31 lv_style_set_pad_all(&style_bg, 0); 32 lv_style_set_pad_gap(&style_bg, 0); 33 lv_style_set_clip_corner(&style_bg, true); 34 lv_style_set_radius(&style_bg, LV_RADIUS_CIRCLE); 35 lv_style_set_border_width(&style_bg, 0); 36 37 38 static lv_style_t style_btn; 39 lv_style_init(&style_btn); 40 lv_style_set_radius(&style_btn, 0); 41 lv_style_set_border_width(&style_btn, 1); 42 lv_style_set_border_opa(&style_btn, LV_OPA_50); 43 lv_style_set_border_color(&style_btn, lv_palette_main(LV_PALETTE_GREY)); 44 lv_style_set_border_side(&style_btn, LV_BORDER_SIDE_INTERNAL); 45 lv_style_set_radius(&style_btn, 0); 46 47 static const char * map[] = {LV_SYMBOL_LEFT, "1", "2", "3", "4", "5", LV_SYMBOL_RIGHT, ""}; 48 49 lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act()); 50 lv_btnmatrix_set_map(btnm, map); 51 lv_obj_add_style(btnm, &style_bg, 0); 52 lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS); 53 lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_VALUE_CHANGED, NULL); 54 lv_obj_set_size(btnm, 225, 35); 55 56 /*Allow selecting on one number at time*/ 57 lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE); 58 lv_btnmatrix_clear_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); 59 lv_btnmatrix_clear_btn_ctrl(btnm, 6, LV_BTNMATRIX_CTRL_CHECKABLE); 60 61 lv_btnmatrix_set_one_checked(btnm, true); 62 lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); 63 64 lv_obj_center(btnm); 65 66 } 67 68 #endif