update view example.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@340 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-01-27 00:05:32 +00:00
parent 4c70ff59d3
commit b1e6049e8c
3 changed files with 101 additions and 5 deletions

View File

@ -1,15 +1,32 @@
#include "demo_view.h"
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
// #include <rtgui/widgets/fn_view.h>
#include <rtgui/widgets/filelist_view.h>
static rtgui_label_t* label;
void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
/* create a fn view */
rtgui_view_t *view;
/* create a file list view */
rtgui_filelist_view_t *view;
rtgui_workbench_t *workbench;
rtgui_rect_t rect;
view = rtgui_filelist_view_create(workbench, "/", "*.*");
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
{
char path[32];
/* set label */
rtgui_filelist_get_fullpath(view, path, sizeof(path));
rtgui_label_set_text(label, path);
}
/* ɾ³ý ÎļþÁбí ÊÓͼ */
rtgui_view_destroy(RTGUI_VIEW(view));
}
rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench)

View File

@ -0,0 +1,78 @@
#include "demo_view.h"
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/list_view.h>
static rtgui_workbench_t* workbench = RT_NULL;
static void listitem_action(void* parameter)
{
char label_text[32];
rtgui_win_t *win;
rtgui_label_t *label;
rtgui_rect_t rect = {0, 0, 150, 80};
int no = (int)parameter;
rtgui_rect_moveto(&rect, 20, 50);
/* 显示消息窗口 */
win = rtgui_win_create(RTGUI_TOPLEVEL(workbench),
"窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
rect.x1 += 20; rect.x2 -= 5;
rect.y1 += 5; rect.y2 = rect.y1 + 20;
rt_sprintf(label_text, "动作 %d", no);
label = rtgui_label_create(label_text);
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
/* 非模态显示窗口 */
rtgui_win_show(win, RT_FALSE);
}
static struct rtgui_list_item items[] =
{
{"列表项1", RT_NULL, listitem_action, (void*)1},
{"列表项2", RT_NULL, listitem_action, (void*)2},
{"列表项3", RT_NULL, listitem_action, (void*)3},
{"列表项4", RT_NULL, listitem_action, (void*)4},
{"列表项5", RT_NULL, listitem_action, (void*)5},
};
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
/* create a file list view */
rtgui_rect_t rect;
rtgui_list_view_t *view;
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item), &rect);
rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));
/* 模式显示视图 */
rtgui_view_show(RTGUI_VIEW(view), RT_FALSE);
}
rtgui_view_t* demo_listview_view(rtgui_workbench_t* workbench)
{
rtgui_rect_t rect;
rtgui_view_t* view;
rtgui_button_t* open_btn;
view = demo_view(workbench, "列表视图演示");
demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 80;
rect.y1 += 30; rect.y2 = rect.y1 + 20;
open_btn = rtgui_button_create("打开列表");
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
return view;
}

View File

@ -64,6 +64,7 @@ static void workbench_entry(void* parameter)
demo_view_radiobox(workbench);
demo_view_textbox(workbench);
demo_view_slider(workbench);
demo_listview_view(workbench);
demo_fn_view(workbench);
/* 显示视图 */