Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_btn.h
1476 views
1
/**
2
* @file lv_btn.h
3
*
4
*/
5
6
#ifndef LV_BTN_H
7
#define LV_BTN_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_BTN != 0
23
24
/*Testing of dependencies*/
25
#if USE_LV_CONT == 0
26
#error "lv_btn: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "
27
#endif
28
29
#include "lv_cont.h"
30
#include "../lv_core/lv_indev.h"
31
32
/*********************
33
* DEFINES
34
*********************/
35
36
/**********************
37
* TYPEDEFS
38
**********************/
39
40
/* Button states
41
* It can be used not only by buttons but other button-like objects too*/
42
enum
43
{
44
LV_BTN_STATE_REL,
45
LV_BTN_STATE_PR,
46
LV_BTN_STATE_TGL_REL,
47
LV_BTN_STATE_TGL_PR,
48
LV_BTN_STATE_INA,
49
LV_BTN_STATE_NUM,
50
};
51
typedef uint8_t lv_btn_state_t;
52
53
enum
54
{
55
LV_BTN_ACTION_CLICK,
56
LV_BTN_ACTION_PR,
57
LV_BTN_ACTION_LONG_PR,
58
LV_BTN_ACTION_LONG_PR_REPEAT,
59
LV_BTN_ACTION_NUM,
60
};
61
typedef uint8_t lv_btn_action_t;
62
63
64
/*Data of button*/
65
typedef struct
66
{
67
lv_cont_ext_t cont; /*Ext. of ancestor*/
68
/*New data for this type */
69
lv_action_t actions[LV_BTN_ACTION_NUM];
70
lv_style_t * styles[LV_BTN_STATE_NUM]; /*Styles in each state*/
71
lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/
72
int idx;
73
#if LV_BTN_INK_EFFECT
74
uint16_t ink_in_time; /*[ms] Time of ink fill effect (0: disable ink effect)*/
75
uint16_t ink_wait_time; /*[ms] Wait before the ink disappears */
76
uint16_t ink_out_time; /*[ms] Time of ink disappearing*/
77
#endif
78
uint8_t toggle :1; /*1: Toggle enabled*/
79
uint8_t long_pr_action_executed :1; /*1: Long press action executed (Handled by the library)*/
80
} lv_btn_ext_t;
81
82
/*Styles*/
83
enum {
84
LV_BTN_STYLE_REL,
85
LV_BTN_STYLE_PR,
86
LV_BTN_STYLE_TGL_REL,
87
LV_BTN_STYLE_TGL_PR,
88
LV_BTN_STYLE_INA,
89
};
90
typedef uint8_t lv_btn_style_t;
91
92
/**********************
93
* GLOBAL PROTOTYPES
94
**********************/
95
96
/**
97
* Create a button objects
98
* @param par pointer to an object, it will be the parent of the new button
99
* @param copy pointer to a button object, if not NULL then the new object will be copied from it
100
* @return pointer to the created button
101
*/
102
lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy);
103
104
/*=====================
105
* Setter functions
106
*====================*/
107
108
/**
109
* Enable the toggled states. On release the button will change from/to toggled state.
110
* @param btn pointer to a button object
111
* @param tgl true: enable toggled states, false: disable
112
*/
113
void lv_btn_set_toggle(lv_obj_t * btn, bool tgl);
114
115
/**
116
* Set the state of the button
117
* @param btn pointer to a button object
118
* @param state the new state of the button (from lv_btn_state_t enum)
119
*/
120
void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);
121
122
/**
123
* Toggle the state of the button (ON->OFF, OFF->ON)
124
* @param btn pointer to a button object
125
*/
126
void lv_btn_toggle(lv_obj_t * btn);
127
128
/**
129
* Set a function to call when a button event happens
130
* @param btn pointer to a button object
131
* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)
132
*/
133
void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action);
134
135
/**
136
* Set the layout on a button
137
* @param btn pointer to a button object
138
* @param layout a layout from 'lv_cont_layout_t'
139
*/
140
static inline void lv_btn_set_layout(lv_obj_t * btn, lv_layout_t layout)
141
{
142
lv_cont_set_layout(btn, layout);
143
}
144
145
/**
146
* Enable the horizontal or vertical fit.
147
* The button size will be set to involve the children horizontally or vertically.
148
* @param btn pointer to a button object
149
* @param hor_en true: enable the horizontal fit
150
* @param ver_en true: enable the vertical fit
151
*/
152
static inline void lv_btn_set_fit(lv_obj_t * btn, bool hor_en, bool ver_en)
153
{
154
lv_cont_set_fit(btn, hor_en, ver_en);
155
}
156
157
/**
158
* Set time of the ink effect (draw a circle on click to animate in the new state)
159
* @param btn pointer to a button object
160
* @param time the time of the ink animation
161
*/
162
void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time);
163
164
/**
165
* Set the wait time before the ink disappears
166
* @param btn pointer to a button object
167
* @param time the time of the ink animation
168
*/
169
void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time);
170
171
/**
172
* Set time of the ink out effect (animate to the released state)
173
* @param btn pointer to a button object
174
* @param time the time of the ink animation
175
*/
176
void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time);
177
178
/**
179
* Set a style of a button.
180
* @param btn pointer to button object
181
* @param type which style should be set
182
* @param style pointer to a style
183
* */
184
void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, lv_style_t *style);
185
186
/*=====================
187
* Getter functions
188
*====================*/
189
190
/**
191
* Get the current state of the button
192
* @param btn pointer to a button object
193
* @return the state of the button (from lv_btn_state_t enum)
194
*/
195
lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn);
196
197
/**
198
* Get the toggle enable attribute of the button
199
* @param btn pointer to a button object
200
* @return ture: toggle enabled, false: disabled
201
*/
202
bool lv_btn_get_toggle(const lv_obj_t * btn);
203
204
/**
205
* Get the release action of a button
206
* @param btn pointer to a button object
207
* @return pointer to the release action function
208
*/
209
lv_action_t lv_btn_get_action(const lv_obj_t * btn, lv_btn_action_t type);
210
211
/**
212
* Get the layout of a button
213
* @param btn pointer to button object
214
* @return the layout from 'lv_cont_layout_t'
215
*/
216
static inline lv_layout_t lv_btn_get_layout(const lv_obj_t * btn)
217
{
218
return lv_cont_get_layout(btn);
219
}
220
221
/**
222
* Get horizontal fit enable attribute of a button
223
* @param btn pointer to a button object
224
* @return true: horizontal fit is enabled; false: disabled
225
*/
226
static inline bool lv_btn_get_hor_fit(const lv_obj_t * btn)
227
{
228
return lv_cont_get_hor_fit(btn);
229
}
230
231
/**
232
* Get vertical fit enable attribute of a container
233
* @param btn pointer to a button object
234
* @return true: vertical fit is enabled; false: disabled
235
*/
236
static inline bool lv_btn_get_ver_fit(const lv_obj_t * btn)
237
{
238
return lv_cont_get_ver_fit(btn);
239
}
240
241
/**
242
* Get time of the ink in effect (draw a circle on click to animate in the new state)
243
* @param btn pointer to a button object
244
* @return the time of the ink animation
245
*/
246
uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn);
247
248
/**
249
* Get the wait time before the ink disappears
250
* @param btn pointer to a button object
251
* @return the time of the ink animation
252
*/
253
uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn);
254
255
/**
256
* Get time of the ink out effect (animate to the releases state)
257
* @param btn pointer to a button object
258
* @return the time of the ink animation
259
*/
260
uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn);
261
262
/**
263
* Get style of a button.
264
* @param btn pointer to button object
265
* @param type which style should be get
266
* @return style pointer to the style
267
* */
268
lv_style_t * lv_btn_get_style(const lv_obj_t * btn, lv_btn_style_t type);
269
270
/**********************
271
* MACROS
272
**********************/
273
274
#endif /*USE_LV_BUTTON*/
275
276
#ifdef __cplusplus
277
} /* extern "C" */
278
#endif
279
280
#endif /*LV_BTN_H*/
281
282