2021-04-12 18:19:04 +02:00
```eval_rst
.. include:: /header.rst
2021-05-19 13:51:22 +02:00
:github_url: |github_link_base|/widgets/extra/msgbox.md
2021-04-12 18:19:04 +02:00
```
# Message box (lv_msgbox)
## Overview
The Message boxes act as pop-ups.
2021-05-19 13:51:22 +02:00
They are built from a background container, a title, an optional close button, a text and optional buttons.
2021-04-12 18:19:04 +02:00
2021-06-09 15:10:35 +02:00
The text will be broken into multiple lines automatically and the height will be set automatically to include the text and the buttons.
2021-04-12 18:19:04 +02:00
2021-06-09 15:10:35 +02:00
The message box can be modal (blocking clicks on the rest of the screen) or not modal.
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
## Parts and Styles
2021-08-26 10:52:39 +02:00
The message box is built from other widgets, so you can check these widgets' documentation for details.
2021-05-19 13:51:22 +02:00
- Background: [lv_obj ](/widgets/obj )
- Close button: [lv_btn ](/widgets/core/btn )
- Title and text: [lv_label ](/widgets/core/label )
- Buttons: [lv_btnmatrix ](/widgets/core/btnmatrix )
2021-04-12 18:19:04 +02:00
## Usage
2021-06-09 15:10:35 +02:00
### Create a message box
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
`lv_msgbox_create(parent, title, txt, btn_txts[], add_close_btn)` creates a message box.
2021-04-12 18:19:04 +02:00
2021-06-09 15:10:35 +02:00
If `parent` is `NULL` the message box will be modal. `title` and `txt` are strings for the title and the text.
2021-05-19 13:51:22 +02:00
`btn_txts[]` is an array with the buttons' text. E.g. `const char * btn_txts[] = {"Ok", "Cancel", NULL}` .
`add_colse_btn` can be `true` or `false` to add/don't add a close button.
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
### Get the parts
2021-06-09 15:10:35 +02:00
The building blocks of the message box can be obtained using the following functions:
2021-05-19 13:51:22 +02:00
```c
lv_obj_t * lv_msgbox_get_title(lv_obj_t * mbox);
lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * mbox);
lv_obj_t * lv_msgbox_get_text(lv_obj_t * mbox);
lv_obj_t * lv_msgbox_get_btns(lv_obj_t * mbox);
```
2021-04-12 18:19:04 +02:00
2021-05-19 13:51:22 +02:00
### Close the message box
`lv_msgbox_close(msgbox)` closes (deletes) the message box.
2021-04-12 18:19:04 +02:00
## Events
2021-05-19 13:51:22 +02:00
- `LV_EVENT_VALUE_CHANGED` is sent by the buttons if one of them is clicked. `LV_OBJ_FLAG_EVENT_BUBBLE` is enabled on the buttons so you can add events to the message box itself.
2021-09-09 14:40:37 +02:00
In the event handler, `lv_event_get_target(e)` will return the button matrix and `lv_event_get_current_target(e)` will return the message box. `lv_msgbox_get_active_btn(msgbox)` and `lv_msgbox_get_active_btn_text(msgbox)` can be used to get the index and text of the clicked button.
2021-04-12 18:19:04 +02:00
Learn more about [Events ](/overview/event ).
2021-05-19 13:51:22 +02:00
## Keys
Keys have effect on the close button and button matrix. You can add them manually to a group if required.
2021-04-12 18:19:04 +02:00
Learn more about [Keys ](/overview/indev ).
## Example
```eval_rst
2021-05-19 13:51:22 +02:00
.. include:: ../../../examples/widgets/msgbox/index.rst
2021-04-12 18:19:04 +02:00
```
## API
```eval_rst
.. doxygenfile:: lv_msgbox.h
:project: lvgl
```