Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_imgbtn.h
1476 views
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
#ifdef LV_CONF_INCLUDE_SIMPLE
17
#include "lv_conf.h"
18
#else
19
#include "../../lv_conf.h"
20
#endif
21
22
#if USE_LV_IMGBTN != 0
23
24
/*Testing of dependencies*/
25
#if USE_LV_BTN == 0
26
#error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) "
27
#endif
28
29
#include "../lv_core/lv_obj.h"
30
#include "lv_btn.h"
31
#include "../lv_draw/lv_draw_img.h"
32
33
/*********************
34
* DEFINES
35
*********************/
36
37
/**********************
38
* TYPEDEFS
39
**********************/
40
/*Data of image button*/
41
typedef struct {
42
lv_btn_ext_t btn; /*Ext. of ancestor*/
43
/*New data for this type */
44
int idx;
45
#if LV_IMGBTN_TILED == 0
46
const void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/
47
#else
48
const void * img_src_left[LV_BTN_STATE_NUM]; /*Store left side images to each state*/
49
const void * img_src_mid[LV_BTN_STATE_NUM]; /*Store center images to each state*/
50
const void * img_src_right[LV_BTN_STATE_NUM]; /*Store right side images to each state*/
51
#endif
52
lv_img_cf_t act_cf; /*Color format of the currently active image*/
53
} lv_imgbtn_ext_t;
54
55
56
/*Styles*/
57
enum {
58
LV_IMGBTN_STYLE_REL,
59
LV_IMGBTN_STYLE_PR,
60
LV_IMGBTN_STYLE_TGL_REL,
61
LV_IMGBTN_STYLE_TGL_PR,
62
LV_IMGBTN_STYLE_INA,
63
};
64
typedef uint8_t lv_imgbtn_style_t;
65
66
67
/**********************
68
* GLOBAL PROTOTYPES
69
**********************/
70
71
/**
72
* Create a image button objects
73
* @param par pointer to an object, it will be the parent of the new image button
74
* @param copy pointer to a image button object, if not NULL then the new object will be copied from it
75
* @return pointer to the created image button
76
*/
77
lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy);
78
79
/*======================
80
* Add/remove functions
81
*=====================*/
82
83
84
/*=====================
85
* Setter functions
86
*====================*/
87
88
#if LV_IMGBTN_TILED == 0
89
/**
90
* Set images for a state of the image button
91
* @param imgbtn pointer to an image button object
92
* @param state for which state set the new image (from `lv_btn_state_t`) `
93
* @param src pointer to an image source (a C array or path to a file)
94
*/
95
void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src);
96
#else
97
/**
98
* Set images for a state of the image button
99
* @param imgbtn pointer to an image button object
100
* @param state for which state set the new image (from `lv_btn_state_t`) `
101
* @param src_left pointer to an image source for the left side of the button (a C array or path to a file)
102
* @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file)
103
* @param src_right pointer to an image source for the right side of the button (a C array or path to a file)
104
*/
105
void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right);
106
107
#endif
108
109
/**
110
* Enable the toggled states. On release the button will change from/to toggled state.
111
* @param imgbtn pointer to an image button object
112
* @param tgl true: enable toggled states, false: disable
113
*/
114
static inline void lv_imgbtn_set_toggle(lv_obj_t * imgbtn, bool tgl)
115
{
116
lv_btn_set_toggle(imgbtn, tgl);
117
}
118
119
/**
120
* Set the state of the image button
121
* @param imgbtn pointer to an image button object
122
* @param state the new state of the button (from lv_btn_state_t enum)
123
*/
124
static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state)
125
{
126
lv_btn_set_state(imgbtn, state);
127
}
128
129
/**
130
* Toggle the state of the image button (ON->OFF, OFF->ON)
131
* @param imgbtn pointer to a image button object
132
*/
133
static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn)
134
{
135
lv_btn_toggle(imgbtn);
136
}
137
138
/**
139
* Set a function to call when a button event happens
140
* @param imgbtn pointer to an image button object
141
* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)
142
*/
143
static inline void lv_imgbtn_set_action(lv_obj_t * imgbtn, lv_btn_action_t type, lv_action_t action)
144
{
145
lv_btn_set_action(imgbtn, type, action);
146
}
147
148
/**
149
* Set a style of a image button.
150
* @param imgbtn pointer to image button object
151
* @param type which style should be set
152
* @param style pointer to a style
153
*/
154
void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t *style);
155
156
/*=====================
157
* Getter functions
158
*====================*/
159
160
161
#if LV_IMGBTN_TILED == 0
162
/**
163
* Get the images in a given state
164
* @param imgbtn pointer to an image button object
165
* @param state the state where to get the image (from `lv_btn_state_t`) `
166
* @return pointer to an image source (a C array or path to a file)
167
*/
168
const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state);
169
170
#else
171
172
/**
173
* Get the left image in a given state
174
* @param imgbtn pointer to an image button object
175
* @param state the state where to get the image (from `lv_btn_state_t`) `
176
* @return pointer to the left image source (a C array or path to a file)
177
*/
178
const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state);
179
180
/**
181
* Get the middle image in a given state
182
* @param imgbtn pointer to an image button object
183
* @param state the state where to get the image (from `lv_btn_state_t`) `
184
* @return pointer to the middle image source (a C array or path to a file)
185
*/
186
const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state);
187
188
/**
189
* Get the right image in a given state
190
* @param imgbtn pointer to an image button object
191
* @param state the state where to get the image (from `lv_btn_state_t`) `
192
* @return pointer to the left image source (a C array or path to a file)
193
*/
194
const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state);
195
196
#endif
197
/**
198
* Get the current state of the image button
199
* @param imgbtn pointer to a image button object
200
* @return the state of the button (from lv_btn_state_t enum)
201
*/
202
static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn)
203
{
204
return lv_btn_get_state(imgbtn);
205
}
206
207
/**
208
* Get the toggle enable attribute of the image button
209
* @param imgbtn pointer to a image button object
210
* @return ture: toggle enabled, false: disabled
211
*/
212
static inline bool lv_imgbtn_get_toggle(const lv_obj_t * imgbtn)
213
{
214
return lv_btn_get_toggle(imgbtn);
215
}
216
217
/**
218
* Get the release action of a image button
219
* @param imgbtn pointer to a image button object
220
* @return pointer to the release action function
221
*/
222
static inline lv_action_t lv_imgbtn_get_action(const lv_obj_t * imgbtn, lv_btn_action_t type)
223
{
224
return lv_btn_get_action(imgbtn, type);
225
}
226
227
/**
228
* Get style of a image button.
229
* @param imgbtn pointer to image button object
230
* @param type which style should be get
231
* @return style pointer to the style
232
*/
233
lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type);
234
235
/*=====================
236
* Other functions
237
*====================*/
238
239
/**********************
240
* MACROS
241
**********************/
242
243
#endif /*USE_LV_IMGBTN*/
244
245
#ifdef __cplusplus
246
} /* extern "C" */
247
#endif
248
249
#endif /*LV_IMGBTN_H*/
250
251