From cfe7e91b95a7b59270e27c969018374513fde6be Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Wed, 5 May 2010 14:29:28 +0000 Subject: [PATCH] add listbox example. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@698 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- examples/gui/SConscript | 1 + examples/gui/demo_view_listbox.c | 60 ++++++++++++++++++++++++++++++++ examples/gui/demo_workbench.c | 1 + 3 files changed, 62 insertions(+) create mode 100644 examples/gui/demo_view_listbox.c diff --git a/examples/gui/SConscript b/examples/gui/SConscript index 87fbfdb291..b1b85b1060 100644 --- a/examples/gui/SConscript +++ b/examples/gui/SConscript @@ -17,6 +17,7 @@ demo_view_label.c demo_view_mywidget.c demo_view_progressbar.c demo_view_radiobox.c +demo_view_listbox.c demo_view_slider.c demo_view_textbox.c demo_view_window.c diff --git a/examples/gui/demo_view_listbox.c b/examples/gui/demo_view_listbox.c new file mode 100644 index 0000000000..bc37f820c5 --- /dev/null +++ b/examples/gui/demo_view_listbox.c @@ -0,0 +1,60 @@ +/* + * 程序清单:label控件演示 + * + * 这个例子会在创建出的view上添加几个不同类型的label控件 + */ +#include "demo_view.h" +#include +#include + +const static struct rtgui_listbox_item items[] = +{ + {"list #0", RT_NULL}, + {"list #1", RT_NULL}, + {"list #2", RT_NULL}, + {"list #3", RT_NULL}, +}; + +static void on_items(rtgui_widget_t* widget, struct rtgui_event* event) +{ + rtgui_listbox_t* box; + /* get listbox */ + box = RTGUI_LISTBOX(widget); + + /* 打印当前的项 */ + rt_kprintf("current item: %d\n", box->current_item); +} + +/* 创建用于演示label控件的视图 */ +rtgui_view_t* demo_view_listbox(rtgui_workbench_t* workbench) +{ + rtgui_rect_t rect; + rtgui_view_t* view; + rtgui_label_t* label; + rtgui_listbox_t* box; + + /* 先创建一个演示用的视图 */ + view = demo_view(workbench, "ListBox Demo"); + + /* 获得视图的位置信息 */ + demo_view_get_rect(view, &rect); + rect.x1 += 5; + rect.x2 -= 5; + rect.y1 += 5; + rect.y2 = rect.y1 + 20; + /* 创建一个label控件 */ + label = rtgui_label_create("listbox: "); + /* 设置label的位置 */ + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + /* view是一个container控件,调用add_child方法添加这个label控件 */ + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + + rect.y1 = rect.y2 + 3; + rect.y2 = 250; + box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &rect); + rtgui_listbox_set_onitem(box, on_items); + /* view是一个container控件,调用add_child方法添加这个listbox控件 */ + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box)); + + return view; +} diff --git a/examples/gui/demo_workbench.c b/examples/gui/demo_workbench.c index 53a9e07abc..115d211e95 100644 --- a/examples/gui/demo_workbench.c +++ b/examples/gui/demo_workbench.c @@ -62,6 +62,7 @@ static void workbench_entry(void* parameter) demo_view_progressbar(workbench); demo_view_radiobox(workbench); demo_view_textbox(workbench); + demo_view_listbox(workbench); demo_view_slider(workbench); demo_view_mywidget(workbench); demo_view_image(workbench);