1 /**
2  * @file lv_imgbtn.h
3  *
4  */
5 
6 #ifndef LV_IMGBTN_H
7 #define LV_IMGBTN_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../../../lvgl.h"
17 
18 #if LV_USE_IMGBTN != 0
19 
20 /*********************
21  *      DEFINES
22  *********************/
23 typedef enum {
24     LV_IMGBTN_STATE_RELEASED,
25     LV_IMGBTN_STATE_PRESSED,
26     LV_IMGBTN_STATE_DISABLED,
27     LV_IMGBTN_STATE_CHECKED_RELEASED,
28     LV_IMGBTN_STATE_CHECKED_PRESSED,
29     LV_IMGBTN_STATE_CHECKED_DISABLED,
30     _LV_IMGBTN_STATE_NUM,
31 } lv_imgbtn_state_t;
32 
33 /**********************
34  *      TYPEDEFS
35  **********************/
36 /*Data of image button*/
37 typedef struct {
38     lv_obj_t obj;
39     const void * img_src_mid[_LV_IMGBTN_STATE_NUM];   /*Store center images to each state*/
40     const void * img_src_left[_LV_IMGBTN_STATE_NUM];  /*Store left side images to each state*/
41     const void * img_src_right[_LV_IMGBTN_STATE_NUM]; /*Store right side images to each state*/
42     lv_img_cf_t act_cf; /*Color format of the currently active image*/
43 } lv_imgbtn_t;
44 
45 extern const lv_obj_class_t lv_imgbtn_class;
46 
47 /**********************
48  * GLOBAL PROTOTYPES
49  **********************/
50 
51 /**
52  * Create an image button object
53  * @param parent pointer to an object, it will be the parent of the new image button
54  * @return pointer to the created image button
55  */
56 lv_obj_t * lv_imgbtn_create(lv_obj_t * parent);
57 
58 /*======================
59  * Add/remove functions
60  *=====================*/
61 
62 /*=====================
63  * Setter functions
64  *====================*/
65 
66 /**
67  * Set images for a state of the image button
68  * @param imgbtn pointer to an image button object
69  * @param state for which state set the new image
70  * @param src_left pointer to an image source for the left side of the button (a C array or path to
71  * a file)
72  * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C
73  * array or path to a file)
74  * @param src_right pointer to an image source for the right side of the button (a C array or path
75  * to a file)
76  */
77 void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_imgbtn_state_t state, const void * src_left, const void * src_mid,
78                        const void * src_right);
79 
80 /**
81  * Use this function instead of `lv_obj_add/clear_state` to set a state manually
82  * @param imgbtn pointer to an image button object
83  * @param state  the new state
84  */
85 void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_imgbtn_state_t state);
86 
87 /*=====================
88  * Getter functions
89  *====================*/
90 
91 /**
92  * Get the left image in a given state
93  * @param imgbtn pointer to an image button object
94  * @param state the state where to get the image (from `lv_btn_state_t`) `
95  * @return pointer to the left image source (a C array or path to a file)
96  */
97 const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_imgbtn_state_t state);
98 
99 /**
100  * Get the middle image in a given state
101  * @param imgbtn pointer to an image button object
102  * @param state the state where to get the image (from `lv_btn_state_t`) `
103  * @return pointer to the middle image source (a C array or path to a file)
104  */
105 const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_imgbtn_state_t state);
106 
107 /**
108  * Get the right image in a given state
109  * @param imgbtn pointer to an image button object
110  * @param state the state where to get the image (from `lv_btn_state_t`) `
111  * @return pointer to the left image source (a C array or path to a file)
112  */
113 const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_imgbtn_state_t state);
114 
115 /*=====================
116  * Other functions
117  *====================*/
118 
119 /**********************
120  *      MACROS
121  **********************/
122 
123 #endif /*LV_USE_IMGBTN*/
124 
125 #ifdef __cplusplus
126 } /*extern "C"*/
127 #endif
128 
129 #endif /*LV_IMGBTN_H*/
130