add Chinese comments.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@462 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-03-07 23:30:15 +00:00
parent 3a8f591e51
commit c770a71778
10 changed files with 261 additions and 47 deletions

View File

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

View File

@ -1,3 +1,16 @@
/*
* view演示
*
* GUI演示而制作的视图
* demo_view
*
*
*
*
*
*
* demo_view_get_rect函数
*/
#ifndef __DEMO_VIEW_H__ #ifndef __DEMO_VIEW_H__
#define __DEMO_VIEW_H__ #define __DEMO_VIEW_H__
@ -5,14 +18,18 @@
#include <rtgui/widgets/view.h> #include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h> #include <rtgui/widgets/workbench.h>
/* 如果是标准版本可以启用box自动布局引擎 */
#ifndef RTGUI_USING_SMALL_SIZE #ifndef RTGUI_USING_SMALL_SIZE
#include <rtgui/widgets/box.h> #include <rtgui/widgets/box.h>
#endif #endif
/* 创建一个演示视图需要给出这个视图所在的workbench和演示标题 */
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title); rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title);
/* 获得演示视图提供给演示控件用的区域信息 */
void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect); void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect);
void demo_view_show(void); void demo_view_show(void);
/* 如果是标准版,可以调用这个函数获得一个自动布局引擎 */
#ifndef RTGUI_USING_SMALL_SIZE #ifndef RTGUI_USING_SMALL_SIZE
rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient); rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient);
#endif #endif

View File

@ -1,6 +1,13 @@
/*
* button控件演示
*
* view上添加几个不同类型的button控件
*/
#include "demo_view.h" #include "demo_view.h"
#include <rtgui/widgets/button.h> #include <rtgui/widgets/button.h>
/* 创建用于演示button控件的视图 */
rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench) rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
@ -8,43 +15,62 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
rtgui_button_t* button; rtgui_button_t* button;
rtgui_font_t* font; rtgui_font_t* font;
/* create a demo view */ /* 先创建一个演示用的视图 */
view = demo_view(workbench, "Button View"); view = demo_view(workbench, "Button View");
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5; rect.y2 = rect.y1 + 20; rect.y1 += 5; rect.y2 = rect.y1 + 20;
/* 创建一个button控件 */
button = rtgui_button_create("Red"); button = rtgui_button_create("Red");
/* 设置label控件的前景色为红色 */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = red; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = red;
/* 设置button的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
/* view是一个container控件调用add_child方法添加这个button控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个button控件 */
button = rtgui_button_create("Blue"); button = rtgui_button_create("Blue");
/* 设置label控件的前景色为蓝色 */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = blue; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = blue;
/* 设置button的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
/* view是一个container控件调用add_child方法添加这个button控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个button控件 */
button = rtgui_button_create("12 font"); button = rtgui_button_create("12 font");
/* 设置字体为12点阵的asc字体 */
font = rtgui_font_refer("asc", 12); font = rtgui_font_refer("asc", 12);
RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font; RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font;
/* 设置button的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
/* view是一个container控件调用add_child方法添加这个button控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个button控件 */
button = rtgui_button_create("16 font"); button = rtgui_button_create("16 font");
/* 设置字体为16点阵的asc字体 */
font = rtgui_font_refer("asc", 16); font = rtgui_font_refer("asc", 16);
RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font; RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font;
/* 设置button的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
/* view是一个container控件调用add_child方法添加这个button控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
return view; return view;
} }

View File

@ -1,6 +1,13 @@
/*
* checkbox控件演示
*
* view上添加几个checkbox控件
*/
#include "demo_view.h" #include "demo_view.h"
#include <rtgui/widgets/checkbox.h> #include <rtgui/widgets/checkbox.h>
/* 创建用于演示checkbox控件的视图 */
rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench) rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
@ -8,44 +15,62 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
rtgui_checkbox_t* checkbox; rtgui_checkbox_t* checkbox;
rtgui_font_t* font; rtgui_font_t* font;
/* create a demo view */ /* 先创建一个演示用的视图 */
view = demo_view(workbench, "CheckBox View"); view = demo_view(workbench, "CheckBox View");
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5; rect.y2 = rect.y1 + 20; rect.y1 += 5; rect.y2 = rect.y1 + 20;
/* 创建一个checkbox控件 */
checkbox = rtgui_checkbox_create("Red"); checkbox = rtgui_checkbox_create("Red");
/* 设置前景色为红色 */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = red; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = red;
/* 设置checkbox的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
/* view是一个container控件调用add_child方法添加这个checkbox控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个checkbox控件 */
checkbox = rtgui_checkbox_create("Blue"); checkbox = rtgui_checkbox_create("Blue");
/* 设置前景色为蓝色 */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = blue; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = blue;
/* 设置checkbox的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
/* view是一个container控件调用add_child方法添加这个checkbox控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个checkbox控件 */
checkbox = rtgui_checkbox_create("12 font"); checkbox = rtgui_checkbox_create("12 font");
/* 设置字体为12点阵 */
font = rtgui_font_refer("asc", 12); font = rtgui_font_refer("asc", 12);
RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font; RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
/* 设置checkbox的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
/* view是一个container控件调用add_child方法添加这个checkbox控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 100; rect.x1 += 5; rect.x2 = rect.x1 + 100;
rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个checkbox控件 */
checkbox = rtgui_checkbox_create("16 font"); checkbox = rtgui_checkbox_create("16 font");
/* 设置字体为16点阵 */
font = rtgui_font_refer("asc", 16); font = rtgui_font_refer("asc", 16);
RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font; RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
/* 设置checkbox的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
/* view是一个container控件调用add_child方法添加这个checkbox控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
return view; return view;
} }

View File

@ -1,6 +1,12 @@
/*
* label控件演示
*
* view上添加几个不同类型的label控件
*/
#include "demo_view.h" #include "demo_view.h"
#include <rtgui/widgets/label.h> #include <rtgui/widgets/label.h>
/* 创建用于演示label控件的视图 */
rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench) rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
@ -8,52 +14,80 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
rtgui_label_t* label; rtgui_label_t* label;
rtgui_font_t* font; rtgui_font_t* font;
/* create a demo view */ /* 先创建一个演示用的视图 */
view = demo_view(workbench, "Label View"); view = demo_view(workbench, "Label View");
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 -= 5; rect.x1 += 5; rect.x2 -= 5;
rect.y1 += 5; rect.y2 = rect.y1 + 20; rect.y1 += 5; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("Red Left"); label = rtgui_label_create("Red Left");
/* 设置label控件上的文本对齐方式为左对齐 */
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_LEFT; RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_LEFT;
/* 设置label控件的前景色为红色 */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = red; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = red;
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* view是一个container控件调用add_child方法添加这个label控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 -= 5; rect.x1 += 5; rect.x2 -= 5;
rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("Blue Right"); label = rtgui_label_create("Blue Right");
/* 设置label控件上的文本对齐方式为右对齐 */
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_RIGHT; RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_RIGHT;
/* 设置label控件的前景色为蓝色 */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue;
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* view是一个container控件调用add_child方法添加这个label控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 -= 5; rect.x1 += 5; rect.x2 -= 5;
rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("Green Center"); label = rtgui_label_create("Green Center");
/* 设置label控件的前景色为绿色 */
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = green; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = green;
/* 设置label控件上的文本对齐方式为右对齐 */
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL; RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL;
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* view是一个container控件调用add_child方法添加这个label控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 -= 5; rect.x1 += 5; rect.x2 -= 5;
rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("12 font"); label = rtgui_label_create("12 font");
/* 设置字体为12点阵的asc字体 */
font = rtgui_font_refer("asc", 12); font = rtgui_font_refer("asc", 12);
RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font; RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* view是一个container控件调用add_child方法添加这个label控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x1 += 5;
rect.y1 += 5 + 25 + 25 + 25 + 25; rect.y2 = rect.y1 + 20; rect.y1 += 5 + 25 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("16 font"); label = rtgui_label_create("16 font");
/* 设置字体为16点阵的asc字体 */
font = rtgui_font_refer("asc", 16); font = rtgui_font_refer("asc", 16);
RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font; RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* view是一个container控件调用add_child方法添加这个label控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
return view; return view;

View File

@ -1,27 +1,37 @@
/*
*
*
* view上添加两个自定义控件
*/
#include "demo_view.h" #include "demo_view.h"
#include "mywidget.h" #include "mywidget.h"
/* 创建用于演示自定义控件的视图 */
rtgui_view_t *demo_view_mywidget(rtgui_workbench_t* workbench) rtgui_view_t *demo_view_mywidget(rtgui_workbench_t* workbench)
{ {
rtgui_view_t *view; rtgui_view_t *view;
rtgui_rect_t rect; rtgui_rect_t rect;
rtgui_mywidget_t *mywidget; rtgui_mywidget_t *mywidget;
/* create a demo view */ /* 先创建一个演示用的视图 */
view = demo_view(workbench, "MyWidget View"); view = demo_view(workbench, "MyWidget View");
/* get demo view rect */ /* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.y1 + 80; rect.x1 += 5; rect.x2 = rect.y1 + 80;
rect.y1 += 5; rect.y2 = rect.y1 + 80; rect.y1 += 5; rect.y2 = rect.y1 + 80;
/* 创建一个自定义控件 */
mywidget = rtgui_mywidget_create(&rect); mywidget = rtgui_mywidget_create(&rect);
/* view是一个container控件调用add_child方法添加这个自控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget));
/* get demo view rect */ /* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 25; rect.x2 = rect.y1 + 40; rect.x1 += 25; rect.x2 = rect.y1 + 40;
rect.y1 += 5 + 100; rect.y2 = rect.y1 + 40; rect.y1 += 5 + 100; rect.y2 = rect.y1 + 40;
/* 创建一个自定义控件 */
mywidget = rtgui_mywidget_create(&rect); mywidget = rtgui_mywidget_create(&rect);
/* view是一个container控件调用add_child方法添加这个自控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget));
return view; return view;

View File

@ -1,7 +1,14 @@
/*
* radiobox控件演示
*
* view上添加两个不同方向的radiobox控件
*/
#include "demo_view.h" #include "demo_view.h"
#include <rtgui/widgets/radiobox.h> #include <rtgui/widgets/radiobox.h>
static char* radio_item[5] = /* 用于显示垂直方向的radio文本项数组 */
static char* radio_item_v[5] =
{ {
"one", "one",
"two", "two",
@ -10,39 +17,49 @@ static char* radio_item[5] =
"item 2" "item 2"
}; };
/* 用于显示水平方向的radio文本项数组 */
static char* radio_item_h[3] = static char* radio_item_h[3] =
{ {
"one", "two", "three" "one", "two", "three"
}; };
/* 创建用于演示radiobox控件的视图 */
rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench) rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
rtgui_view_t* view; rtgui_view_t* view;
rtgui_radiobox_t* radiobox; rtgui_radiobox_t* radiobox;
/* 先创建一个演示用的视图 */
view = demo_view(workbench, "RadioBox View"); view = demo_view(workbench, "RadioBox View");
demo_view_get_rect(view, &rect);
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 -= 5; rect.x1 += 5; rect.x2 -= 5;
rect.y1 += 5; rect.y2 = rect.y1 + 5 * 25; rect.y1 += 5; rect.y2 = rect.y1 + 5 * 25;
radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item, 5); /* 创建一个垂直方向显示的radiobox控件文本项是radio_item_v数组共5个项 */
radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
/* 设置当前选择的数组是第0项 */
rtgui_radiobox_set_selection(radiobox, 0); rtgui_radiobox_set_selection(radiobox, 0);
/* 添加radiobox控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
/* 设置radiobox控件的位置信息 */
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
/* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 -= 5; rect.x1 += 5; rect.x2 -= 5;
rect.y1 += 5 + 5 * 25; rect.y2 = rect.y1 + 60; rect.y1 += 5 + 5 * 25; rect.y2 = rect.y1 + 60;
/* 创建一个水平方向显示的radiobox控件文本项是radio_item_h数组共3个项 */
radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3); radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
/* 设置当前选择的数组是第0项 */
rtgui_radiobox_set_selection(radiobox, 0); rtgui_radiobox_set_selection(radiobox, 0);
/* 添加radiobox控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
/* 设置radiobox控件的位置信息 */
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
return view; return view;
} }

View File

@ -1,7 +1,13 @@
/*
* texbox控件演示
*
* view上添加几个不同类型的textbox控件
*/
#include "demo_view.h" #include "demo_view.h"
#include <rtgui/widgets/label.h> #include <rtgui/widgets/label.h>
#include <rtgui/widgets/textbox.h> #include <rtgui/widgets/textbox.h>
/* 创建用于演示textbox控件的视图 */
rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench) rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench)
{ {
rtgui_rect_t rect, textbox_rect; rtgui_rect_t rect, textbox_rect;
@ -9,52 +15,79 @@ rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench)
rtgui_label_t* label; rtgui_label_t* label;
rtgui_textbox_t* text; rtgui_textbox_t* text;
/* create a demo view */ /* 先创建一个演示用的视图 */
view = demo_view(workbench, "TextBox View"); view = demo_view(workbench, "TextBox View");
/* add label */ /* 获得视图的位置信息 */
demo_view_get_rect(view, &rect); demo_view_get_rect(view, &rect);
rect.x1 += 5; rect.x2 = rect.x1 + 30; rect.x1 += 5; rect.x2 = rect.x1 + 30;
rect.y1 += 5; rect.y2 = rect.y1 + 20; rect.y1 += 5; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("Ãû×Ö: "); label = rtgui_label_create("Ãû×Ö: ");
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* view是一个container控件调用add_child方法添加这个label控件 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
/* 让textbox_rect赋值到rect以计算textbox控件的位置 */
textbox_rect = rect; textbox_rect = rect;
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
/* 创建一个textbox控件 */
text = rtgui_textbox_create("bernard"); text = rtgui_textbox_create("bernard");
/* 设置textbox控件的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
/* 添加textbox控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
/* 计算下一个label控件的位置 */
rect.y1 += 23; rect.y2 = rect.y1 + 20; rect.y1 += 23; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("Óʼþ: "); label = rtgui_label_create("Óʼþ: ");
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* 添加label控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
textbox_rect = rect; textbox_rect = rect;
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
/* 创建一个textbox控件 */
text = rtgui_textbox_create("bernard.xiong@gmail.com"); text = rtgui_textbox_create("bernard.xiong@gmail.com");
/* 设置textbox控件的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
/* 添加textbox控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
rect.y1 += 23; rect.y2 = rect.y1 + 20; rect.y1 += 23; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("ÃÜÂë: "); label = rtgui_label_create("ÃÜÂë: ");
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* 添加label控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
textbox_rect = rect; textbox_rect = rect;
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
/* 创建一个textbox控件 */
text = rtgui_textbox_create("rt-thread"); text = rtgui_textbox_create("rt-thread");
/* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */
text->flag |= RTGUI_TEXTBOX_MASK; text->flag |= RTGUI_TEXTBOX_MASK;
/* 设置textbox控件的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
/* 添加textbox控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
rect.y1 += 23; rect.y2 = rect.y1 + 20; rect.y1 += 23; rect.y2 = rect.y1 + 20;
/* 创建一个label控件 */
label = rtgui_label_create("Ö÷Ò³: "); label = rtgui_label_create("Ö÷Ò³: ");
/* 设置label的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
/* 添加label控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
textbox_rect = rect; textbox_rect = rect;
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
/* 创建一个textbox控件 */
text = rtgui_textbox_create("http://www.rt-thread.org"); text = rtgui_textbox_create("http://www.rt-thread.org");
/* 设置textbox控件的位置 */
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
/* 添加textbox控件到视图中 */
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
return view; return view;

View File

@ -68,9 +68,11 @@ static void rtgui_mywidget_onmouse(struct rtgui_mywidget* me, struct rtgui_event
} }
} }
static rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) /* mywidget控件的事件处理函数 */
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{ {
struct rtgui_mywidget* me = (struct rtgui_mywidget*)widget; /* 调用事件处理函数时widget指针指向控件本身所以先获得相应控件对象的指针 */
struct rtgui_mywidget* me = RTGUI_MYWIDGET(widget);
switch (event->type) switch (event->type)
{ {
@ -86,44 +88,47 @@ static rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struc
/* 其他事件调用父类的事件处理函数 */ /* 其他事件调用父类的事件处理函数 */
default: default:
rtgui_widget_event_handler(widget, event); return rtgui_widget_event_handler(widget, event);
} }
return RT_FALSE; return RT_FALSE;
} }
/* 自定义控件的构造函数 */
static void _rtgui_mywidget_constructor(rtgui_mywidget_t *mywidget) static void _rtgui_mywidget_constructor(rtgui_mywidget_t *mywidget)
{ {
/* 初始化控件并设置事件处理函数 */ /* 默认这个控件接收聚焦 */
RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* 初始化控件并设置事件处理函数 */
rtgui_widget_set_event_handler(RTGUI_WIDGET(mywidget), rtgui_mywidget_event_handler); rtgui_widget_set_event_handler(RTGUI_WIDGET(mywidget), rtgui_mywidget_event_handler);
/* 初始状态时OFF */
mywidget->status = MYWIDGET_STATUS_OFF; mywidget->status = MYWIDGET_STATUS_OFF;
} }
static void _rtgui_mywidget_destructor(rtgui_mywidget_t *mywidget) /* 获得控件的类型 */
{
}
rtgui_type_t *rtgui_mywidget_type_get(void) rtgui_type_t *rtgui_mywidget_type_get(void)
{ {
/* 控件的类型是一个静态变量默认是NULL */
static rtgui_type_t *mywidget_type = RT_NULL; static rtgui_type_t *mywidget_type = RT_NULL;
if (!mywidget_type) if (!mywidget_type)
{ {
/* 当控件类型不存在时,创建它,并指定这种类型数据的大小及指定相应的构造函数和析构函数 */
mywidget_type = rtgui_type_create("mywidget", RTGUI_WIDGET_TYPE, mywidget_type = rtgui_type_create("mywidget", RTGUI_WIDGET_TYPE,
sizeof(rtgui_mywidget_t), sizeof(rtgui_mywidget_t),
RTGUI_CONSTRUCTOR(_rtgui_mywidget_constructor), RTGUI_CONSTRUCTOR(_rtgui_mywidget_constructor), RT_NULL);
RTGUI_DESTRUCTOR(_rtgui_mywidget_destructor));
} }
return mywidget_type; return mywidget_type;
} }
/* 创建一个自定义控件 */
struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r) struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r)
{ {
struct rtgui_mywidget* me; struct rtgui_mywidget* me;
/* 让rtgui_widget创建出一个指定类型RTGUI_MYWIDGET_TYPE类型的控件 */
me = (struct rtgui_mywidget*) rtgui_widget_create (RTGUI_MYWIDGET_TYPE); me = (struct rtgui_mywidget*) rtgui_widget_create (RTGUI_MYWIDGET_TYPE);
if (me != RT_NULL) if (me != RT_NULL)
{ {
@ -133,6 +138,7 @@ struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r)
return me; return me;
} }
/* 删除一个自定义控件 */
void rtgui_mywidget_destroy(struct rtgui_mywidget* me) void rtgui_mywidget_destroy(struct rtgui_mywidget* me)
{ {
rtgui_widget_destroy(RTGUI_WIDGET(me)); rtgui_widget_destroy(RTGUI_WIDGET(me));

View File

@ -1,22 +1,34 @@
/*
*
*
*
* |
* --o--
* |
* o色彩表示了当前的状态ON状态时是绿色OFF状态时是红色
* o位置接受鼠标点击
*/
#ifndef __MY_WIDGET_H__ #ifndef __MY_WIDGET_H__
#define __MY_WIDGET_H__ #define __MY_WIDGET_H__
#include <rtgui/rtgui.h> #include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h> #include <rtgui/widgets/widget.h>
/* 自定义控件的状态值定义 */
#define MYWIDGET_STATUS_ON 1 #define MYWIDGET_STATUS_ON 1
#define MYWIDGET_STATUS_OFF 0 #define MYWIDGET_STATUS_OFF 0
/** Gets the type of a button */ /** 每个控件会有一个类型,通过如下的宏获得控件相应的类型信息 */
#define RTGUI_MYWIDGET_TYPE (rtgui_mywidget_type_get()) #define RTGUI_MYWIDGET_TYPE (rtgui_mywidget_type_get())
/** Casts the object to an rtgui_button */ /** 对一个对象实例,可以通过下面的宏实现类型转换 */
#define RTGUI_MYWIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MYWIDGET_TYPE, rtgui_mywidget_t)) #define RTGUI_MYWIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MYWIDGET_TYPE, rtgui_mywidget_t))
/** Checks if the object is an rtgui_button */ /** 可以通过下面的宏以决定一个具体实例是否是自定义控件类型 */
#define RTGUI_IS_MYWIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MYWIDGET_TYPE)) #define RTGUI_IS_MYWIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MYWIDGET_TYPE))
/* 个性化控件 */ /* 个性化控件类定义 */
struct rtgui_mywidget struct rtgui_mywidget
{ {
/* 这个控件是继承自rtgui_widget控件 */
struct rtgui_widget parent; struct rtgui_widget parent;
/* 状态ON、OFF */ /* 状态ON、OFF */
@ -24,7 +36,17 @@ struct rtgui_mywidget
}; };
typedef struct rtgui_mywidget rtgui_mywidget_t; typedef struct rtgui_mywidget rtgui_mywidget_t;
/* 这个函数用于获得自定义控件的类型 */
rtgui_type_t *rtgui_mywidget_type_get(void);
/* 控件的创建和删除 */
struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r); struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r);
void rtgui_mywidget_destroy(struct rtgui_mywidget* me); void rtgui_mywidget_destroy(struct rtgui_mywidget* me);
/* 控件的默认事件处理函数。
*
*
*/
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
#endif #endif