1 #include "../../lv_examples.h"
2 #if LV_USE_BTNMATRIX  && LV_BUILD_EXAMPLES
3 
event_cb(lv_event_t * e)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  */
lv_example_btnmatrix_3(void)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     static lv_style_t style_btn;
38     lv_style_init(&style_btn);
39     lv_style_set_radius(&style_btn, 0);
40     lv_style_set_border_width(&style_btn, 1);
41     lv_style_set_border_opa(&style_btn, LV_OPA_50);
42     lv_style_set_border_color(&style_btn, lv_palette_main(LV_PALETTE_GREY));
43     lv_style_set_border_side(&style_btn, LV_BORDER_SIDE_INTERNAL);
44     lv_style_set_radius(&style_btn, 0);
45 
46     static const char * map[] = {LV_SYMBOL_LEFT, "1", "2", "3", "4", "5", LV_SYMBOL_RIGHT, ""};
47 
48     lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
49     lv_btnmatrix_set_map(btnm, map);
50     lv_obj_add_style(btnm, &style_bg, 0);
51     lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS);
52     lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_VALUE_CHANGED, NULL);
53     lv_obj_set_size(btnm, 225, 35);
54 
55     /*Allow selecting on one number at time*/
56     lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE);
57     lv_btnmatrix_clear_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
58     lv_btnmatrix_clear_btn_ctrl(btnm, 6, LV_BTNMATRIX_CTRL_CHECKABLE);
59 
60     lv_btnmatrix_set_one_checked(btnm, true);
61     lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED);
62 
63     lv_obj_center(btnm);
64 
65 }
66 
67 #endif
68