1 /**
2  * @file lv_mbox.h
3  *
4  */
5 
6 #ifndef LV_MBOX_H
7 #define LV_MBOX_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 LV_USE_MBOX != 0
23 
24 /*Testing of dependencies*/
25 #if LV_USE_CONT == 0
26 #error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (LV_USE_CONT  1) "
27 #endif
28 
29 #if LV_USE_BTNM == 0
30 #error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (LV_USE_BTNM  1) "
31 #endif
32 
33 #if LV_USE_LABEL == 0
34 #error "lv_mbox: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL  1) "
35 #endif
36 
37 #include "../lv_core/lv_obj.h"
38 #include "lv_cont.h"
39 #include "lv_btnm.h"
40 #include "lv_label.h"
41 
42 /*********************
43  *      DEFINES
44  *********************/
45 
46 /**********************
47  *      TYPEDEFS
48  **********************/
49 
50 /*Data of message box*/
51 typedef struct
52 {
53     lv_cont_ext_t bg; /*Ext. of ancestor*/
54     /*New data for this type */
55     lv_obj_t * text; /*Text of the message box*/
56     lv_obj_t * btnm; /*Button matrix for the buttons*/
57 #if LV_USE_ANIMATION
58     uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/
59 #endif
60 } lv_mbox_ext_t;
61 
62 /** Message box styles. */
63 enum {
64     LV_MBOX_STYLE_BG,
65     LV_MBOX_STYLE_BTN_BG, /**< Same meaning as ordinary button styles. */
66     LV_MBOX_STYLE_BTN_REL,
67     LV_MBOX_STYLE_BTN_PR,
68     LV_MBOX_STYLE_BTN_TGL_REL,
69     LV_MBOX_STYLE_BTN_TGL_PR,
70     LV_MBOX_STYLE_BTN_INA,
71 };
72 typedef uint8_t lv_mbox_style_t;
73 
74 /**********************
75  * GLOBAL PROTOTYPES
76  **********************/
77 
78 /**
79  * Create a message box objects
80  * @param par pointer to an object, it will be the parent of the new message box
81  * @param copy pointer to a message box object, if not NULL then the new object will be copied from
82  * it
83  * @return pointer to the created message box
84  */
85 lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy);
86 
87 /*======================
88  * Add/remove functions
89  *=====================*/
90 
91 /**
92  * Add button to the message box
93  * @param mbox pointer to message box object
94  * @param btn_map button descriptor (button matrix map).
95  *                E.g.  a const char *txt[] = {"ok", "close", ""} (Can not be local variable)
96  */
97 void lv_mbox_add_btns(lv_obj_t * mbox, const char ** btn_mapaction);
98 
99 /*=====================
100  * Setter functions
101  *====================*/
102 
103 /**
104  * Set the text of the message box
105  * @param mbox pointer to a message box
106  * @param txt a '\0' terminated character string which will be the message box text
107  */
108 void lv_mbox_set_text(lv_obj_t * mbox, const char * txt);
109 
110 /**
111  * Set animation duration
112  * @param mbox pointer to a message box object
113  * @param anim_time animation length in  milliseconds (0: no animation)
114  */
115 void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time);
116 
117 /**
118  * Automatically delete the message box after a given time
119  * @param mbox pointer to a message box object
120  * @param delay a time (in milliseconds) to wait before delete the message box
121  */
122 void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay);
123 
124 /**
125  * Stop the auto. closing of message box
126  * @param mbox pointer to a message box object
127  */
128 void lv_mbox_stop_auto_close(lv_obj_t * mbox);
129 
130 /**
131  * Set a style of a message box
132  * @param mbox pointer to a message box object
133  * @param type which style should be set
134  * @param style pointer to a style
135  */
136 void lv_mbox_set_style(lv_obj_t * mbox, lv_mbox_style_t type, const lv_style_t * style);
137 
138 /**
139  * Set whether recoloring is enabled. Must be called after `lv_mbox_add_btns`.
140  * @param btnm pointer to button matrix object
141  * @param en whether recoloring is enabled
142  */
143 void lv_mbox_set_recolor(lv_obj_t * mbox, bool en);
144 
145 /*=====================
146  * Getter functions
147  *====================*/
148 
149 /**
150  * Get the text of the message box
151  * @param mbox pointer to a message box object
152  * @return pointer to the text of the message box
153  */
154 const char * lv_mbox_get_text(const lv_obj_t * mbox);
155 
156 /**
157  * Get the index of the lastly "activated" button by the user (pressed, released etc)
158  * Useful in the the `event_cb`.
159  * @param btnm pointer to button matrix object
160  * @return  index of the last released button (LV_BTNM_BTN_NONE: if unset)
161  */
162 uint16_t lv_mbox_get_active_btn(lv_obj_t * mbox);
163 
164 /**
165  * Get the text of the lastly "activated" button by the user (pressed, released etc)
166  * Useful in the the `event_cb`.
167  * @param btnm pointer to button matrix object
168  * @return text of the last released button (NULL: if unset)
169  */
170 const char * lv_mbox_get_active_btn_text(lv_obj_t * mbox);
171 
172 /**
173  * Get the animation duration (close animation time)
174  * @param mbox pointer to a message box object
175  * @return animation length in  milliseconds (0: no animation)
176  */
177 uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox);
178 
179 /**
180  * Get a style of a message box
181  * @param mbox pointer to a message box object
182  * @param type which style should be get
183  * @return style pointer to a style
184  */
185 const lv_style_t * lv_mbox_get_style(const lv_obj_t * mbox, lv_mbox_style_t type);
186 
187 /**
188  * Get whether recoloring is enabled
189  * @param mbox pointer to a message box object
190  * @return whether recoloring is enabled
191  */
192 bool lv_mbox_get_recolor(const lv_obj_t * mbox);
193 
194 /**
195  * Get message box button matrix
196  * @param mbox pointer to a message box object
197  * @return pointer to button matrix object
198  * @remarks return value will be NULL unless `lv_mbox_add_btns` has been already called
199  */
200 lv_obj_t * lv_mbox_get_btnm(lv_obj_t * mbox);
201 
202 /**********************
203  *      MACROS
204  **********************/
205 
206 #endif /*LV_USE_MBOX*/
207 
208 #ifdef __cplusplus
209 } /* extern "C" */
210 #endif
211 
212 #endif /*LV_MBOX_H*/
213