[English]

Message box(消息框) (lv_msgbox)

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 manually, 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.


消息框是由多种控件组成的,下面是各个控件(组成)对应的文档:

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.


lv_msgbox_create(parent)`用于创建一个消息框。 如果 ``parent``为 ``NULL`,那么该消息框将是模态的,并会使用 default_display 的顶层 Layer 作为父级对象。

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.


如果你想添加一个 [确定]、[取消] 或其他按钮,以便用户能够进行响应选择,可以使用:cpp:expr:`lv_msgbox_add_footer_button(msgbox, btn_text)`函数来添加各个按钮。调用该函数时,如果之前不存在页脚(容器),则会添加一个,并且它会返回一个指向所创建按钮的指针,该指针可用于添加 ``LV_EVENT_CLICKED``(或其他)事件,以检测用户的响应并据此采取相应行动。

如此添加的页脚按钮会均匀分布且居中显示。

如果需要的话,也可以使用:cpp:expr:`lv_msgbox_add_header_button(msgbox, symbol)`将按钮添加到页眉处。这样添加的按钮会添加到页眉的右端。

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

那些向消息框中添加内容的函数会返回一个指向新添加部件的指针:

Close the message box(关闭消息框)

如果你要删除消息框,不建议直接调用 lv_obj_delete 函数进行操作,而是使用 lv_msgbox_close 函数

显示原文

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.


lv_msgbox_close(msgbox) 关闭(删除)消息框。

lv_msgbox_close_async(msgbox) 异步关闭(删除)消息框。这在如果你想要在下一次调用 lv_timer_handler 时而不是立即关闭消息框时非常有用。

Events(事件)

显示原文

No special events are sent by this Widget, though its parts can send events. See their documentation for details: Button(按钮) (lv_button) and Label (标签)(lv_label).

Further Reading

Learn more about Base-Widget Events emitted by all Widgets.

Learn more about Events(事件).


该部件不会发送特殊事件,不过其各部分可以发送事件。详情请参阅它们的文档::ref:`lv_button`(按钮相关文档)和 :ref:`lv_label`(标签相关文档)。

进一步了解所有部件发出的 Base-Widget Events

进一步了解 Events(事件)

Keys(按键)

显示原文

No Keys are processed by Msgbox Widgets.

Further Reading

Learn more about Keys(按键).


消息框部件不处理任何 按键

进一步了解 :ref:输入设备按键 :ref:`indev_keys`相关内容。

Example

API

lv_msgbox.h

lv_types.h