demo_listview.c 2.5 KB
Newer Older
B
bernard.xiong 已提交
1 2 3 4 5 6 7
#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;
8
static rtgui_list_view_t* _view = RT_NULL;
9
static rtgui_image_t* return_image = RT_NULL;
B
bernard.xiong 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

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

B
bernard.xiong 已提交
25 26 27 28
	rect.x1 += 20;
	rect.x2 -= 5;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 20;
B
bernard.xiong 已提交
29 30 31 32 33 34 35 36 37 38 39

	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);
}

40 41 42 43
static void return_action(void* parameter)
{
	if (_view != RT_NULL)
	{
44
		rtgui_view_destroy(RTGUI_VIEW(_view));
45 46 47 48
		_view = RT_NULL;
	}
}

49
static struct rtgui_list_item items[] =
B
bernard.xiong 已提交
50 51 52 53 54 55
{
	{"б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},
B
bernard.xiong 已提交
56
	{"",    RT_NULL, return_action,    RT_NULL},
B
bernard.xiong 已提交
57 58 59 60 61 62 63 64 65 66
};

static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
	/* create a file list view */
	rtgui_rect_t rect;

	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);

B
bernard.xiong 已提交
67 68
	_view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item),
		&rect);
69
	rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view));
B
bernard.xiong 已提交
70 71

	/* ģʽʾͼ */
72
	rtgui_view_show(RTGUI_VIEW(_view), RT_FALSE);
B
bernard.xiong 已提交
73 74 75 76 77
}

rtgui_view_t* demo_listview_view(rtgui_workbench_t* workbench)
{
	rtgui_rect_t rect;
78
	rtgui_view_t *view;
B
bernard.xiong 已提交
79 80 81 82 83
	rtgui_button_t* open_btn;

	view = demo_view(workbench, "бͼʾ");

	demo_view_get_rect(view, &rect);
B
bernard.xiong 已提交
84 85 86 87
	rect.x1 += 5;
	rect.x2 = rect.x1 + 80;
	rect.y1 += 30;
	rect.y2 = rect.y1 + 20;
B
bernard.xiong 已提交
88 89 90 91 92 93 94
	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;
}