2010-03-08 07:30:15 +08:00
|
|
|
|
/*
|
|
|
|
|
* 程序清单:自定义控件演示
|
|
|
|
|
*
|
|
|
|
|
* 这个例子会在创建出的view上添加两个自定义控件
|
|
|
|
|
*/
|
2010-01-27 17:42:19 +08:00
|
|
|
|
#include "demo_view.h"
|
|
|
|
|
#include "mywidget.h"
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建用于演示自定义控件的视图 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
rtgui_view_t *demo_view_mywidget(rtgui_workbench_t* workbench)
|
|
|
|
|
{
|
|
|
|
|
rtgui_view_t *view;
|
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
rtgui_mywidget_t *mywidget;
|
|
|
|
|
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 先创建一个演示用的视图 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
view = demo_view(workbench, "MyWidget View");
|
|
|
|
|
|
2010-03-14 14:36:46 +08:00
|
|
|
|
/* 获得视图的位置信息 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
demo_view_get_rect(view, &rect);
|
2010-03-14 14:36:46 +08:00
|
|
|
|
rect.x1 += 5;
|
|
|
|
|
rect.x2 = rect.y1 + 80;
|
|
|
|
|
rect.y1 += 5;
|
|
|
|
|
rect.y2 = rect.y1 + 80;
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建一个自定义控件 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
mywidget = rtgui_mywidget_create(&rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* view是一个container控件,调用add_child方法添加这个自控件 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget));
|
|
|
|
|
|
2010-03-14 14:36:46 +08:00
|
|
|
|
/* 获得视图的位置信息 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
demo_view_get_rect(view, &rect);
|
2010-03-14 14:36:46 +08:00
|
|
|
|
rect.x1 += 25;
|
|
|
|
|
rect.x2 = rect.y1 + 40;
|
|
|
|
|
rect.y1 += 5 + 100;
|
|
|
|
|
rect.y2 = rect.y1 + 40;
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* 创建一个自定义控件 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
mywidget = rtgui_mywidget_create(&rect);
|
2010-03-08 07:30:15 +08:00
|
|
|
|
/* view是一个container控件,调用add_child方法添加这个自控件 */
|
2010-01-27 17:42:19 +08:00
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget));
|
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
}
|