[English]

Window (窗口)(lv_win)

Overview(概述)

显示原文

The Window is container-like object built from a header with title and buttons and a content area.


Window(窗口)是一个类似容器的对象,由带有标头、按钮和内容区域构建而成。

Parts and Styles(部分和样式)

显示原文

The Window is built from other widgets so you can check their documentation for details:


窗口控件是由其他控件构建的,因此可以查看它们的文档以获取详细信息:

Usage(用法)

Create a Window(创建一个窗口)

显示原文

lv_win_create(parent) creates a Window with an empty header.


lv_win_create(parent) 创建一个标头为空的窗口。

Title and buttons(标头和按钮)

显示原文

Any number of texts (but typically only one) can be added to the header with lv_win_add_title(win, "The title").

Control buttons can be added to the window's header with lv_win_add_button(win, icon, button_width). icon can be any image source, and button_width is the width of the button.

The title and the buttons will be added in the order the functions are called. So adding a button, a text and two other buttons will result in a button on the left, a title, and 2 buttons on the right. The width of the title is set to take all the remaining space on the header. In other words: it pushes to the right all the buttons that are added after the title.


可以使用 lv_win_add_title(win, "The title") 将任意数量的文本(但通常只有一个)添加到标头中。

可以使用 lv_win_add_button(win, icon, button_width) 将控制按钮添加到窗口的标头 。 icon 可以是任何图像源, button_width 是按钮的宽度。

标头和按钮将按照调用函数的顺序添加。因此,添加一个按钮、一个文本和另外两个按钮将在左侧产生一个按钮,在右侧产生一个标头和两个按钮。标头的宽度设置为占据标头上的所有剩余空间。换句话说: 它将标头后添加的所有按钮推到右侧。

Get the parts(获取部分)

显示原文

lv_win_get_header(win) returns a pointer to the header, lv_win_get_content(win) returns a pointer to the content container to which the content of the window can be added.


lv_win_get_header(win) 返回一个指向标头的指针, lv_win_get_content(win) 返回一个指向可以在窗口添加内容的容器指针。

Events(事件)

显示原文

No special events are sent by the windows, however events can be added manually to the return value of lv_win_add_button().

Learn more about Events(事件).


窗口不会发送特殊事件,但是可以手动将事件添加到 lv_win_add_button() 的返回值中。

了解有关 Events(事件) 的更多信息。

Keys(按键)

显示原文

No Keys are handled by the window.

Learn more about Keys(按键).


窗口不处理任何 按键

了解有关 Keys(按键) 的更多信息。

Example

[English]

Simple window

#include "../../lv_examples.h"
#if LV_USE_WIN && LV_BUILD_EXAMPLES

static void event_handler(lv_event_t * e)
{
    lv_obj_t * obj = lv_event_get_target(e);
    LV_UNUSED(obj);
    LV_LOG_USER("Button %d clicked", (int)lv_obj_get_index(obj));
}

void lv_example_win_1(void)
{
    lv_obj_t * win = lv_win_create(lv_screen_active());
    lv_obj_t * btn;
    btn = lv_win_add_button(win, LV_SYMBOL_LEFT, 40);
    lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);

    lv_win_add_title(win, "A title");

    btn = lv_win_add_button(win, LV_SYMBOL_RIGHT, 40);
    lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);

    btn = lv_win_add_button(win, LV_SYMBOL_CLOSE, 60);
    lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);

    lv_obj_t * cont = lv_win_get_content(win);  /*Content can be added here*/
    lv_obj_t * label = lv_label_create(cont);
    lv_label_set_text(label, "This is\n"
                      "a pretty\n"
                      "long text\n"
                      "to see how\n"
                      "the window\n"
                      "becomes\n"
                      "scrollable.\n"
                      "\n"
                      "\n"
                      "Some more\n"
                      "text to be\n"
                      "sure it\n"
                      "overflows. :)");

}

#endif

API

lv_win.h

lv_types.h