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 "../lv_conf_internal.h"
17
18 #if LV_USE_IMGBTN != 0
19
20 /*Testing of dependencies*/
21 #if LV_USE_BTN == 0
22 #error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (LV_USE_BTN 1) "
23 #endif
24
25 #include "../lv_core/lv_obj.h"
26 #include "lv_btn.h"
27 #include "../lv_draw/lv_draw_img.h"
28
29 /*********************
30 * DEFINES
31 *********************/
32
33 /**********************
34 * TYPEDEFS
35 **********************/
36 /*Data of image button*/
37 typedef struct {
38 lv_btn_ext_t btn; /*Ext. of ancestor*/
39 /*New data for this type */
40 const void * img_src_mid[_LV_BTN_STATE_LAST]; /*Store center images to each state*/
41 #if LV_IMGBTN_TILED
42 const void * img_src_left[_LV_BTN_STATE_LAST]; /*Store left side images to each state*/
43 const void * img_src_right[_LV_BTN_STATE_LAST]; /*Store right side images to each state*/
44 #endif
45 lv_img_cf_t act_cf; /*Color format of the currently active image*/
46 uint8_t tiled : 1; /*1: the middle src will be repeated to fill the user defined width*/
47 } lv_imgbtn_ext_t;
48
49 /*Parts of the image button*/
50 enum {
51 LV_IMGBTN_PART_MAIN = LV_BTN_PART_MAIN,
52 };
53 typedef uint8_t lv_imgbtn_part_t;
54
55 /**********************
56 * GLOBAL PROTOTYPES
57 **********************/
58
59 /**
60 * Create a image button objects
61 * @param par pointer to an object, it will be the parent of the new image button
62 * @param copy pointer to a image button object, if not NULL then the new object will be copied from
63 * it
64 * @return pointer to the created image button
65 */
66 lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy);
67
68 /*======================
69 * Add/remove functions
70 *=====================*/
71
72 /*=====================
73 * Setter functions
74 *====================*/
75
76 /**
77 * Set images for a state of the image button
78 * @param imgbtn pointer to an image button object
79 * @param state for which state set the new image (from `lv_btn_state_t`) `
80 * @param src pointer to an image source (a C array or path to a file)
81 */
82 void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src);
83
84 #if LV_IMGBTN_TILED
85 /**
86 * Set images for a state of the image button
87 * @param imgbtn pointer to an image button object
88 * @param state for which state set the new image (from `lv_btn_state_t`) `
89 * @param src_left pointer to an image source for the left side of the button (a C array or path to
90 * a file)
91 * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C
92 * array or path to a file)
93 * @param src_right pointer to an image source for the right side of the button (a C array or path
94 * to a file)
95 */
96 void lv_imgbtn_set_src_tiled(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid,
97 const void * src_right);
98
99 #endif
100
101 /**
102 * Enable the toggled states. On release the button will change from/to toggled state.
103 * @param imgbtn pointer to an image button object
104 * @param tgl true: enable toggled states, false: disable
105 */
lv_imgbtn_set_checkable(lv_obj_t * imgbtn,bool tgl)106 static inline void lv_imgbtn_set_checkable(lv_obj_t * imgbtn, bool tgl)
107 {
108 lv_btn_set_checkable(imgbtn, tgl);
109 }
110
111 /**
112 * Set the state of the image button
113 * @param imgbtn pointer to an image button object
114 * @param state the new state of the button (from lv_btn_state_t enum)
115 */
lv_imgbtn_set_state(lv_obj_t * imgbtn,lv_btn_state_t state)116 static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state)
117 {
118 lv_btn_set_state(imgbtn, state);
119 }
120
121 /**
122 * Toggle the state of the image button (ON->OFF, OFF->ON)
123 * @param imgbtn pointer to a image button object
124 */
lv_imgbtn_toggle(lv_obj_t * imgbtn)125 static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn)
126 {
127 lv_btn_toggle(imgbtn);
128 }
129
130 /*=====================
131 * Getter functions
132 *====================*/
133
134 #if LV_IMGBTN_TILED == 0
135 /**
136 * Get the images in a given state
137 * @param imgbtn pointer to an image button object
138 * @param state the state where to get the image (from `lv_btn_state_t`) `
139 * @return pointer to an image source (a C array or path to a file)
140 */
141 const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state);
142
143 #else
144
145 /**
146 * Get the left image in a given state
147 * @param imgbtn pointer to an image button object
148 * @param state the state where to get the image (from `lv_btn_state_t`) `
149 * @return pointer to the left image source (a C array or path to a file)
150 */
151 const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state);
152
153 /**
154 * Get the middle image in a given state
155 * @param imgbtn pointer to an image button object
156 * @param state the state where to get the image (from `lv_btn_state_t`) `
157 * @return pointer to the middle image source (a C array or path to a file)
158 */
159 const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state);
160
161 /**
162 * Get the right image in a given state
163 * @param imgbtn pointer to an image button object
164 * @param state the state where to get the image (from `lv_btn_state_t`) `
165 * @return pointer to the left image source (a C array or path to a file)
166 */
167 const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state);
168
169 #endif
170 /**
171 * Get the current state of the image button
172 * @param imgbtn pointer to a image button object
173 * @return the state of the button (from lv_btn_state_t enum)
174 */
lv_imgbtn_get_state(const lv_obj_t * imgbtn)175 static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn)
176 {
177 return lv_btn_get_state(imgbtn);
178 }
179
180 /**
181 * Get the toggle enable attribute of the image button
182 * @param imgbtn pointer to a image button object
183 * @return true: toggle enabled, false: disabled
184 */
lv_imgbtn_get_checkable(const lv_obj_t * imgbtn)185 static inline bool lv_imgbtn_get_checkable(const lv_obj_t * imgbtn)
186 {
187 return lv_btn_get_checkable(imgbtn);
188 }
189
190 /*=====================
191 * Other functions
192 *====================*/
193
194 /**********************
195 * MACROS
196 **********************/
197
198 #endif /*LV_USE_IMGBTN*/
199
200 #ifdef __cplusplus
201 } /* extern "C" */
202 #endif
203
204 #endif /*LV_IMGBTN_H*/
205