demo_view_notebook.c 1.4 KB
Newer Older
1
/*
G
Grissiom 已提交
2
 * 程序清单:notebook控件演示
3
 *
G
Grissiom 已提交
4
 * 这个例子会在创建出的container上演示notebook控件
5 6 7 8 9 10 11 12
 */

#include "demo_view.h"
#include <rtgui/widgets/notebook.h>
#include <rtgui/widgets/listbox.h>

const static struct rtgui_listbox_item items[] =
{
13 14 15 16
    {"list #0", RT_NULL},
    {"list #1", RT_NULL},
    {"list #2", RT_NULL},
    {"list #3", RT_NULL},
17 18 19 20
};

const static struct rtgui_listbox_item items2[] =
{
21 22 23 24 25
    {"list #0", RT_NULL},
    {"list #1", RT_NULL},
    {"list #2", RT_NULL},
    {"new list #1", RT_NULL},
    {"new list #2", RT_NULL},
26 27
};

G
Grissiom 已提交
28
/* 创建用于演示notebook控件的视图 */
29
rtgui_container_t *demo_view_notebook(void)
30
{
31 32 33 34
    rtgui_rect_t rect;
    rtgui_container_t *container;
    struct rtgui_notebook *notebook;
    rtgui_listbox_t *box;
35

G
Grissiom 已提交
36
    /* 先创建一个演示用的视图 */
37
    container = demo_view("Notebook View");
38

G
Grissiom 已提交
39
    /* 获得视图的位置信息 */
40
    demo_view_get_rect(container, &rect);
41

42
    notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_BOTTOM);
G
Grissiom 已提交
43
    /* container是一个container控件,调用add_child方法添加这个notebook控件 */
44
    rtgui_container_add_child(container, RTGUI_WIDGET(notebook));
45

46 47
    box = rtgui_listbox_create(items, sizeof(items) / sizeof(struct rtgui_listbox_item), &rect);
    rtgui_notebook_add(notebook, "Tab 1", RTGUI_WIDGET(box));
48

49 50
    box = rtgui_listbox_create(items2, sizeof(items2) / sizeof(struct rtgui_listbox_item), &rect);
    rtgui_notebook_add(notebook, "Tab 2", RTGUI_WIDGET(box));
51

52
    return container;
53
}