1 /**
2  * @file lv_mbox.h
3  *
4  */
5 
6 #ifndef LV_MSGBOX_H
7 #define LV_MSGBOX_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_MSGBOX != 0
19 
20 /*Testing of dependencies*/
21 #if LV_USE_CONT == 0
22 #error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (LV_USE_CONT  1) "
23 #endif
24 
25 #if LV_USE_BTNMATRIX == 0
26 #error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (LV_USE_BTNMATRIX  1) "
27 #endif
28 
29 #if LV_USE_LABEL == 0
30 #error "lv_mbox: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL  1) "
31 #endif
32 
33 #include "../lv_core/lv_obj.h"
34 #include "lv_cont.h"
35 #include "lv_btnmatrix.h"
36 #include "lv_label.h"
37 
38 /*********************
39  *      DEFINES
40  *********************/
41 
42 /**********************
43  *      TYPEDEFS
44  **********************/
45 
46 /*Data of message box*/
47 typedef struct {
48     lv_cont_ext_t bg; /*Ext. of ancestor*/
49     /*New data for this type */
50     lv_obj_t * text; /*Text of the message box*/
51     lv_obj_t * btnm; /*Button matrix for the buttons*/
52 #if LV_USE_ANIMATION
53     uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/
54 #endif
55 } lv_msgbox_ext_t;
56 
57 /** Message box styles. */
58 enum {
59     LV_MSGBOX_PART_BG = LV_CONT_PART_MAIN,
60 
61     LV_MSGBOX_PART_BTN_BG = _LV_CONT_PART_REAL_LAST,
62     LV_MSGBOX_PART_BTN,
63 };
64 typedef uint8_t lv_msgbox_style_t;
65 
66 /**********************
67  * GLOBAL PROTOTYPES
68  **********************/
69 
70 /**
71  * Create a message box objects
72  * @param par pointer to an object, it will be the parent of the new message box
73  * @param copy pointer to a message box object, if not NULL then the new object will be copied from
74  * it
75  * @return pointer to the created message box
76  */
77 lv_obj_t * lv_msgbox_create(lv_obj_t * par, const lv_obj_t * copy);
78 
79 /*======================
80  * Add/remove functions
81  *=====================*/
82 
83 /**
84  * Add button to the message box
85  * @param mbox pointer to message box object
86  * @param btn_map button descriptor (button matrix map).
87  *                E.g.  a const char *txt[] = {"ok", "close", ""} (Can not be local variable)
88  */
89 void lv_msgbox_add_btns(lv_obj_t * mbox, const char * btn_mapaction[]);
90 
91 /*=====================
92  * Setter functions
93  *====================*/
94 
95 /**
96  * Set the text of the message box
97  * @param mbox pointer to a message box
98  * @param txt a '\0' terminated character string which will be the message box text
99  */
100 void lv_msgbox_set_text(lv_obj_t * mbox, const char * txt);
101 
102 /**
103  * Set animation duration
104  * @param mbox pointer to a message box object
105  * @param anim_time animation length in  milliseconds (0: no animation)
106  */
107 void lv_msgbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time);
108 
109 /**
110  * Automatically delete the message box after a given time
111  * @param mbox pointer to a message box object
112  * @param delay a time (in milliseconds) to wait before delete the message box
113  */
114 void lv_msgbox_start_auto_close(lv_obj_t * mbox, uint16_t delay);
115 
116 /**
117  * Stop the auto. closing of message box
118  * @param mbox pointer to a message box object
119  */
120 void lv_msgbox_stop_auto_close(lv_obj_t * mbox);
121 
122 /**
123  * Set whether recoloring is enabled. Must be called after `lv_msgbox_add_btns`.
124  * @param mbox pointer to message box object
125  * @param en whether recoloring is enabled
126  */
127 void lv_msgbox_set_recolor(lv_obj_t * mbox, bool en);
128 
129 /*=====================
130  * Getter functions
131  *====================*/
132 
133 /**
134  * Get the text of the message box
135  * @param mbox pointer to a message box object
136  * @return pointer to the text of the message box
137  */
138 const char * lv_msgbox_get_text(const lv_obj_t * mbox);
139 
140 /**
141  * Get the index of the lastly "activated" button by the user (pressed, released etc)
142  * Useful in the the `event_cb`.
143  * @param mbox pointer to message box object
144  * @return  index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset)
145  */
146 uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox);
147 
148 /**
149  * Get the text of the lastly "activated" button by the user (pressed, released etc)
150  * Useful in the the `event_cb`.
151  * @param mbox pointer to message box object
152  * @return text of the last released button (NULL: if unset)
153  */
154 const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox);
155 
156 /**
157  * Get the animation duration (close animation time)
158  * @param mbox pointer to a message box object
159  * @return animation length in  milliseconds (0: no animation)
160  */
161 uint16_t lv_msgbox_get_anim_time(const lv_obj_t * mbox);
162 
163 /**
164  * Get whether recoloring is enabled
165  * @param mbox pointer to a message box object
166  * @return whether recoloring is enabled
167  */
168 bool lv_msgbox_get_recolor(const lv_obj_t * mbox);
169 
170 /**
171  * Get message box button matrix
172  * @param mbox pointer to a message box object
173  * @return pointer to button matrix object
174  * @remarks return value will be NULL unless `lv_msgbox_add_btns` has been already called
175  */
176 lv_obj_t * lv_msgbox_get_btnmatrix(lv_obj_t * mbox);
177 
178 /**********************
179  *      MACROS
180  **********************/
181 
182 #endif /*LV_USE_MSGBOX*/
183 
184 #ifdef __cplusplus
185 } /* extern "C" */
186 #endif
187 
188 #endif /*LV_MSGBOX_H*/
189