add Chinese Comments
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@481 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
f05df1f97b
commit
e48f777a6d
|
@ -6,7 +6,7 @@
|
|||
static rtgui_label_t* label;
|
||||
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
{
|
||||
/* create a file list view */
|
||||
/* create a file list view */
|
||||
rtgui_filelist_view_t *view;
|
||||
rtgui_workbench_t *workbench;
|
||||
rtgui_rect_t rect;
|
||||
|
@ -35,31 +35,35 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
|
||||
rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_button_t* open_btn;
|
||||
rtgui_font_t* font;
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_button_t* open_btn;
|
||||
rtgui_font_t* font;
|
||||
|
||||
font = rtgui_font_refer("asc", 12);
|
||||
|
||||
view = demo_view(workbench, "FileList View");
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
label = rtgui_label_create("fn: ");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
label = rtgui_label_create("fn: ");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 80;
|
||||
rect.y1 += 30; rect.y2 = rect.y1 + 20;
|
||||
open_btn = rtgui_button_create("Open File");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 80;
|
||||
rect.y1 += 30;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
open_btn = rtgui_button_create("Open File");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
|
||||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font;
|
||||
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
|
||||
|
||||
return view;
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,10 @@ static void listitem_action(void* parameter)
|
|||
win = rtgui_win_create(RTGUI_TOPLEVEL(workbench),
|
||||
"窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
|
||||
rect.x1 += 20; rect.x2 -= 5;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 20;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
|
||||
rt_sprintf(label_text, "动作 %d", no);
|
||||
label = rtgui_label_create(label_text);
|
||||
|
@ -51,7 +53,7 @@ static struct rtgui_list_item items[] =
|
|||
{"列表项3", RT_NULL, listitem_action, (void*)3},
|
||||
{"列表项4", RT_NULL, listitem_action, (void*)4},
|
||||
{"列表项5", RT_NULL, listitem_action, (void*)5},
|
||||
{"·µ»Ø", RT_NULL, return_action, RT_NULL},
|
||||
{"·µ»Ø", RT_NULL, return_action, RT_NULL},
|
||||
};
|
||||
|
||||
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
|
@ -62,7 +64,8 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
||||
|
||||
_view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item), &rect);
|
||||
_view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item),
|
||||
&rect);
|
||||
rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view));
|
||||
|
||||
/* 模式显示视图 */
|
||||
|
@ -78,8 +81,10 @@ rtgui_view_t* demo_listview_view(rtgui_workbench_t* workbench)
|
|||
view = demo_view(workbench, "列表视图演示");
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 80;
|
||||
rect.y1 += 30; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 80;
|
||||
rect.y1 += 30;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
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);
|
||||
|
|
|
@ -34,32 +34,34 @@ 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)
|
||||
{
|
||||
char view_name[32];
|
||||
struct rtgui_view* view;
|
||||
char view_name[32];
|
||||
struct rtgui_view* view;
|
||||
|
||||
/* 设置视图的名称 */
|
||||
rt_sprintf(view_name, "view %d", demo_view_number + 1);
|
||||
view = rtgui_view_create(view_name);
|
||||
if (view == RT_NULL) return RT_NULL;
|
||||
/* 设置视图的名称 */
|
||||
rt_sprintf(view_name, "view %d", demo_view_number + 1);
|
||||
view = rtgui_view_create(view_name);
|
||||
if (view == RT_NULL) return RT_NULL;
|
||||
|
||||
/* 创建成功后,添加到数组中 */
|
||||
demo_view_list[demo_view_number] = view;
|
||||
demo_view_number ++;
|
||||
|
||||
/* 添加到父workbench中 */
|
||||
/* 添加到父workbench中 */
|
||||
rtgui_workbench_add_view(workbench, view);
|
||||
|
||||
/* 添加下一个视图和前一个视图按钮 */
|
||||
{
|
||||
struct rtgui_rect rect;
|
||||
struct rtgui_button *next_btn, *prev_btn;
|
||||
/* 添加下一个视图和前一个视图按钮 */
|
||||
{
|
||||
struct rtgui_rect rect;
|
||||
struct rtgui_button *next_btn, *prev_btn;
|
||||
struct rtgui_label *label;
|
||||
struct rtgui_staticline *line;
|
||||
|
||||
/* 获得视图的位置信息(在加入到workbench中时,workbench会自动调整视图的大小) */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rect.x1 += 5; rect.y1 += 5;
|
||||
rect.x2 -= 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.y1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
|
||||
/* 创建标题用的标签 */
|
||||
label = rtgui_label_create(title);
|
||||
|
@ -68,7 +70,8 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
|
|||
/* 添加标签到视图中 */
|
||||
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);
|
||||
/* 设置静态线的位置信息 */
|
||||
|
@ -78,12 +81,14 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
|
|||
|
||||
/* 获得视图的位置信息 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rect.x2 -= 5; rect.y2 -= 5;
|
||||
rect.x1 = rect.x2 - 50; rect.y1 = rect.y2 - 20;
|
||||
rect.x2 -= 5;
|
||||
rect.y2 -= 5;
|
||||
rect.x1 = rect.x2 - 50;
|
||||
rect.y1 = rect.y2 - 20;
|
||||
|
||||
/* 创建"下一个"按钮 */
|
||||
next_btn = rtgui_button_create("Next");
|
||||
/* 设置onbutton动作到demo_view_next函数 */
|
||||
next_btn = rtgui_button_create("Next");
|
||||
/* 设置onbutton动作到demo_view_next函数 */
|
||||
rtgui_button_set_onbutton(next_btn, demo_view_next);
|
||||
/* 设置按钮的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
|
||||
|
@ -92,8 +97,10 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
|
|||
|
||||
/* 获得视图的位置信息 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rect.x1 += 5; rect.y2 -= 5;
|
||||
rect.x2 = rect.x1 + 50; rect.y1 = rect.y2 - 20;
|
||||
rect.x1 += 5;
|
||||
rect.y2 -= 5;
|
||||
rect.x2 = rect.x1 + 50;
|
||||
rect.y1 = rect.y2 - 20;
|
||||
|
||||
/* 创建"上一个"按钮 */
|
||||
prev_btn = rtgui_button_create("Prev");
|
||||
|
@ -103,9 +110,9 @@ rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
|
|||
rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
|
||||
/* 添加按钮到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(prev_btn));
|
||||
}
|
||||
}
|
||||
|
||||
/* 返回创建的视图 */
|
||||
/* 返回创建的视图 */
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -133,7 +140,7 @@ rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient)
|
|||
rect.y1 += 45;
|
||||
rect.y2 -= 25;
|
||||
|
||||
/* 创建一个自动布局引擎 */
|
||||
/* 创建一个自动布局引擎 */
|
||||
box = rtgui_box_create(orient, &rect);
|
||||
/* 添加box控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
|
||||
|
|
|
@ -18,10 +18,12 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "Button View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("Red");
|
||||
/* 设置label控件的前景色为红色 */
|
||||
|
@ -31,10 +33,12 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("Blue");
|
||||
/* 设置label控件的前景色为蓝色 */
|
||||
|
@ -44,10 +48,12 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("12 font");
|
||||
/* 设置字体为12点阵的asc字体 */
|
||||
|
@ -58,10 +64,12 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个button控件 */
|
||||
button = rtgui_button_create("16 font");
|
||||
/* 设置字体为16点阵的asc字体 */
|
||||
|
|
|
@ -18,10 +18,12 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "CheckBox View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("Red",RT_TRUE);
|
||||
/* 设置前景色为红色 */
|
||||
|
@ -31,10 +33,12 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("Blue",RT_TRUE);
|
||||
/* 设置前景色为蓝色 */
|
||||
|
@ -44,10 +48,12 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("12 font",RT_TRUE);
|
||||
/* 设置字体为12点阵 */
|
||||
|
@ -58,10 +64,12 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个checkbox控件 */
|
||||
checkbox = rtgui_checkbox_create("16 font",RT_TRUE);
|
||||
/* 设置字体为16点阵 */
|
||||
|
|
|
@ -55,41 +55,59 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
|||
rtgui_rect_t rect = {0, 0, 16, 16};
|
||||
rtgui_rect_moveto(&rect, 30, 120);
|
||||
|
||||
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
|
||||
rect.x1 += 20; rect.x2 += 20 + 50;
|
||||
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
|
||||
rect.x1 += 20;
|
||||
rect.x2 += 20 + 50;
|
||||
rtgui_dc_draw_text(dc, "raise", &rect);
|
||||
rect.x1 -= 20; rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20; rect.y2 += 20;
|
||||
rect.x1 -= 20;
|
||||
rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
|
||||
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SIMPLE);
|
||||
rect.x1 += 20; rect.x2 += 20 + 50;
|
||||
rect.x1 += 20;
|
||||
rect.x2 += 20 + 50;
|
||||
rtgui_dc_draw_text(dc, "simple", &rect);
|
||||
rect.x1 -= 20; rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20; rect.y2 += 20;
|
||||
rect.x1 -= 20;
|
||||
rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
|
||||
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
|
||||
rect.x1 += 20; rect.x2 += 20 + 50;
|
||||
rect.x1 += 20;
|
||||
rect.x2 += 20 + 50;
|
||||
rtgui_dc_draw_text(dc, "sunken", &rect);
|
||||
rect.x1 -= 20; rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20; rect.y2 += 20;
|
||||
rect.x1 -= 20;
|
||||
rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
|
||||
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
|
||||
rect.x1 += 20; rect.x2 += 20 + 50;
|
||||
rect.x1 += 20;
|
||||
rect.x2 += 20 + 50;
|
||||
rtgui_dc_draw_text(dc, "box", &rect);
|
||||
rect.x1 -= 20; rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20; rect.y2 += 20;
|
||||
rect.x1 -= 20;
|
||||
rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
|
||||
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC);
|
||||
rect.x1 += 20; rect.x2 += 20 + 50;
|
||||
rect.x1 += 20;
|
||||
rect.x2 += 20 + 50;
|
||||
rtgui_dc_draw_text(dc, "static", &rect);
|
||||
rect.x1 -= 20; rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20; rect.y2 += 20;
|
||||
rect.x1 -= 20;
|
||||
rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
|
||||
rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_EXTRA);
|
||||
rect.x1 += 20; rect.x2 += 20 + 50;
|
||||
rect.x1 += 20;
|
||||
rect.x2 += 20 + 50;
|
||||
rtgui_dc_draw_text(dc, "extra", &rect);
|
||||
rect.x1 -= 20; rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20; rect.y2 += 20;
|
||||
rect.x1 -= 20;
|
||||
rect.x2 -= 20 + 50;
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
}
|
||||
/* »æͼÍê³É */
|
||||
rtgui_dc_end_drawing(dc);
|
||||
|
|
|
@ -17,10 +17,12 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "Label View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个label控件 */
|
||||
label = rtgui_label_create("Red Left");
|
||||
/* 设置label控件上的文本对齐方式为:左对齐 */
|
||||
|
@ -32,10 +34,12 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个label控件 */
|
||||
label = rtgui_label_create("Blue Right");
|
||||
/* 设置label控件上的文本对齐方式为:右对齐 */
|
||||
|
@ -47,10 +51,12 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个label控件 */
|
||||
label = rtgui_label_create("Green Center");
|
||||
/* 设置label控件的前景色为绿色 */
|
||||
|
@ -62,10 +68,12 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个label控件 */
|
||||
label = rtgui_label_create("12 font");
|
||||
/* 设置字体为12点阵的asc字体 */
|
||||
|
@ -76,10 +84,11 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
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");
|
||||
/* 设置字体为16点阵的asc字体 */
|
||||
|
|
|
@ -16,19 +16,23 @@ rtgui_view_t *demo_view_mywidget(rtgui_workbench_t* workbench)
|
|||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "MyWidget View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.y1 + 80;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 80;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.y1 + 80;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 80;
|
||||
/* 创建一个自定义控件 */
|
||||
mywidget = rtgui_mywidget_create(&rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个自控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(mywidget));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 25; rect.x2 = rect.y1 + 40;
|
||||
rect.y1 += 5 + 100; rect.y2 = rect.y1 + 40;
|
||||
rect.x1 += 25;
|
||||
rect.x2 = rect.y1 + 40;
|
||||
rect.y1 += 5 + 100;
|
||||
rect.y2 = rect.y1 + 40;
|
||||
/* 创建一个自定义控件 */
|
||||
mywidget = rtgui_mywidget_create(&rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个自控件 */
|
||||
|
|
|
@ -9,57 +9,61 @@
|
|||
|
||||
/* 用于显示垂直方向的radio文本项数组 */
|
||||
static char* radio_item_v[5] =
|
||||
{
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
"item 1",
|
||||
"item 2"
|
||||
};
|
||||
{
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
"item 1",
|
||||
"item 2"
|
||||
};
|
||||
|
||||
/* 用于显示水平方向的radio文本项数组 */
|
||||
static char* radio_item_h[3] =
|
||||
{
|
||||
"one", "two", "three"
|
||||
};
|
||||
{
|
||||
"one", "two", "three"
|
||||
};
|
||||
|
||||
/* 创建用于演示radiobox控件的视图 */
|
||||
rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_radiobox_t* radiobox;
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_radiobox_t* radiobox;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "RadioBox View");
|
||||
view = demo_view(workbench, "RadioBox View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 5 * 25;
|
||||
|
||||
/* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
|
||||
radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
|
||||
/* 设置当前选择的数组是第0项 */
|
||||
rtgui_radiobox_set_selection(radiobox, 0);
|
||||
/* 添加radiobox控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
|
||||
/* 设置radiobox控件的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5 + 5 * 25; rect.y2 = rect.y1 + 60;
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 5 * 25;
|
||||
|
||||
/* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */
|
||||
radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
|
||||
/* 设置当前选择的数组是第0项 */
|
||||
/* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
|
||||
radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
|
||||
/* 设置当前选择的数组是第0项 */
|
||||
rtgui_radiobox_set_selection(radiobox, 0);
|
||||
/* 添加radiobox控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
|
||||
/* 设置radiobox控件的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
|
||||
/* 添加radiobox控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
|
||||
/* 设置radiobox控件的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
|
||||
|
||||
return view;
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
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);
|
||||
/* 设置当前选择的数组是第0项 */
|
||||
rtgui_radiobox_set_selection(radiobox, 0);
|
||||
/* 添加radiobox控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
|
||||
/* 设置radiobox控件的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,12 @@ rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench)
|
|||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "TextBox View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 30;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 30;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个label控件 */
|
||||
label = rtgui_label_create("名字: ");
|
||||
/* 设置label的位置 */
|
||||
|
@ -29,65 +31,72 @@ rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench)
|
|||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
|
||||
/* 让textbox_rect赋值到rect,以计算textbox控件的位置 */
|
||||
/* 让textbox_rect赋值到rect,以计算textbox控件的位置 */
|
||||
textbox_rect = rect;
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5;
|
||||
textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
text = rtgui_textbox_create("bernard",RTGUI_TEXTBOX_SINGLE);
|
||||
/* 设置textbox控件的位置 */
|
||||
/* 设置textbox控件的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
/* 添加textbox控件到视图中 */
|
||||
/* 添加textbox控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
|
||||
|
||||
/* 计算下一个label控件的位置 */
|
||||
rect.y1 += 23; rect.y2 = rect.y1 + 20;
|
||||
/* 计算下一个label控件的位置 */
|
||||
rect.y1 += 23;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个label控件 */
|
||||
label = rtgui_label_create("邮件: ");
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* 添加label控件到视图中 */
|
||||
/* 添加label控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
textbox_rect = rect;
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5;
|
||||
textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
text = rtgui_textbox_create("bernard.xiong@gmail.com",RTGUI_TEXTBOX_SINGLE);
|
||||
/* 设置textbox控件的位置 */
|
||||
/* 设置textbox控件的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
/* 添加textbox控件到视图中 */
|
||||
/* 添加textbox控件到视图中 */
|
||||
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_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* 添加label控件到视图中 */
|
||||
/* 添加label控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
textbox_rect = rect;
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5;
|
||||
textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
text = rtgui_textbox_create("rt-thread",RTGUI_TEXTBOX_SINGLE);
|
||||
/* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */
|
||||
/* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */
|
||||
text->flag |= RTGUI_TEXTBOX_MASK;
|
||||
/* 设置textbox控件的位置 */
|
||||
/* 设置textbox控件的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
/* 添加textbox控件到视图中 */
|
||||
/* 添加textbox控件到视图中 */
|
||||
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_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* 添加label控件到视图中 */
|
||||
/* 添加label控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
textbox_rect = rect;
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
textbox_rect.x1 = textbox_rect.x2 + 5;
|
||||
textbox_rect.x2 = textbox_rect.x1 + 160;
|
||||
/* 创建一个textbox控件 */
|
||||
text = rtgui_textbox_create("http://www.rt-thread.org",RTGUI_TEXTBOX_SINGLE);
|
||||
/* 设置textbox控件的位置 */
|
||||
/* 设置textbox控件的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
|
||||
/* 添加textbox控件到视图中 */
|
||||
/* 添加textbox控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
|
||||
|
||||
return view;
|
||||
|
|
|
@ -11,6 +11,7 @@ static struct rtgui_win* msgbox = RT_NULL;
|
|||
static rt_uint8_t label_text[80];
|
||||
static rt_uint8_t cnt = 5;
|
||||
|
||||
/* 获取一个递增的窗口标题 */
|
||||
static char* get_win_title()
|
||||
{
|
||||
static rt_uint8_t win_no = 0;
|
||||
|
@ -20,6 +21,7 @@ static char* get_win_title()
|
|||
return win_title;
|
||||
}
|
||||
|
||||
/* 窗口关闭时的事件处理 */
|
||||
void window_demo_close(struct rtgui_widget* widget, rtgui_event_t *even)
|
||||
{
|
||||
rtgui_win_t* win;
|
||||
|
@ -34,61 +36,48 @@ void window_demo_close(struct rtgui_widget* widget, rtgui_event_t *even)
|
|||
/* 关闭对话框时的回调函数 */
|
||||
void diag_close(struct rtgui_timer* timer, void* parameter)
|
||||
{
|
||||
cnt --;
|
||||
sprintf(label_text, "closed then %d second!", cnt);
|
||||
|
||||
/* 设置标签文本并更新控件 */
|
||||
rtgui_label_set_text(label, label_text);
|
||||
rtgui_widget_update(RTGUI_WIDGET(label));
|
||||
|
||||
if (cnt == 0)
|
||||
{
|
||||
/* 超时,关闭对话框 */
|
||||
rtgui_win_destroy(msgbox);
|
||||
|
||||
/* 停止并删除定时器 */
|
||||
rtgui_timer_stop(timer);
|
||||
rtgui_timer_destory(timer);
|
||||
}
|
||||
|
||||
cnt --;
|
||||
}
|
||||
|
||||
void window_demo_autoclose(rtgui_toplevel_t* parent)
|
||||
{
|
||||
struct rtgui_rect rect = {50, 50, 200, 200};
|
||||
|
||||
msgbox = rtgui_win_create(parent, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
if (msgbox != RT_NULL)
|
||||
{
|
||||
cnt = 5;
|
||||
sprintf(label_text, "closed then %d second!", cnt);
|
||||
label = rtgui_label_create(label_text);
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(msgbox), RTGUI_WIDGET(label));
|
||||
|
||||
rtgui_win_show(msgbox, RT_FALSE);
|
||||
}
|
||||
|
||||
timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
|
||||
rtgui_timer_start(timer);
|
||||
}
|
||||
|
||||
static rt_uint16_t delta_x = 20;
|
||||
static rt_uint16_t delta_y = 40;
|
||||
|
||||
/* 显示正常窗口 */
|
||||
void window_demo_normal(rtgui_toplevel_t* parent)
|
||||
/* 触发正常窗口显示 */
|
||||
static void demo_win_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_win_t *win;
|
||||
rtgui_label_t *label;
|
||||
rtgui_toplevel_t *parent;
|
||||
rtgui_rect_t rect = {0, 0, 150, 80};
|
||||
|
||||
parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_rect_moveto(&rect, delta_x, delta_y);
|
||||
delta_x += 20; delta_y += 20;
|
||||
delta_x += 20;
|
||||
delta_y += 20;
|
||||
|
||||
/* 创建一个窗口 */
|
||||
win = rtgui_win_create(parent,
|
||||
get_win_title(), &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
|
||||
rect.x1 += 20; rect.x2 -= 5;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 20;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
|
||||
label = rtgui_label_create("这是一个普通窗口");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
|
@ -98,21 +87,58 @@ void window_demo_normal(rtgui_toplevel_t* parent)
|
|||
rtgui_win_show(win, RT_FALSE);
|
||||
}
|
||||
|
||||
void window_demo_modal(rtgui_toplevel_t* parent)
|
||||
/* 触发自动窗口显示 */
|
||||
static void demo_autowin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_toplevel_t *parent;
|
||||
struct rtgui_rect rect =
|
||||
{
|
||||
50, 50, 200, 200
|
||||
};
|
||||
|
||||
parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
|
||||
msgbox = rtgui_win_create(parent, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
if (msgbox != RT_NULL)
|
||||
{
|
||||
cnt = 5;
|
||||
sprintf(label_text, "closed then %d second!", cnt);
|
||||
label = rtgui_label_create(label_text);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(msgbox), RTGUI_WIDGET(label));
|
||||
|
||||
rtgui_win_show(msgbox, RT_FALSE);
|
||||
}
|
||||
|
||||
/* 创建一个定时器 */
|
||||
timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
|
||||
rtgui_timer_start(timer);
|
||||
}
|
||||
|
||||
/* 触发模态窗口显示 */
|
||||
static void demo_modalwin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_win_t *win;
|
||||
rtgui_label_t *label;
|
||||
rtgui_toplevel_t *parent;
|
||||
rtgui_rect_t rect = {0, 0, 150, 80};
|
||||
|
||||
parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_rect_moveto(&rect, delta_x, delta_y);
|
||||
delta_x += 20; delta_y += 20;
|
||||
delta_x += 20;
|
||||
delta_y += 20;
|
||||
|
||||
/* 创建一个窗口 */
|
||||
win = rtgui_win_create(parent,
|
||||
get_win_title(), &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
|
||||
rect.x1 += 20; rect.x2 -= 5;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 20;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
|
||||
label = rtgui_label_create("这是一个模式窗口");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
|
@ -124,17 +150,21 @@ void window_demo_modal(rtgui_toplevel_t* parent)
|
|||
rtgui_win_destroy(win);
|
||||
}
|
||||
|
||||
void window_demo_notitle(rtgui_toplevel_t* parent)
|
||||
/* 触发无标题窗口显示 */
|
||||
static void demo_ntitlewin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_win_t *win;
|
||||
rtgui_label_t *label;
|
||||
rtgui_button_t *button;
|
||||
rtgui_toplevel_t *parent;
|
||||
rtgui_rect_t widget_rect, rect = {0, 0, 150, 80};
|
||||
|
||||
parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_rect_moveto(&rect, delta_x, delta_y);
|
||||
delta_x += 20; delta_y += 20;
|
||||
delta_x += 20;
|
||||
delta_y += 20;
|
||||
|
||||
/* 创建一个窗口 */
|
||||
/* 创建一个窗口,风格为无标题及无边框 */
|
||||
win = rtgui_win_create(parent,
|
||||
"no title", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
|
||||
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win)) = white;
|
||||
|
@ -143,16 +173,20 @@ void window_demo_notitle(rtgui_toplevel_t* parent)
|
|||
label = rtgui_label_create("无边框窗口");
|
||||
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)), "无边框窗口", &widget_rect);
|
||||
rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
|
||||
widget_rect.y1 += 20; widget_rect.y2 += 20;
|
||||
widget_rect.y1 += 20;
|
||||
widget_rect.y2 += 20;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &widget_rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
|
||||
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white;
|
||||
|
||||
/* 创建一个关闭按钮 */
|
||||
widget_rect.x1 = 0; widget_rect.y1 = 0;
|
||||
widget_rect.x2 = 40; widget_rect.y2 = 20;
|
||||
widget_rect.x1 = 0;
|
||||
widget_rect.y1 = 0;
|
||||
widget_rect.x2 = 40;
|
||||
widget_rect.y2 = 20;
|
||||
rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
|
||||
widget_rect.y1 += 40; widget_rect.y2 += 40;
|
||||
widget_rect.y1 += 40;
|
||||
widget_rect.y2 += 40;
|
||||
button = rtgui_button_create("关闭");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button));
|
||||
|
@ -162,65 +196,62 @@ void window_demo_notitle(rtgui_toplevel_t* parent)
|
|||
rtgui_win_show(win, RT_FALSE);
|
||||
}
|
||||
|
||||
static void demo_win_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
window_demo_normal(RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget)));
|
||||
}
|
||||
|
||||
static void demo_autowin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
window_demo_autoclose(RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget)));
|
||||
}
|
||||
|
||||
static void demo_modalwin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
window_demo_modal(RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget)));
|
||||
}
|
||||
|
||||
static void demo_ntitlewin_onbutton(struct rtgui_widget* widget, rtgui_event_t* event)
|
||||
{
|
||||
window_demo_notitle(RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget)));
|
||||
}
|
||||
|
||||
rtgui_view_t* demo_view_window(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_button_t *button;
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_button_t *button;
|
||||
|
||||
view = demo_view(workbench, "Window Demo");
|
||||
/* 创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "Window Demo");
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建按钮用于显示正常窗口 */
|
||||
button = rtgui_button_create("Normal Win");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_button_set_onbutton(button, demo_win_onbutton);
|
||||
/* 设置onbutton为demo_win_onbutton函数 */
|
||||
rtgui_button_set_onbutton(button, demo_win_onbutton);
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建按钮用于显示一个自动关闭的窗口 */
|
||||
button = rtgui_button_create("Auto Win");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_button_set_onbutton(button, demo_autowin_onbutton);
|
||||
/* 设置onbutton为demo_autowin_onbutton函数 */
|
||||
rtgui_button_set_onbutton(button, demo_autowin_onbutton);
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建按钮用于触发一个模式窗口 */
|
||||
button = rtgui_button_create("Modal Win");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_button_set_onbutton(button, demo_modalwin_onbutton);
|
||||
/* 设置onbutton为demo_modalwin_onbutton函数 */
|
||||
rtgui_button_set_onbutton(button, demo_modalwin_onbutton);
|
||||
|
||||
demo_view_get_rect(view, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25; rect.y2 = rect.y1 + 20;
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建按钮用于触发一个不包含标题的窗口 */
|
||||
button = rtgui_button_create("NoTitle Win");
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton);
|
||||
/* 设置onbutton为demo_ntitlewin_onbutton函数 */
|
||||
rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton);
|
||||
|
||||
return view;
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ static void rtgui_mywidget_ondraw(struct rtgui_mywidget* me)
|
|||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
/* 计算中心原点 */
|
||||
x = (rect.x2 + rect.x1)/2; y = (rect.y2 + rect.y1)/2;
|
||||
x = (rect.x2 + rect.x1)/2;
|
||||
y = (rect.y2 + rect.y1)/2;
|
||||
|
||||
/* 绘制十字架 */
|
||||
rtgui_dc_set_color(dc, black);
|
||||
|
@ -53,11 +54,12 @@ static void rtgui_mywidget_onmouse(struct rtgui_mywidget* me, struct rtgui_event
|
|||
rtgui_widget_rect_to_device(RTGUI_WIDGET(me), &rect);
|
||||
|
||||
/* 计算中心原点 */
|
||||
x = (rect.x2 + rect.x1)/2; y = (rect.y2 + rect.y1)/2;
|
||||
x = (rect.x2 + rect.x1)/2;
|
||||
y = (rect.y2 + rect.y1)/2;
|
||||
|
||||
/* 比较鼠标坐标是否在圈内 */
|
||||
if ((mouse->x < x + 5 && mouse->x > x - 5) &&
|
||||
(mouse->y < y + 5 && mouse->y > y - 5))
|
||||
(mouse->y < y + 5 && mouse->y > y - 5))
|
||||
{
|
||||
/* 更改控件状态 */
|
||||
if (me->status & MYWIDGET_STATUS_ON) me->status = MYWIDGET_STATUS_OFF;
|
||||
|
@ -71,7 +73,7 @@ static void rtgui_mywidget_onmouse(struct rtgui_mywidget* me, struct rtgui_event
|
|||
/* mywidget控件的事件处理函数 */
|
||||
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
{
|
||||
/* 调用事件处理函数时,widget指针指向控件本身,所以先获得相应控件对象的指针 */
|
||||
/* 调用事件处理函数时,widget指针指向控件本身,所以先获得相应控件对象的指针 */
|
||||
struct rtgui_mywidget* me = RTGUI_MYWIDGET(widget);
|
||||
|
||||
switch (event->type)
|
||||
|
@ -86,7 +88,7 @@ rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui
|
|||
rtgui_mywidget_onmouse(RTGUI_MYWIDGET(me), (struct rtgui_event_mouse*) event);
|
||||
break;
|
||||
|
||||
/* 其他事件调用父类的事件处理函数 */
|
||||
/* 其他事件调用父类的事件处理函数 */
|
||||
default:
|
||||
return rtgui_widget_event_handler(widget, event);
|
||||
}
|
||||
|
@ -97,24 +99,24 @@ rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui
|
|||
/* 自定义控件的构造函数 */
|
||||
static void _rtgui_mywidget_constructor(rtgui_mywidget_t *mywidget)
|
||||
{
|
||||
/* 默认这个控件接收聚焦 */
|
||||
/* 默认这个控件接收聚焦 */
|
||||
RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
/* 初始化控件并设置事件处理函数 */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(mywidget), rtgui_mywidget_event_handler);
|
||||
|
||||
/* 初始状态时OFF */
|
||||
/* 初始状态时OFF */
|
||||
mywidget->status = MYWIDGET_STATUS_OFF;
|
||||
}
|
||||
|
||||
/* 获得控件的类型 */
|
||||
rtgui_type_t *rtgui_mywidget_type_get(void)
|
||||
{
|
||||
/* 控件的类型是一个静态变量,默认是NULL */
|
||||
/* 控件的类型是一个静态变量,默认是NULL */
|
||||
static rtgui_type_t *mywidget_type = RT_NULL;
|
||||
|
||||
if (!mywidget_type)
|
||||
{
|
||||
/* 当控件类型不存在时,创建它,并指定这种类型数据的大小及指定相应的构造函数和析构函数 */
|
||||
/* 当控件类型不存在时,创建它,并指定这种类型数据的大小及指定相应的构造函数和析构函数 */
|
||||
mywidget_type = rtgui_type_create("mywidget", RTGUI_WIDGET_TYPE,
|
||||
sizeof(rtgui_mywidget_t),
|
||||
RTGUI_CONSTRUCTOR(_rtgui_mywidget_constructor), RT_NULL);
|
||||
|
@ -126,14 +128,14 @@ rtgui_type_t *rtgui_mywidget_type_get(void)
|
|||
/* 创建一个自定义控件 */
|
||||
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);
|
||||
if (me != RT_NULL)
|
||||
{
|
||||
/* 让rtgui_widget创建出一个指定类型:RTGUI_MYWIDGET_TYPE类型的控件 */
|
||||
me = (struct rtgui_mywidget*) rtgui_widget_create (RTGUI_MYWIDGET_TYPE);
|
||||
if (me != RT_NULL)
|
||||
{
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(me), r);
|
||||
}
|
||||
}
|
||||
|
||||
return me;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
/* 个性化控件类定义 */
|
||||
struct rtgui_mywidget
|
||||
{
|
||||
/* 这个控件是继承自rtgui_widget控件 */
|
||||
/* 这个控件是继承自rtgui_widget控件 */
|
||||
struct rtgui_widget parent;
|
||||
|
||||
/* 状态:ON、OFF */
|
||||
|
|
Loading…
Reference in New Issue