当前位置:网站首页>ESP32 LVGL8. 1 - msgbox message box (msgbox 28)

ESP32 LVGL8. 1 - msgbox message box (msgbox 28)

2022-04-23 18:40:00 Please call me Xiao Peng

Tips : This blog serves as a learning note , If there are mistakes, I hope to correct them

One 、textarea brief introduction

1.1 summary Overview

  “ news ” Box acts as a pop-up window . They consist of a background container 、 A title 、 An optional close button and an optional button constructed from text . The text will be automatically divided into multiple lines , The height will be automatically set to include text and buttons . Message boxes can be modal ( Block the rest of the screen from clicking ), It can also be non modal .

1.2 Part and style Parts and Styles

  
The message box is built by other widgets , So you can check the documentation of these widgets for details .
• background :lv_obj
• close button :lv_btn
• Title and text :lv_label
• Button :lv_btnmatrix

1.3 Use Usage

1.3.1 Create a message box Create a message box

  Lv_msgbox_create (parent, title, txt, btn_txts[], add_close_btn) Create a message box .
If parent by NULL, The message box will be modal .Title and TXT Is a string of title and text .btn_txts []
Is an array with button text . for example const char * btn_txts[] = {“Ok”, “Cancel”, NULL}.
Add_colse_btn It can be for true or false To add / Do not add close button .

1.3.2 Get parts Get the parts

   The building blocks of the message box can be obtained through the following functions :

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);

1.3.3 Close the message box Close the message box

  Lv_msgbox_close (msgbox) close ( Delete ) Message box .

1.4 event Events

   If one of them is clicked ,LV_EVENT_VALUE_CHANGED Will be sent by the button . Enabled... On the button LV_OBJ_FLAG_EVENT_BUBBLE, So you can add events to the message box itself . In the event handler ,lv_event_get_target(e) Will return Button Matrix and lv_event_get_current_target(e) The message box is returned .
lv_msgbox_get_active_btn(msgbox) and lv_msgbox_get_active_btn_text(msgbox) Click buttons that can be used to get indexes and text .

1.5 Key Keys

   The key has an effect on the close button and button matrix . if necessary , You can manually add them to the Group .

Two 、msgbox API

******************
*  Create a message box object 
* @param Parent pointer or NULL Create a full screen modal message box 
* @param title The title of the message box 
* @param TXT The text of the message box 
* @param btn_txts The button acts as a to “” An array of text at the end of the element . for example :{
    "btn1", "btn2", ""}
* @param add_close_btn true: Add a close button 
* @return Pointer to the message box object 
*******************/
lv_obj_t * lv_msgbox_create(Lv_obj_t * parent, const char * title, const char * txt, const char * btn_txts[],bool add_close_btn);
// Get the title of the message box 
lv_obj_t * lv_msgbox_get_title(Lv_obj_t * obj);
// Get the close button of the message box 
lv_obj_t * lv_msgbox_get_close_btn(Lv_obj_t * obj);
// Get the text content of the message box 
lv_obj_t * lv_msgbox_get_text(Lv_obj_t * obj);
// Get the directory of the message box 
lv_obj_t * lv_msgbox_get_content(Lv_obj_t * obj);
// Get the button of the message box 
lv_obj_t * lv_msgbox_get_btns(Lv_obj_t * obj);**
*  Gets the index of the selected button 
* @param mbox Message box object 
* @ Returns the index of the button (LV_BTNMATRIX_BTN_NONE: If not set )
*/
uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox);
// Get active key text 
const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox);
// Close the message box 
void lv_msgbox_close(lv_obj_t * mbox);
// Close the message box 
void lv_msgbox_close_async(lv_obj_t * mbox);

3、 ... and 、 Example

3.1 Example to achieve digital key input

static void event_cb(lv_event_t * e)
{
    
    lv_obj_t * obj = lv_event_get_current_target(e);
    LV_LOG_USER("Button %s clicked", lv_msgbox_get_active_btn_text(obj));
}

void lv_example_msgbox_1(void)
{
    
    static const char * btns[] ={
    "Apply", "Close", ""};// Create button character 
    lv_obj_t * mbox1 = lv_msgbox_create(NULL, "Hello", "This is a message box with two buttons.", btns, true);
    lv_obj_add_event_cb(mbox1, event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    lv_obj_center(mbox1);
}

 Insert picture description here

版权声明
本文为[Please call me Xiao Peng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210609449995.html