From e48f777a6d63d6d8b0700d4c6d51c0f9551bd336 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Sun, 14 Mar 2010 06:36:46 +0000 Subject: [PATCH] add Chinese Comments git-svn-id: https://rt-thread.googlecode.com/svn/trunk@481 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- examples/gui/demo_fnview.c | 36 +++--- examples/gui/demo_listview.c | 17 ++- examples/gui/demo_view.c | 53 +++++---- examples/gui/demo_view_button.c | 32 ++++-- examples/gui/demo_view_checkbox.c | 32 ++++-- examples/gui/demo_view_dc.c | 56 ++++++--- examples/gui/demo_view_label.c | 37 +++--- examples/gui/demo_view_mywidget.c | 16 ++- examples/gui/demo_view_radiobox.c | 76 ++++++------ examples/gui/demo_view_textbox.c | 65 ++++++----- examples/gui/demo_view_window.c | 185 +++++++++++++++++------------- examples/gui/mywidget.c | 32 +++--- examples/gui/mywidget.h | 2 +- 13 files changed, 374 insertions(+), 265 deletions(-) diff --git a/examples/gui/demo_fnview.c b/examples/gui/demo_fnview.c index 68c4269137..c1451d4ba3 100644 --- a/examples/gui/demo_fnview.c +++ b/examples/gui/demo_fnview.c @@ -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; } diff --git a/examples/gui/demo_listview.c b/examples/gui/demo_listview.c index fbbd367547..fb573b7daf 100644 --- a/examples/gui/demo_listview.c +++ b/examples/gui/demo_listview.c @@ -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); diff --git a/examples/gui/demo_view.c b/examples/gui/demo_view.c index c64225057b..0be5b8264c 100644 --- a/examples/gui/demo_view.c +++ b/examples/gui/demo_view.c @@ -34,32 +34,34 @@ void demo_view_prev(struct rtgui_widget* widget, rtgui_event_t *event) /* 鍒涘缓涓涓紨绀鸿鍥撅紝闇鎻愪緵鐖秝orkbench鍜屾紨绀虹敤鐨勬爣棰 */ 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涓椂锛寃orkbench浼氳嚜鍔ㄨ皟鏁磋鍥剧殑澶у皬) */ 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鍔ㄤ綔鍒癲emo_view_next鍑芥暟 */ + next_btn = rtgui_button_create("Next"); + /* 璁剧疆onbutton鍔ㄤ綔鍒癲emo_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)); diff --git a/examples/gui/demo_view_button.c b/examples/gui/demo_view_button.c index cbc486194b..d54a7bc065 100644 --- a/examples/gui/demo_view_button.c +++ b/examples/gui/demo_view_button.c @@ -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; /* 鍒涘缓涓涓猙utton鎺т欢 */ button = rtgui_button_create("Red"); /* 璁剧疆label鎺т欢鐨勫墠鏅壊涓虹孩鑹 */ @@ -31,10 +33,12 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猙utton鎺т欢 */ button = rtgui_button_create("Blue"); /* 璁剧疆label鎺т欢鐨勫墠鏅壊涓鸿摑鑹 */ @@ -44,10 +48,12 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猙utton鎺т欢 */ button = rtgui_button_create("12 font"); /* 璁剧疆瀛椾綋涓12鐐归樀鐨刟sc瀛椾綋 */ @@ -58,10 +64,12 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猙utton鎺т欢 */ button = rtgui_button_create("16 font"); /* 璁剧疆瀛椾綋涓16鐐归樀鐨刟sc瀛椾綋 */ diff --git a/examples/gui/demo_view_checkbox.c b/examples/gui/demo_view_checkbox.c index a122168301..f5e4ddc85e 100644 --- a/examples/gui/demo_view_checkbox.c +++ b/examples/gui/demo_view_checkbox.c @@ -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; /* 鍒涘缓涓涓猚heckbox鎺т欢 */ checkbox = rtgui_checkbox_create("Red",RT_TRUE); /* 璁剧疆鍓嶆櫙鑹蹭负绾㈣壊 */ @@ -31,10 +33,12 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猚heckbox鎺т欢 */ checkbox = rtgui_checkbox_create("Blue",RT_TRUE); /* 璁剧疆鍓嶆櫙鑹蹭负钃濊壊 */ @@ -44,10 +48,12 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猚heckbox鎺т欢 */ checkbox = rtgui_checkbox_create("12 font",RT_TRUE); /* 璁剧疆瀛椾綋涓12鐐归樀 */ @@ -58,10 +64,12 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猚heckbox鎺т欢 */ checkbox = rtgui_checkbox_create("16 font",RT_TRUE); /* 璁剧疆瀛椾綋涓16鐐归樀 */ diff --git a/examples/gui/demo_view_dc.c b/examples/gui/demo_view_dc.c index b6c31d54ea..bb12fb7fdc 100644 --- a/examples/gui/demo_view_dc.c +++ b/examples/gui/demo_view_dc.c @@ -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); diff --git a/examples/gui/demo_view_label.c b/examples/gui/demo_view_label.c index e2dd49fdf9..1c6b560082 100644 --- a/examples/gui/demo_view_label.c +++ b/examples/gui/demo_view_label.c @@ -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; /* 鍒涘缓涓涓猯abel鎺т欢 */ label = rtgui_label_create("Red Left"); /* 璁剧疆label鎺т欢涓婄殑鏂囨湰瀵归綈鏂瑰紡涓猴細宸﹀榻 */ @@ -32,10 +34,12 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猯abel鎺т欢 */ label = rtgui_label_create("Blue Right"); /* 璁剧疆label鎺т欢涓婄殑鏂囨湰瀵归綈鏂瑰紡涓猴細鍙冲榻 */ @@ -47,10 +51,12 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猯abel鎺т欢 */ label = rtgui_label_create("Green Center"); /* 璁剧疆label鎺т欢鐨勫墠鏅壊涓虹豢鑹 */ @@ -62,10 +68,12 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猯abel鎺т欢 */ label = rtgui_label_create("12 font"); /* 璁剧疆瀛椾綋涓12鐐归樀鐨刟sc瀛椾綋 */ @@ -76,10 +84,11 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench) /* view鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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; /* 鍒涘缓涓涓猯abel鎺т欢 */ label = rtgui_label_create("16 font"); /* 璁剧疆瀛椾綋涓16鐐归樀鐨刟sc瀛椾綋 */ diff --git a/examples/gui/demo_view_mywidget.c b/examples/gui/demo_view_mywidget.c index 4b99fe92a7..1c0e6de693 100644 --- a/examples/gui/demo_view_mywidget.c +++ b/examples/gui/demo_view_mywidget.c @@ -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鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_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鏄竴涓猚ontainer鎺т欢锛岃皟鐢╝dd_child鏂规硶娣诲姞杩欎釜鑷帶浠 */ diff --git a/examples/gui/demo_view_radiobox.c b/examples/gui/demo_view_radiobox.c index 6ae2b82677..ba204c8d7f 100644 --- a/examples/gui/demo_view_radiobox.c +++ b/examples/gui/demo_view_radiobox.c @@ -9,57 +9,61 @@ /* 鐢ㄤ簬鏄剧ず鍨傜洿鏂瑰悜鐨剅adio鏂囨湰椤规暟缁 */ static char* radio_item_v[5] = -{ - "one", - "two", - "three", - "item 1", - "item 2" -}; + { + "one", + "two", + "three", + "item 1", + "item 2" + }; /* 鐢ㄤ簬鏄剧ず姘村钩鏂瑰悜鐨剅adio鏂囨湰椤规暟缁 */ 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; + /* 鑾峰緱瑙嗗浘鐨勪綅缃俊鎭 */ + demo_view_get_rect(view, &rect); + rect.x1 += 5; + rect.x2 -= 5; + rect.y1 += 5; + rect.y2 = rect.y1 + 5 * 25; - /* 鍒涘缓涓涓瀭鐩存柟鍚戞樉绀虹殑radiobox鎺т欢锛屾枃鏈」鏄痳adio_item_v鏁扮粍锛屽叡5涓」 */ - radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5); - /* 璁剧疆褰撳墠閫夋嫨鐨勬暟缁勬槸绗0椤 */ + /* 鍒涘缓涓涓瀭鐩存柟鍚戞樉绀虹殑radiobox鎺т欢锛屾枃鏈」鏄痳adio_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); - /* 鑾峰緱瑙嗗浘鐨勪綅缃俊鎭 */ + /* 鑾峰緱瑙嗗浘鐨勪綅缃俊鎭 */ 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 + 5 * 25; + rect.y2 = rect.y1 + 60; - /* 鍒涘缓涓涓按骞虫柟鍚戞樉绀虹殑radiobox鎺т欢锛屾枃鏈」鏄痳adio_item_h鏁扮粍锛屽叡3涓」 */ - radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3); - /* 璁剧疆褰撳墠閫夋嫨鐨勬暟缁勬槸绗0椤 */ + /* 鍒涘缓涓涓按骞虫柟鍚戞樉绀虹殑radiobox鎺т欢锛屾枃鏈」鏄痳adio_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); + /* 娣诲姞radiobox鎺т欢鍒拌鍥句腑 */ + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox)); + /* 璁剧疆radiobox鎺т欢鐨勪綅缃俊鎭 */ + rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect); - return view; + return view; } diff --git a/examples/gui/demo_view_textbox.c b/examples/gui/demo_view_textbox.c index 8f16351a42..e4b8646754 100644 --- a/examples/gui/demo_view_textbox.c +++ b/examples/gui/demo_view_textbox.c @@ -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; diff --git a/examples/gui/demo_view_window.c b/examples/gui/demo_view_window.c index 5d336b552e..c3eedf843d 100644 --- a/examples/gui/demo_view_window.c +++ b/examples/gui/demo_view_window.c @@ -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; } diff --git a/examples/gui/mywidget.c b/examples/gui/mywidget.c index a9668a7873..1c65240bc0 100644 --- a/examples/gui/mywidget.c +++ b/examples/gui/mywidget.c @@ -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) { - /* 鎺т欢鐨勭被鍨嬫槸涓涓潤鎬佸彉閲忥紝榛樿鏄疦ULL */ + /* 鎺т欢鐨勭被鍨嬫槸涓涓潤鎬佸彉閲忥紝榛樿鏄疦ULL */ 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; - /* 璁﹔tgui_widget鍒涘缓鍑轰竴涓寚瀹氱被鍨嬶細RTGUI_MYWIDGET_TYPE绫诲瀷鐨勬帶浠 */ - me = (struct rtgui_mywidget*) rtgui_widget_create (RTGUI_MYWIDGET_TYPE); - if (me != RT_NULL) - { + /* 璁﹔tgui_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; } diff --git a/examples/gui/mywidget.h b/examples/gui/mywidget.h index f1273682b6..2bb9035d12 100644 --- a/examples/gui/mywidget.h +++ b/examples/gui/mywidget.h @@ -28,7 +28,7 @@ /* 涓у寲鎺т欢绫诲畾涔 */ struct rtgui_mywidget { - /* 杩欎釜鎺т欢鏄户鎵胯嚜rtgui_widget鎺т欢 */ + /* 杩欎釜鎺т欢鏄户鎵胯嚜rtgui_widget鎺т欢 */ struct rtgui_widget parent; /* 鐘舵侊細ON銆丱FF */ -- GitLab