rtgui_view_t* demo_view_window(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t* view; rtgui_button_t *button; /* 创建一个演示用的视图 */ 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; /* 创建按钮用于显示正常窗口 */ button = rtgui_button_create("Normal Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置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; /* 创建按钮用于显示一个自动关闭的窗口 */ button = rtgui_button_create("Auto Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置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; /* 创建按钮用于触发一个模式窗口 */ button = rtgui_button_create("Modal Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置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; /* 创建按钮用于触发一个不包含标题的窗口 */ button = rtgui_button_create("NoTitle Win"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button)); /* 设置onbutton为demo_ntitlewin_onbutton函数 */ rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton); return view; }
static void app_lcd(void *parameter) { /* create application */ struct rtgui_app *app; struct rtgui_rect rect1 = {0, 0, 240, 320}; struct rtgui_button* btn; struct rtgui_label *lb; app = rtgui_app_create("lcd_app"); if (!app) { rt_kprintf("Create application \"lcd_app\" failed!\n"); return; } /* create main window */ win_main = rtgui_win_create(RT_NULL, "main", &rect1, RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE); if (win_main == RT_NULL) { rt_kprintf("Create window \"main\" failed!\n"); rtgui_app_destroy(app); return; } RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win_main)) = green; rect1.x1 = rect1.y1 = 50; rect1.x2 -= 50; rect1.y2 -= 50; lb = rtgui_label_create("I am a transparent label!!!!!!!!!"); rtgui_widget_set_rect(RTGUI_WIDGET(lb), &rect1); RTGUI_WIDGET_FLAG(RTGUI_WIDGET(lb)) |= RTGUI_WIDGET_FLAG_TRANSPARENT; rect1.x1 += 20; rect1.y1 += 20; notebook = rtgui_notebook_create(&rect1, 0); /* create lable in main container */ btn = rtgui_button_create("Here I am."); rtgui_notebook_add(notebook, "btn A", RTGUI_WIDGET(btn)); rtgui_button_set_onbutton(btn, remove_myself); btn = rtgui_button_create("There I am."); rtgui_notebook_add(notebook, "btn B", RTGUI_WIDGET(btn)); rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(lb)); rtgui_container_add_child(RTGUI_CONTAINER(win_main), RTGUI_WIDGET(notebook)); rtgui_win_show(win_main, RT_FALSE); rtgui_app_run(app); rtgui_app_destroy(app); }
/* 触发模态窗口显示 */ static void demo_modalwin_onbutton(struct rtgui_object *object, rtgui_event_t *event) { rtgui_win_t *win; rtgui_label_t *label; rtgui_rect_t rect = {0, 0, 150, 80}; rtgui_rect_moveto(&rect, delta_x, delta_y); delta_x += 20; delta_y += 20; /* 创建一个窗口 */ win = rtgui_win_create(main_win, get_win_title(), &rect, RTGUI_WIN_STYLE_DEFAULT); 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); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label)); /* 模态显示窗口 */ rtgui_win_show(win, RT_TRUE); /* 删除非自动删除窗口 */ rtgui_win_destroy(win); }
/* 触发自动窗口显示 */ static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *event) { struct rtgui_rect rect = {50, 50, 200, 200}; /* don't create the window twice */ if (autowin) return; autowin = rtgui_win_create(main_win, "Information", &rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); if (autowin == RT_NULL) return; cnt = 5; rt_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(autowin), RTGUI_WIDGET(label)); /* 设置关闭窗口时的动作 */ rtgui_win_set_onclose(autowin, auto_window_close); rtgui_win_show(autowin, RT_FALSE); /* 创建一个定时器 */ timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL); rtgui_timer_start(timer); }
static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent) { rtgui_win_t *menu; rtgui_listbox_t *listbox; rtgui_rect_t screen, rect = {0, 0, 140, 85}; rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen); rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)), "Folder Menu", &rect, RTGUI_WIN_STYLE_DEFAULT); if (menu != RT_NULL) { /* set user data on menu window */ menu->user_data = (rt_uint32_t)parent; rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate); listbox = rtgui_listbox_create(items, sizeof(items)/sizeof(items[0]), &rect); rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item); rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox)); rtgui_win_show(menu, RT_FALSE); rtgui_widget_focus(RTGUI_WIDGET(listbox)); rtgui_listbox_set_current_item(listbox, 0); } }
/* 触发自动窗口显示 */ 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; rt_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_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; /* 创建一个窗口 */ 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; /* 添加一个文本标签 */ label = rtgui_label_create("这是一个普通窗口"); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label)); /* 非模态显示窗口 */ rtgui_win_show(win, RT_FALSE); }
void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box) { if (win == RT_NULL || box == RT_NULL) return; rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box)); rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent)); }
void _draw_default(struct rtgui_object *object, rtgui_event_t* event) { struct rtgui_widget *widget = RTGUI_WIDGET(object); struct rtgui_dc* dc; rtgui_rect_t rect; /* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container先绘图 */ rtgui_container_event_handler(object, event); /* 获得控件所属的DC */ dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */ return; /* 获得demo container允许绘图的区域 */ demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect); /* 擦除所有 */ RTGUI_WIDGET_BACKGROUND(widget) = default_background; rtgui_dc_fill_rect(dc, &rect); /* 显示提示 */ rtgui_dc_draw_text(dc, "按任意键开始/停止测试...", &rect); /* 绘图完成 */ rtgui_dc_end_drawing(dc); }
void _onidle(struct rtgui_object *object, rtgui_event_t *event) { rtgui_color_t color; rtgui_rect_t rect, draw_rect; struct rtgui_dc *dc; /* 获得控件所属的DC */ // dc = rtgui_dc_hw_create(RTGUI_WIDGET(container)); dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(container)); if (dc == RT_NULL) return; demo_view_get_logic_rect(RTGUI_CONTAINER(container), &rect); draw_rect.x1 = RAND(rect.x1, rect.x2); draw_rect.y1 = RAND(rect.y1, rect.y2); draw_rect.x2 = RAND(draw_rect.x1, rect.x2); draw_rect.y2 = RAND(draw_rect.y1, rect.y2); color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255); RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container)) = color; rtgui_dc_fill_rect(dc, &draw_rect); /* 绘图完成 */ rtgui_dc_end_drawing(dc); }
struct rtgui_object* rtgui_notebook_get_object(struct rtgui_notebook *notebook, rt_uint32_t id) { int i; for (i = 0; i < notebook->count; i++) { struct rtgui_object *o = RTGUI_OBJECT(notebook->childs[i].widget); if (o->id == id) return o; if (RTGUI_IS_CONTAINER(o)) { struct rtgui_object *obj; obj = rtgui_container_get_object(RTGUI_CONTAINER(o), id); if (obj) return obj; } else if (RTGUI_IS_NOTEBOOK(o)) { struct rtgui_object *obj; obj = rtgui_notebook_get_object(RTGUI_NOTEBOOK(o), id); if (obj) return obj; } } return RT_NULL; }
int main(int argc, char** argv) { struct rtgui_app* application; struct rtgui_win* win; struct rtgui_button *button; application = rtgui_app_create("button"); if (application != RT_NULL) { rtgui_rect_t rect; win = rtgui_mainwin_create(RT_NULL, "button", RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); rtgui_widget_get_extent(RTGUI_WIDGET(win), &rect); /* create lable in app window */ button = rtgui_button_create("close"); rtgui_button_set_onbutton(button, _on_close); rect.x2 -= 5; rect.y2 -= 5; rect.x1 = rect.x2 - 80; rect.y1 = rect.y2 - 25; rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button)); rtgui_win_show(win, RT_TRUE); rtgui_app_destroy(application); } return 0; }
rtgui_terminal_t* rtgui_terminal_create(pvoid parent,const char* text, int left,int top,int w,int h) { rtgui_container_t *container; rtgui_terminal_t* tma; RT_ASSERT(parent != RT_NULL); container = RTGUI_CONTAINER(parent); tma = rtgui_widget_create(RTGUI_TERMINAL_TYPE); if(tma != RT_NULL) { rtgui_rect_t rect; rtgui_widget_get_rect(container, &rect); rtgui_widget_rect_to_device(container,&rect); rect.x1 += left; rect.y1 += top; rect.x2 = rect.x1+w; rect.y2 = rect.y1+h; rtgui_widget_set_rect(tma,&rect); rtgui_container_add_child(container, tma); /* calculate line width and line page count */ rtgui_terminal_calc_width(tma); /* set text */ rtgui_terminal_calc_line(tma, text); } return tma; }
struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* parent_menu, const struct rtgui_menu_item* items, rt_uint16_t count) { rtgui_rect_t rect = {0, 0, 100, 100}; struct rtgui_menu* menu; menu = (struct rtgui_menu*) rtgui_widget_create ( RTGUI_MENU_TYPE ); if (menu != RT_NULL) { rtgui_win_set_title(RTGUI_WIN(menu), title); menu->parent_menu = parent_menu; menu->items = items; menu->items_count = count; rtgui_widget_set_rect(RTGUI_WIDGET(menu), &rect); rtgui_rect_inflate(&rect, -1); /* create menu item list */ menu->items_list = rtgui_listctrl_create((rt_uint32_t)items, count, &rect, _rtgui_menu_item_ondraw); RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(menu->items_list)) = rtgui_theme_default_bc(); rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(menu->items_list)); rtgui_listctrl_set_onitem(menu->items_list, _rtgui_menu_onitem); } return menu; }
struct rtgui_panel* apps_list_create(struct rtgui_panel* panel) { struct rtgui_rect rect; RT_ASSERT(panel != RT_NULL); if (app_default_icon == RT_NULL) { app_default_icon = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)exec_xpm, sizeof(exec_xpm), RT_FALSE); } if (app_close == RT_NULL) { app_close = rtgui_image_create_from_mem("xpm", (const rt_uint8_t *)close_xpm, sizeof(close_xpm), RT_FALSE); } rtgui_widget_get_extent(RTGUI_WIDGET(panel), &rect); /* create application list */ rtgui_rect_inflate(&rect, -15); app_list = rtgui_listctrl_create(RTGUI_CONTAINER(panel), (rt_uint32_t)app_items, app_count, 15,15,RC_W(rect)-30,RC_H(rect)-30, _app_info_draw); rtgui_listctrl_set_itemheight(app_list, app_default_icon->h + 2); rtgui_listctrl_set_onitem(app_list, _handle_app_activate); rtgui_object_set_event_handler(RTGUI_OBJECT(app_list), apps_listctrl_event_handler); //rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(app_list)); return RTGUI_PANEL(panel); }
/* 创建用于演示notebook控件的视图 */ rtgui_view_t* demo_view_notebook(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t* view; rtgui_notebook_t* notebook; rtgui_listbox_t* box; /* 先创建一个演示用的视图 */ view = demo_view(workbench, "Notebook View"); /* 获得视图的位置信息 */ demo_view_get_rect(view, &rect); notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_BOTTOM); /* view是一个container控件,调用add_child方法添加这个notebook控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(notebook)); box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &rect); rtgui_notebook_add(notebook, "Tab 1", RTGUI_WIDGET(box)); box = rtgui_listbox_create(items2, sizeof(items2)/sizeof(struct rtgui_listbox_item), &rect); rtgui_notebook_add(notebook, "Tab 2", RTGUI_WIDGET(box)); return view; }
static void listitem_action(void* parameter) #endif { char label_text[32]; rtgui_win_t *win; rtgui_label_t *label; rtgui_rect_t rect = {0, 0, 150, 80}; int no = (int)parameter; rtgui_rect_moveto(&rect, 20, 50); /* 显示消息窗口 */ 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; /* 添加相应的标签 */ rt_sprintf(label_text, "动作 %d", no); label = rtgui_label_create(label_text); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label)); /* 非模态显示窗口 */ rtgui_win_show(win, RT_FALSE); }
/* 创建用于演示列表视图的视图 */ rtgui_view_t* demo_listview_icon_view(rtgui_workbench_t* workbench) { rtgui_rect_t rect; rtgui_view_t *view; rtgui_button_t* open_btn; view = demo_view(workbench, "图标视图演示"); if (item_icon == RT_NULL) item_icon = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE); if (exit_icon == RT_NULL) exit_icon = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)exit_xpm, sizeof(exit_xpm), RT_TRUE); /* 添加动作按钮 */ 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("打开图标列表"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn)); rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect); rtgui_button_set_onbutton(open_btn, open_btn_onbutton); return view; }
static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win) { struct rtgui_dc* dc; struct rtgui_rect rect; struct rtgui_event_paint event; /* begin drawing */ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win)); if (dc == RT_NULL) return RT_FALSE; /* get window rect */ rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect); /* fill area */ rtgui_dc_fill_rect(dc, &rect); /* paint each widget */ RTGUI_EVENT_PAINT_INIT(&event); event.wid = RT_NULL; rtgui_container_dispatch_event(RTGUI_CONTAINER(win), (rtgui_event_t*)&event); rtgui_dc_end_drawing(dc); return RT_FALSE; }
void rtgui_workbench_remove_view(rtgui_workbench_t* workbench, rtgui_view_t* view) { if (view == workbench->current_view) rtgui_workbench_hide_view(workbench, view); rtgui_container_remove_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view)); }
rt_bool_t show_modal_info(struct rtgui_widget *object, struct rtgui_event *event) { rtgui_label_t *label; struct rtgui_win *win; rtgui_rect_t rect = {0, 60, 150, 100}; win = rtgui_win_create(main_win, "Info", &rect, RTGUI_WIN_STYLE_DEFAULT); rect.x1 += 20; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; label = rtgui_label_create("modal mode info"); rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label)); rtgui_win_show(win, RT_TRUE); rtgui_win_destroy(win); return RT_TRUE; }
static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent) { struct rtgui_win *menu; rtgui_rect_t screen, rect = {0, 0, 140, 85}; rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen); rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)), "Folder Menu", &rect, RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); if (menu != RT_NULL) { rtgui_listbox_t *listbox; /* Pass the pointer to filelist_view via user_data. */ menu->user_data = (rt_uint32_t)parent; rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate); listbox = rtgui_listbox_create(_folder_actions, sizeof(_folder_actions) / sizeof(_folder_actions[0]), &rect); /* Set the item index *before* setup the callback. `set_current_item` * will invoke the "onitem". So just keep it clean when setting the * current item. */ rtgui_listbox_set_current_item(listbox, 0); rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item); rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox)); rtgui_win_show(menu, RT_TRUE); } }
int creat_software_ver_not_match_win(struct rtgui_widget* widget) { rtgui_rect_t rect = {60, 45, 260, 160}; rtgui_label_t *label1; rtgui_label_t *label2; rtgui_toplevel_t *parent; if (RT_NULL != software_version_not_match_win) return FAIL; parent = RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(widget)); software_version_not_match_win = rtgui_win_create(parent, "致命错误", &rect, RTGUI_WIN_STYLE_MODAL); rtgui_widget_get_extent(RTGUI_WIDGET(software_version_not_match_win),&rect); rect.x1 += 20; rect.x2 -= 20; rect.y1 += 20; rect.y2 = rect.y1 + 30; label1 = rtgui_label_create("接收端与lcd软件版本"); if (NULL != label1) { rtgui_widget_set_rect(RTGUI_WIDGET(label1), &rect); rtgui_container_add_child(RTGUI_CONTAINER(software_version_not_match_win), RTGUI_WIDGET(label1)); } rtgui_widget_get_extent(RTGUI_WIDGET(software_version_not_match_win),&rect); rect.x1 += 70; rect.x2 -= 30; rect.y1 += 50; rect.y2 = rect.y1 + 30; label2 = rtgui_label_create("不匹配!"); if (NULL != label2) { rtgui_widget_set_rect(RTGUI_WIDGET(label2), &rect); rtgui_container_add_child(RTGUI_CONTAINER(software_version_not_match_win), RTGUI_WIDGET(label2)); } send_cmd_to_rxe(1, SWITCH2PT); rtgui_win_show(software_version_not_match_win, RT_TRUE); rtgui_win_destroy(software_version_not_match_win); software_version_not_match_win = RT_NULL; return SUCC; }
rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench) { rtgui_view_t *view; rtgui_rect_t rect; rtgui_label_t *label; /* create a demo view */ view = demo_view(workbench, "ProgressBar View"); /* get demo view rect */ demo_view_get_rect(view, &rect); label = rtgui_label_create("邦峠序業訳:"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.y1 += 20; rect.y2 = rect.y1 + 18; hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(hbar)); /* get demo view rect */ demo_view_get_rect(view, &rect); label = rtgui_label_create("換岷序業訳:"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 45; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.x1 += 110; rect.x2 = rect.x1 + 20; rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150; vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(vbar)); bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC, progressbar_timeout, RT_NULL); rtgui_timer_start(bar_timer); return view; }
static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struct rtgui_event_mouse* event) { struct rtgui_rect rect; /* get widget rect */ rect = RTGUI_WIDGET(box)->extent; /* move to the pull down button */ rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH; if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) { /* handle mouse button on pull down button */ if (event->button & RTGUI_MOUSE_BUTTON_LEFT && event->button & RTGUI_MOUSE_BUTTON_DOWN) { box->pd_pressed = RT_TRUE; rtgui_widget_update(RTGUI_WIDGET(box)); } else if (event->button & RTGUI_MOUSE_BUTTON_LEFT && event->button & RTGUI_MOUSE_BUTTON_UP) { box->pd_pressed = RT_FALSE; rtgui_widget_update(RTGUI_WIDGET(box)); /* pop pull down window */ if (box->pd_win == RT_NULL) { rtgui_listbox_t *list; /* create pull down window */ rect = RTGUI_WIDGET(box)->extent; rect.y1 = rect.y2; rect.y2 = rect.y1 + 5 * (2 + rtgui_theme_get_selected_height()); box->pd_win = rtgui_win_create(RT_NULL, "combo", &rect, RTGUI_WIN_STYLE_NO_TITLE); rtgui_win_set_ondeactivate(RTGUI_WIN(box->pd_win), rtgui_combobox_pulldown_hide); /* set user data to parent combobox */ box->pd_win->user_data = (rt_uint32_t)box; /* create list box */ rtgui_rect_inflate(&rect, -1); list = rtgui_listbox_create(box->items, box->items_count, &rect); rtgui_container_add_child(RTGUI_CONTAINER(box->pd_win), RTGUI_WIDGET(list)); rtgui_widget_focus(RTGUI_WIDGET(list)); rtgui_listbox_set_onitem(list, rtgui_combobox_pdwin_onitem); rtgui_win_set_ondeactivate(box->pd_win, rtgui_combobox_pdwin_ondeactive); } /* show combo box pull down window */ rtgui_win_show(RTGUI_WIN(box->pd_win), RT_FALSE); } return RT_TRUE; } return RT_FALSE; }
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view) { rtgui_container_add_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view)); /* hide view in default */ RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view)); /* reset view extent */ rtgui_widget_set_rect(RTGUI_WIDGET(view), &(RTGUI_WIDGET(workbench)->extent)); }
rtgui_view_t *demo_view_slider(rtgui_workbench_t* workbench) { rtgui_view_t *view; rtgui_rect_t rect; rtgui_label_t *label; rtgui_slider_t *slider; /* create a demo view */ view = demo_view(workbench, "Slider View"); /* get demo view rect */ demo_view_get_rect(view, &rect); label = rtgui_label_create("horizontal slider:"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.y1 += 20; rect.y2 = rect.y1 + 18; slider = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider)); rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect); /* get demo view rect */ demo_view_get_rect(view, &rect); label = rtgui_label_create("vertical slider:"); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 50; rect.y2 = rect.y1 + 18; rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.x1 += 110; rect.x2 = rect.x1 + 20; rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150; slider = rtgui_slider_create(0, 100, RTGUI_VERTICAL); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider)); rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect); return view; }
/* 触发无标题窗口显示 */ 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; /* 创建一个窗口,风格为无标题及无边框 */ 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; /* 创建一个文本标签 */ 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; 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; rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL); 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)); rtgui_button_set_onbutton(button, window_demo_close); /* 非模态显示窗口 */ rtgui_win_show(win, RT_FALSE); }
/* 打开列表视图用的按钮触发函数 */ static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event) { rtgui_rect_t rect; /* 获得顶层的application */ application = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget)); rtgui_widget_get_rect(RTGUI_WIDGET(application), &rect); /* 创建一个列表视图, 项指定为items */ _view = rtgui_list_view_create(items, sizeof(items) / sizeof(struct rtgui_list_item), &rect, RTGUI_LIST_VIEW_LIST); rtgui_application_add_container(application, RTGUI_CONTAINER(_view)); /* 模式显示视图 */ rtgui_container_show(RTGUI_CONTAINER(_view), RT_TRUE); rtgui_container_destroy(RTGUI_CONTAINER(_view)); _view = RT_NULL; }
/* 创建用于演示文件列表视图的视图 */ 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; /* 默认采用12字体的显示 */ 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); 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); RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font; rtgui_button_set_onbutton(open_btn, open_btn_onbutton); return view; }