Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_mbox.h
1476 views
1
/*
2
* Copyright (c) 2019 CTCaer
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms and conditions of the GNU General Public License,
6
* version 2, as published by the Free Software Foundation.
7
*
8
* This program is distributed in the hope it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
* more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
17
/**
18
* @file lv_mbox.h
19
*
20
*/
21
22
#ifndef LV_MBOX_H
23
#define LV_MBOX_H
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
/*********************
30
* INCLUDES
31
*********************/
32
#ifdef LV_CONF_INCLUDE_SIMPLE
33
#include "lv_conf.h"
34
#else
35
#include "../../lv_conf.h"
36
#endif
37
38
#if USE_LV_MBOX != 0
39
40
/*Testing of dependencies*/
41
#if USE_LV_CONT == 0
42
#error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "
43
#endif
44
45
#if USE_LV_BTNM == 0
46
#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) "
47
#endif
48
49
#if USE_LV_LABEL == 0
50
#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) "
51
#endif
52
53
54
#include "../lv_core/lv_obj.h"
55
#include "lv_cont.h"
56
#include "lv_btnm.h"
57
#include "lv_label.h"
58
59
/*********************
60
* DEFINES
61
*********************/
62
63
/**********************
64
* TYPEDEFS
65
**********************/
66
67
/*Data of message box*/
68
typedef struct
69
{
70
lv_cont_ext_t bg; /*Ext. of ancestor*/
71
/*New data for this type */
72
lv_obj_t *text; /*Text of the message box*/
73
lv_obj_t *btnm; /*Button matrix for the buttons*/
74
uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/
75
} lv_mbox_ext_t;
76
77
enum {
78
LV_MBOX_STYLE_BG,
79
LV_MBOX_STYLE_BTN_BG,
80
LV_MBOX_STYLE_BTN_REL,
81
LV_MBOX_STYLE_BTN_PR,
82
LV_MBOX_STYLE_BTN_TGL_REL,
83
LV_MBOX_STYLE_BTN_TGL_PR,
84
LV_MBOX_STYLE_BTN_INA,
85
};
86
typedef uint8_t lv_mbox_style_t;
87
88
/**********************
89
* GLOBAL PROTOTYPES
90
**********************/
91
92
/**
93
* Create a message box objects
94
* @param par pointer to an object, it will be the parent of the new message box
95
* @param copy pointer to a message box object, if not NULL then the new object will be copied from it
96
* @return pointer to the created message box
97
*/
98
lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy);
99
100
/*======================
101
* Add/remove functions
102
*=====================*/
103
104
/**
105
* Add button to the message box
106
* @param mbox pointer to message box object
107
* @param btn_map button descriptor (button matrix map).
108
* E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable)
109
* @param action a function which will be called when a button is released
110
*/
111
void lv_mbox_add_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t action);
112
113
/*=====================
114
* Setter functions
115
*====================*/
116
117
/**
118
* Set the text of the message box
119
* @param mbox pointer to a message box
120
* @param txt a '\0' terminated character string which will be the message box text
121
*/
122
void lv_mbox_set_text(lv_obj_t * mbox, const char * txt);
123
124
/**
125
* Stop the action to call when button is released
126
* @param mbox pointer to a message box object
127
* @param pointer to an 'lv_btnm_action_t' action. In the action you need to use `lv_mbox_get_from_btn()` to get the `mbox`.
128
*/
129
void lv_mbox_set_action(lv_obj_t * mbox, lv_btnm_action_t action);
130
131
/**
132
* Set animation duration
133
* @param mbox pointer to a message box object
134
* @param anim_time animation length in milliseconds (0: no animation)
135
*/
136
void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time);
137
138
/**
139
* Automatically delete the message box after a given time
140
* @param mbox pointer to a message box object
141
* @param delay a time (in milliseconds) to wait before delete the message box
142
*/
143
void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay);
144
145
/**
146
* Stop the auto. closing of message box
147
* @param mbox pointer to a message box object
148
*/
149
void lv_mbox_stop_auto_close(lv_obj_t * mbox);
150
151
/**
152
* Set a style of a message box
153
* @param mbox pointer to a message box object
154
* @param type which style should be set
155
* @param style pointer to a style
156
*/
157
void lv_mbox_set_style(lv_obj_t *mbox, lv_mbox_style_t type, lv_style_t *style);
158
159
/**
160
* Set whether recoloring is enabled. Must be called after `lv_mbox_add_btns`.
161
* @param btnm pointer to button matrix object
162
* @param en whether recoloring is enabled
163
*/
164
void lv_mbox_set_recolor(lv_obj_t * mbox, bool en);
165
166
void lv_mbox_set_recolor_text(lv_obj_t * mbox, bool en);
167
168
/*=====================
169
* Getter functions
170
*====================*/
171
172
/**
173
* Get the text of the message box
174
* @param mbox pointer to a message box object
175
* @return pointer to the text of the message box
176
*/
177
const char * lv_mbox_get_text(const lv_obj_t * mbox);
178
179
/**
180
* Get the message box object from one of its button.
181
* It is useful in the button release actions where only the button is known
182
* @param btn pointer to a button of a message box
183
* @return pointer to the button's message box
184
*/
185
lv_obj_t * lv_mbox_get_from_btn(const lv_obj_t * btn);
186
187
/**
188
* Get the animation duration (close animation time)
189
* @param mbox pointer to a message box object
190
* @return animation length in milliseconds (0: no animation)
191
*/
192
uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox);
193
194
195
/**
196
* Get a style of a message box
197
* @param mbox pointer to a message box object
198
* @param type which style should be get
199
* @return style pointer to a style
200
*/
201
lv_style_t * lv_mbox_get_style(const lv_obj_t *mbox, lv_mbox_style_t type);
202
203
/**
204
* Get whether recoloring is enabled
205
* @param btnm pointer to button matrix object
206
* @return whether recoloring is enabled
207
*/
208
bool lv_mbox_get_recolor(const lv_obj_t * mbox);
209
210
/**********************
211
* MACROS
212
**********************/
213
214
215
#endif /*USE_LV_MBOX*/
216
217
#ifdef __cplusplus
218
} /* extern "C" */
219
#endif
220
221
#endif /*LV_MBOX_H*/
222
223