Message Box (lv_msgbox)
Message boxes act as pop-ups. They are built from a content area with a helper to add text, an optional header (which can have a title, a close button, and other buttons), and an optional footer wi...
Overview
Message boxes act as pop-ups. They are built from a content area with a helper to add text, an optional header (which can have a title, a close button, and other buttons), and an optional footer with buttons.
The text will be broken into multiple lines, and the height will be set automatically. If the height is set programmatically, the content will become scrollable.
The message box can be modal (blocking clicks on the rest of the screen) or not modal.
Parts and Styles
The message box is built from other Widgets, so you can check these Widgets' documentation for details.
- Content, header, and footer: base widget
- Buttons: Button (lv_button)
- Title and content text: Label (lv_label)
Usage
Create a message box
lv_msgbox_create(parent) creates a message box.
If parent is NULL the message box will be modal, and will use the
Default Display's Top Layer as a parent.
Adding buttons
If you want to add an [OK] or [Cancel] or other buttons for the
user to have a choice of responses, add each button using the
lv_msgbox_add_footer_button(msgbox, btn_text) function. Calling this
function adds a footer (container) if one was not already present, and it returns a
pointer to the button created, which can be used to add LV_EVENT_CLICKED (or
other) events to detect and act on the user's response.
Footer buttons so added are evenly spaced and centered.
Buttons can also be added to the header if desired with
lv_msgbox_add_header_button(msgbox, symbol).
Buttons so added are added to the right end of the header.
Getting the parts
The building blocks of the message box can be obtained using the following functions:
lv_obj_t * lv_msgbox_get_content(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_get_title(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_get_header(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_get_footer(lv_obj_t * msgbox);Functions that add something to the message box return a pointer to the newly added Widget:
lv_obj_t * lv_msgbox_add_text(lv_obj_t * msgbox, const char * text);
lv_obj_t * lv_msgbox_add_text_fmt(lv_obj_t * obj, const char * fmt, ...);
lv_obj_t * lv_msgbox_add_title(lv_obj_t * msgbox, const char * title);
lv_obj_t * lv_msgbox_add_close_button(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_add_header_button(lv_obj_t * msgbox, const void * symbol);
lv_obj_t * lv_msgbox_add_footer_button(lv_obj_t * msgbox, const char * text);Close the message box
lv_msgbox_close(msgbox) closes (deletes) the message box.
lv_msgbox_close_async(msgbox) closes (deletes) the message box
asynchronously. This is useful if you want the message box to close the on
the next call to lv_timer_handler instead of immediately.
Events
No special events are sent by Message Box Widgets. See these Widgets' documentation for details: Button (lv_button) and Label (lv_label).
Keys
No Keys are processed by Message Box Widgets.
Further Reading
Learn more about Keys.
Examples
Simple Message box
Scrolling and styled Message box
Message box with blurred background
API
How is this guide?
Last updated on
Menu (lv_menu)
The Menu Widget can be used to create multi-level menus that automatically handle navigation among menu levels, and enable its user to capture page navigation and click events.
Roller (lv_roller)
Roller allows the end user to select an item from a list by scrolling through it. The item in the middle is the selected item and normally stands out from the other items due to different styles ap...