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; }
void rtgui_combo_add_string(rtgui_combo_t* cbo,const char* string) { if(cbo->lbox != RT_NULL) { rtgui_listbox_item_t item; rtgui_rect_t rect; rt_uint32_t h,count; item.name = (char*)string; item.image = RT_NULL; rtgui_listbox_add_item(cbo->lbox, &item, 1); rtgui_widget_get_rect(cbo->lbox, &rect); count = rtgui_listbox_get_count(cbo->lbox); h = RTGUI_WIDGET_BORDER_SIZE(cbo->lbox)*2+(RTGUI_SEL_H + 2)*count; if(h>RC_H(rect)) { if(cbo->lbox->item_per_page<5)/* change when less than five */ { rect.y2 = rect.y1+h; rtgui_widget_rect_to_device(cbo->lbox,&rect); rtgui_widget_set_rect(cbo->lbox,&rect);/* update listbox extent */ cbo->lbox->item_per_page = RC_H(rect) / (RTGUI_SEL_H+2); if(cbo->lbox->scroll != RT_NULL)/* update scrollbar extent */ { rtgui_widget_get_rect(cbo->lbox->scroll, &rect); rect.y2 = rect.y1+h-RTGUI_WIDGET_BORDER_SIZE(cbo->lbox)*2; rtgui_widget_rect_to_device(cbo->lbox->scroll,&rect); rtgui_widget_set_rect(cbo->lbox->scroll,&rect); if(cbo->lbox->item_count > cbo->lbox->item_per_page) { RTGUI_WIDGET_SHOW(cbo->lbox->scroll); rtgui_scrollbar_set_line_step(cbo->lbox->scroll, 1); rtgui_scrollbar_set_page_step(cbo->lbox->scroll, cbo->lbox->item_per_page); rtgui_scrollbar_set_range(cbo->lbox->scroll, cbo->lbox->item_count); } else { RTGUI_WIDGET_HIDE(cbo->lbox->scroll); } rtgui_widget_update_clip(cbo->lbox); } } } } }
rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint8_t style) { struct rtgui_win* win; /* allocate win memory */ win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE); if (win != RT_NULL) { /* set parent toplevel */ win->parent_toplevel = parent_toplevel; /* set title, rect and style */ if (title != RT_NULL) win->title = rt_strdup(title); else win->title = RT_NULL; rtgui_widget_set_rect(RTGUI_WIDGET(win), rect); win->style = style; if (_rtgui_win_create_in_server(win) == RT_FALSE) { rtgui_widget_destroy(RTGUI_WIDGET(win)); return RT_NULL; } } return 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); }
/* * head_name[] -- 最后一个元素必须是NULL * rows -- 包含表头在内 */ rtgui_form_t *rtgui_form_create(const char *head_name[], int rows, int cols, rtgui_rect_t *rect) { int i, len; struct rtgui_form *form; if (NULL==head_name || NULL==rect) return NULL; form = (struct rtgui_form *)rtgui_widget_create(RTGUI_FORM_TYPE); if (NULL == form) return NULL; i = 0; while (NULL != head_name[i]) ++i; if (i != cols) { form_debug(("%s(), head items (%d) not same as cols(%d)!\n", __FUNCTION__, i, cols)); goto err_entry; } form_debug(("%s(), line:%d: rows:%d, cols:%d!\n", __FUNCTION__, __LINE__, rows, cols)); len = 0; for (i=0; i<cols; ++i) { len += rt_strlen(head_name[i]); } len += cols * GAG_BETWEEN_COL; form->fbody = rt_calloc(len*(rows-1), 1); /* 不包含表格头部占用的存储空间 */ if (NULL == form->fbody) { form_debug(("fun:%s(), line:%d:%d malloc fail!\n", __FUNCTION__, __LINE__, len*(rows-1))); goto err_entry; } form->head_name = rt_calloc(cols, sizeof(head_name[0])); if (NULL == form->head_name) { form_debug(("fun:%s(), line:%d:%d malloc fail!\n", __FUNCTION__, __LINE__, cols * sizeof(head_name[0]))); rt_free(form->fbody); goto err_entry; } form_debug(("%s(), line:%d: fbody-len:%d, head-name-len:%d!\n", __FUNCTION__, __LINE__, len*(rows-1), cols * sizeof(head_name[0]))); for (i=0; i<cols; ++i) { form->head_name[i] = head_name[i]; } form->head_item_cnt = cols; form->row_cnt_of_fbody = rows - 1; form->bytes_of_row = len; rtgui_widget_set_rect(RTGUI_WIDGET(form), rect); return form; err_entry: rtgui_widget_destroy(RTGUI_WIDGET(form)); return NULL; }
rtgui_win_t* rtgui_win_create(struct rtgui_win* parent_window, const char* title, rtgui_rect_t *rect, rt_uint16_t style) { struct rtgui_win* win; /* allocate win memory */ win = RTGUI_WIN(rtgui_widget_create(RTGUI_WIN_TYPE)); if (win == RT_NULL) return RT_NULL; /* set parent toplevel */ win->parent_window = parent_window; /* set title, rect and style */ if (title != RT_NULL) win->title = rt_strdup(title); else win->title = RT_NULL; rtgui_widget_set_rect(RTGUI_WIDGET(win), rect); win->style = style; if (_rtgui_win_create_in_server(win) == RT_FALSE) { goto __on_err; } return win; __on_err: rtgui_widget_destroy(RTGUI_WIDGET(win)); return RT_NULL; }
/* 触发自动窗口显示 */ 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); }
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; }
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; }
struct rtgui_checkbox* rtgui_checkbox_create(const char* text, rt_bool_t checked) { struct rtgui_checkbox* box; box = (struct rtgui_checkbox*) rtgui_widget_create (RTGUI_CHECKBOX_TYPE); if (box != RT_NULL) { rtgui_rect_t rect; /* set default rect */ rtgui_font_get_metrics(rtgui_font_default(), text, &rect); rect.x2 += RTGUI_BORDER_DEFAULT_WIDTH + 5 + (RTGUI_BORDER_DEFAULT_WIDTH << 1); rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect); rtgui_label_set_text(RTGUI_LABEL(box), text); if (checked == RT_TRUE) box->status_down = RTGUI_CHECKBOX_STATUS_CHECKED; else box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED; } return box; }
void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y) { rtgui_rect_t rect; struct rtgui_event_resize eresize; if (menu == RT_NULL) return; /* set window extent */ rect.x1 = 0; rect.y1 = 0; rect.x2 = 100; rect.y2 = menu->items_count * (rtgui_theme_get_selected_height() + 2) + 5; rtgui_rect_moveto(&rect, x, y); rtgui_win_set_rect(RTGUI_WIN(menu), &rect); rtgui_rect_inflate(&rect, -1); rtgui_widget_set_rect(RTGUI_WIDGET(menu->items_list), &rect); eresize.parent.type = RTGUI_EVENT_RESIZE; eresize.x = rect.x1; eresize.y = rect.y1; eresize.h = rect.y2 - rect.y1; eresize.w = rect.x2 - rect.x1; rtgui_listctrl_event_handler(RTGUI_WIDGET(menu->items_list), &(eresize.parent)); /* on menu pop handler */ if (menu->on_menupop != RT_NULL) { menu->on_menupop(RTGUI_WIDGET(menu), RT_NULL); } /* show menu window */ rtgui_win_show(RTGUI_WIN(menu), RT_FALSE); }
static void _rtgui_filelist_view_constructor(struct rtgui_filelist_view *view) { /* default rect */ struct rtgui_rect rect = {0, 0, 200, 200}; /* set default widget rect and set event handler */ rtgui_object_set_event_handler(RTGUI_OBJECT(view), rtgui_filelist_view_event_handler); rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect); RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; view->current_item = 0; view->items_count = 0; view->page_items = 0; view->on_changed = RT_NULL; view->current_directory = RT_NULL; view->pattern = RT_NULL; RTGUI_WIDGET_BACKGROUND(view) = white; RTGUI_WIDGET_TEXTALIGN(view) = RTGUI_ALIGN_CENTER_VERTICAL; _instance_count++; if (_instance_count == 1) { file_image = rtgui_image_create_from_mem("xpm", (rt_uint8_t *)file_xpm, sizeof(file_xpm), RT_TRUE); folder_image = rtgui_image_create_from_mem("xpm", (rt_uint8_t *)folder_xpm, sizeof(folder_xpm), RT_TRUE); } }
/* 触发模态窗口显示 */ 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 listitem_action(rtgui_widget_t *widget, void *parameter) { 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(main_win, "窗口", &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(win, RTGUI_WIDGET(label)); /* 非模态显示窗口 */ rtgui_win_show(win, RT_FALSE); }
static void _rtgui_textbox_constructor(rtgui_textbox_t *box) { rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT}; rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect); RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_textbox_event_handler); rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus); rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus); /* set default text align */ RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL; /* set proper of control */ box->caret_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC, _rtgui_textbox_caret_timeout, box); box->line = box->line_begin = box->position = 0; box->flag = RTGUI_TEXTBOX_SINGLE; /* allocate default line buffer */ box->text = RT_NULL; rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect); box->font_width = rtgui_rect_width(rect); }
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_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; }
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; }
rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title) { struct rtgui_workbench* workbench; /* the server thread id */ rt_thread_t server = rtgui_thread_get_server(); if (server == RT_NULL) { rt_kprintf("can't find rtgui server\n"); return RT_NULL; } /* create workbench */ workbench = (rtgui_workbench_t*) rtgui_widget_create (RTGUI_WORKBENCH_TYPE); if (workbench != RT_NULL) { /* the buffer uses to receive event */ union { struct rtgui_event_panel_attach ecreate; struct rtgui_event_panel_info epanel; char buffer[256]; /* use to recv other information */ } event; /* set workbench title */ workbench->title = (unsigned char*)rt_strdup((char*)title); /* create application in server */ RTGUI_EVENT_PANEL_ATTACH_INIT(&(event.ecreate)); /* set the panel name and workbench */ rt_strncpy(event.ecreate.panel_name, panel_name, RTGUI_NAME_MAX); event.ecreate.workbench = workbench; /* send PANEL ATTACH to server */ if (rtgui_thread_send_sync(server, &(event.ecreate.parent), sizeof(struct rtgui_event_panel_attach)) != RTGUI_STATUS_OK) { return RT_NULL; } /* get PANEL INFO */ rtgui_thread_recv_filter(RTGUI_EVENT_PANEL_INFO, &(event.epanel.parent), sizeof(event)); /* set panel */ workbench->panel = (struct rtgui_panel*)event.epanel.panel; /* connected */ RTGUI_TOPLEVEL(workbench)->server = server; /* set extent of workbench */ rtgui_widget_set_rect(RTGUI_WIDGET(workbench), &(event.epanel.extent)); /* set workbench in thread */ rtgui_thread_set_widget(RTGUI_WIDGET(workbench)); } return workbench; }
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 rtgui_edit_adjust_scroll(rtgui_scrollbar_t *bar) { struct rtgui_edit *edit; RT_ASSERT(bar != RT_NULL); if(bar->WIDGET_GROUP != RT_NULL) { rtgui_rect_t rect; rt_uint32_t _left=0,_top=0,_width=RTGUI_DEFAULT_SB_WIDTH,_len=0; edit = bar->WIDGET_GROUP; rtgui_widget_get_rect(edit, &rect); rtgui_widget_rect_to_device(edit,&rect); if(bar->orient==RTGUI_HORIZONTAL) { if(RTGUI_WIDGET_IS_HIDE(edit->hscroll)) { if(edit->max_rows > edit->row_per_page) { RTGUI_WIDGET_SHOW(edit->hscroll); rtgui_scrollbar_set_line_step(edit->hscroll, 1); rtgui_scrollbar_set_page_step(edit->hscroll, edit->row_per_page); rtgui_scrollbar_set_range(edit->hscroll, edit->max_rows); } else RTGUI_WIDGET_HIDE(edit->vscroll); rtgui_widget_update_clip(RTGUI_WIDGET(edit)); } else { _left = RTGUI_WIDGET_BORDER_SIZE(edit); _top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width; _len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2; if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll)) _len -= _width; rect.x1 += _left; rect.y1 += _top; rect.x2 = rect.x1+_len; rect.y2 = rect.y1+_width; } } else if(bar->orient==RTGUI_VERTICAL) { _left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width; _top = RTGUI_WIDGET_BORDER_SIZE(edit); _len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2; if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll)) _len -= _width; rect.x1 += _left; rect.y1 += _top; rect.x2 = rect.x1+_width; rect.y2 = rect.y1+_len; } rtgui_widget_set_rect(bar,&rect); } }
rt_bool_t rtgui_notebook_event_handler(struct rtgui_object *object, struct rtgui_event *event) { int page_index; rtgui_rect_t rect; struct rtgui_notebook *notebook; RT_ASSERT(object != RT_NULL); RT_ASSERT(event != RT_NULL); notebook = RTGUI_NOTEBOOK(object); switch (event->type) { case RTGUI_EVENT_COMMAND: /* broadcast on each tab */ _rtgui_notebook_ontab(notebook, event); break; case RTGUI_EVENT_PAINT: _rtgui_notebook_ondraw(notebook); break; case RTGUI_EVENT_MOUSE_BUTTON: _rtgui_notebook_onmouse(notebook, (struct rtgui_event_mouse *)event); break; case RTGUI_EVENT_SHOW: /* show myself */ rtgui_widget_onshow(object, event); /* show the tab widget */ return _rtgui_notebook_current_widget_handle(notebook, event); case RTGUI_EVENT_HIDE: /* hide myself */ rtgui_widget_onhide(object, event); /* hide the tab widget */ return _rtgui_notebook_current_widget_handle(notebook, event); case RTGUI_EVENT_KBD: return _rtgui_notebook_current_widget_handle(notebook, event); case RTGUI_EVENT_UPDATE_TOPLVL: /* update myself */ rtgui_widget_onupdate_toplvl(object, event); /* update all the widgets in myself */ _rtgui_notebook_all_widget_handle(notebook, event); return RT_FALSE; case RTGUI_EVENT_RESIZE: /* re-size page widget */ _rtgui_notebook_get_page_rect(notebook, &rect); rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect); for (page_index = 0; page_index < notebook->count; page_index ++) { rtgui_widget_set_rect(notebook->childs[page_index].widget, &rect); } break; default: /* use parent event handler */ return rtgui_widget_event_handler(object, event); } return RT_FALSE; }
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; }
rtgui_container_t *demo_view_scrollbar(void) { rtgui_container_t *container; rtgui_rect_t rect; rtgui_label_t *label; rtgui_scrollbar_t *hbar; rtgui_scrollbar_t *vbar; /* create a demo container */ container = demo_view("ScrollBar View"); /* get demo container rect */ demo_view_get_rect(container, &rect); label = rtgui_label_create("horizontal bar:"); rtgui_container_add_child(container, 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_scrollbar_create(RTGUI_HORIZONTAL, &rect); rtgui_container_add_child(container, RTGUI_WIDGET(hbar)); /* get demo container rect */ demo_view_get_rect(container, &rect); label = rtgui_label_create("vertical bar:"); rtgui_container_add_child(container, 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_scrollbar_create(RTGUI_VERTICAL, &rect); rtgui_container_add_child(container, RTGUI_WIDGET(vbar)); rtgui_scrollbar_set_line_step(vbar, 1); // RTGUI_WIDGET_DISABLE(vbar); return container; }
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 _rtgui_staticline_constructor(rtgui_staticline_t *staticline) { /* init widget and set event handler */ rtgui_rect_t rect = {0, 0, 100, 2}; rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect); staticline->orient= RTGUI_HORIZONTAL; rtgui_object_set_event_handler(RTGUI_OBJECT(staticline), rtgui_staticline_event_handler); }