2010-01-14 17:59:07 +08:00
|
|
|
|
#include <rtgui/rtgui.h>
|
2010-01-18 07:41:59 +08:00
|
|
|
|
#include <rtgui/widgets/view.h>
|
|
|
|
|
#include <rtgui/widgets/button.h>
|
|
|
|
|
#include <rtgui/widgets/workbench.h>
|
2010-01-25 08:02:14 +08:00
|
|
|
|
#include <rtgui/widgets/staticline.h>
|
2010-01-18 07:41:59 +08:00
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 用于存放演示视图的数组,最多可创建32个演示视图 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
static rtgui_view_t* demo_view_list[32];
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 当前演示视图索引 */
|
|
|
|
|
static rt_uint16_t demo_view_current = 0;
|
|
|
|
|
/* 总共包括的演示视图数目 */
|
|
|
|
|
static rt_uint16_t demo_view_number = 0;
|
2010-01-18 07:41:59 +08:00
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 显示下一个演示视图 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
void demo_view_next(struct rtgui_widget* widget, rtgui_event_t *event)
|
2010-01-18 07:41:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (demo_view_current + 1< demo_view_number)
|
|
|
|
|
{
|
|
|
|
|
demo_view_current ++;
|
|
|
|
|
rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 显示前一个演示视图 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
void demo_view_prev(struct rtgui_widget* widget, rtgui_event_t *event)
|
2010-01-18 07:41:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (demo_view_current != 0)
|
|
|
|
|
{
|
|
|
|
|
demo_view_current --;
|
|
|
|
|
rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建一个演示视图,需提供父workbench和演示用的标题 */
|
2010-01-25 08:02:14 +08:00
|
|
|
|
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
|
2010-01-18 07:41:59 +08:00
|
|
|
|
{
|
|
|
|
|
char view_name[32];
|
|
|
|
|
struct rtgui_view* view;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 设置视图的名称 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rt_sprintf(view_name, "view %d", demo_view_number + 1);
|
|
|
|
|
view = rtgui_view_create(view_name);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
if (view == RT_NULL) return RT_NULL;
|
2010-01-18 07:41:59 +08:00
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建成功后,添加到数组中 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
demo_view_list[demo_view_number] = view;
|
|
|
|
|
demo_view_number ++;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 添加到父workbench中 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_workbench_add_view(workbench, view);
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 添加下一个视图和前一个视图按钮 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
{
|
|
|
|
|
struct rtgui_rect rect;
|
|
|
|
|
struct rtgui_button *next_btn, *prev_btn;
|
2010-01-21 18:05:06 +08:00
|
|
|
|
struct rtgui_label *label;
|
|
|
|
|
struct rtgui_staticline *line;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 获得视图的位置信息(在加入到workbench中时,workbench会自动调整视图的大小) */
|
2010-01-21 18:05:06 +08:00
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
|
|
|
|
rect.x1 += 5; rect.y1 += 5;
|
2010-01-25 08:02:14 +08:00
|
|
|
|
rect.x2 -= 5; rect.y2 = rect.y1 + 20;
|
2010-01-21 18:05:06 +08:00
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建标题用的标签 */
|
2010-01-25 08:02:14 +08:00
|
|
|
|
label = rtgui_label_create(title);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 设置标签位置信息 */
|
2010-01-21 18:05:06 +08:00
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 添加标签到视图中 */
|
2010-01-21 18:05:06 +08:00
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
2010-01-25 08:02:14 +08:00
|
|
|
|
|
2010-01-21 18:05:06 +08:00
|
|
|
|
rect.y1 += 20; rect.y2 += 20;
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建一个水平的staticline线 */
|
2010-01-21 18:05:06 +08:00
|
|
|
|
line = rtgui_staticline_create(RTGUI_HORIZONTAL);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 设置静态线的位置信息 */
|
2010-01-21 18:05:06 +08:00
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 添加静态线到视图中 */
|
2010-01-21 18:05:06 +08:00
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(line));
|
2010-01-18 07:41:59 +08:00
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 获得视图的位置信息 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
|
|
|
|
rect.x2 -= 5; rect.y2 -= 5;
|
|
|
|
|
rect.x1 = rect.x2 - 50; rect.y1 = rect.y2 - 20;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建"下一个"按钮 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
next_btn = rtgui_button_create("Next");
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 设置onbutton动作到demo_view_next函数 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_button_set_onbutton(next_btn, demo_view_next);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 设置按钮的位置信息 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 添加按钮到视图中 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(next_btn));
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 获得视图的位置信息 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
|
|
|
|
rect.x1 += 5; rect.y2 -= 5;
|
|
|
|
|
rect.x2 = rect.x1 + 50; rect.y1 = rect.y2 - 20;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建"上一个"按钮 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
prev_btn = rtgui_button_create("Prev");
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 设置onbutton动作到demo_view_prev函数 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_button_set_onbutton(prev_btn, demo_view_prev);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 设置按钮的位置信息 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 添加按钮到视图中 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(prev_btn));
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 返回创建的视图 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 这个函数用于返回演示视图的对外可用区域 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect)
|
|
|
|
|
{
|
|
|
|
|
RT_ASSERT(view != RT_NULL);
|
|
|
|
|
RT_ASSERT(rect != RT_NULL);
|
|
|
|
|
|
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(view), rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 去除演示标题和下方按钮的区域 */
|
2010-01-25 08:02:14 +08:00
|
|
|
|
rect->y1 += 45;
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rect->y2 -= 25;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 当是标准版本时,这个函数用于返回自动布局引擎box控件 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
#ifndef RTGUI_USING_SMALL_SIZE
|
|
|
|
|
rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient)
|
|
|
|
|
{
|
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
rtgui_box_t* box;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 获得视图的位置信息 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
2010-01-21 18:05:06 +08:00
|
|
|
|
rect.y1 += 45;
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rect.y2 -= 25;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建一个自动布局引擎 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
box = rtgui_box_create(orient, &rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 添加box控件到视图中 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
|
|
|
|
|
|
|
|
|
|
return box;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 这个函数用于显示当前的视图 */
|
2010-01-18 07:41:59 +08:00
|
|
|
|
void demo_view_show()
|
|
|
|
|
{
|
|
|
|
|
if (demo_view_number != 0)
|
|
|
|
|
{
|
2010-03-08 07:30:15 +08:00
|
|
|
|
rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE);
|
2010-01-18 07:41:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|