demo_view_radiobox.c 2.0 KB
Newer Older
B
bernard.xiong 已提交
1 2 3 4 5 6
/*
 * 程序清单:radiobox控件演示
 *
 * 这个例子会在创建出的view上添加两个不同方向的radiobox控件
 */

B
bernard.xiong 已提交
7 8 9
#include "demo_view.h"
#include <rtgui/widgets/radiobox.h>

B
bernard.xiong 已提交
10 11
/* 用于显示垂直方向的radio文本项数组 */
static char* radio_item_v[5] =
B
bernard.xiong 已提交
12 13 14 15 16 17 18
	{
		"one",
		"two",
		"three",
		"item 1",
		"item 2"
	};
B
bernard.xiong 已提交
19

B
bernard.xiong 已提交
20
/* 用于显示水平方向的radio文本项数组 */
B
bernard.xiong 已提交
21
static char* radio_item_h[3] =
B
bernard.xiong 已提交
22 23 24
	{
		"one", "two", "three"
	};
B
bernard.xiong 已提交
25

B
bernard.xiong 已提交
26
/* 创建用于演示radiobox控件的视图 */
B
bernard.xiong 已提交
27 28
rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench)
{
B
bernard.xiong 已提交
29 30 31
	rtgui_rect_t rect;
	rtgui_view_t* view;
	rtgui_radiobox_t* radiobox;
B
bernard.xiong 已提交
32

B
bernard.xiong 已提交
33
	/* 先创建一个演示用的视图 */
B
bernard.xiong 已提交
34
	view = demo_view(workbench, "RadioBox View");
B
bernard.xiong 已提交
35

B
bernard.xiong 已提交
36 37 38 39 40 41
	/* 获得视图的位置信息 */
	demo_view_get_rect(view, &rect);
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 5;
	rect.y2 = rect.y1 + 5 * 25;
B
bernard.xiong 已提交
42

B
bernard.xiong 已提交
43 44 45
	/* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
	radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
	/* 设置当前选择的数组是第0项 */
B
bernard.xiong 已提交
46
	rtgui_radiobox_set_selection(radiobox, 0);
B
bernard.xiong 已提交
47 48 49 50
	/* 添加radiobox控件到视图中 */
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
	/* 设置radiobox控件的位置信息 */
	rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
B
bernard.xiong 已提交
51

B
bernard.xiong 已提交
52
	/* 获得视图的位置信息 */
B
bernard.xiong 已提交
53
	demo_view_get_rect(view, &rect);
B
bernard.xiong 已提交
54 55 56 57
	rect.x1 += 5;
	rect.x2 -= 5;
	rect.y1 += 5 + 5 * 25;
	rect.y2 = rect.y1 + 60;
B
bernard.xiong 已提交
58

B
bernard.xiong 已提交
59 60 61
	/* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */
	radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
	/* 设置当前选择的数组是第0项 */
B
bernard.xiong 已提交
62
	rtgui_radiobox_set_selection(radiobox, 0);
B
bernard.xiong 已提交
63 64 65 66
	/* 添加radiobox控件到视图中 */
	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
	/* 设置radiobox控件的位置信息 */
	rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
B
bernard.xiong 已提交
67

B
bernard.xiong 已提交
68
	return view;
B
bernard.xiong 已提交
69
}