/* 创建用于演示textbox控件的视图 */ rtgui_view_t* demo_gui_textbox(rtgui_view_t* parent_view) { rtgui_view_t* view; /* 先创建一个演示用的视图 */ view = demo_view_create(parent_view, "TextBox View"); rtgui_label_create(view, "名字: ", 5, 40, 50, 20); rtgui_textbox_create(view, "bernard",5, 60, 200, 20, RTGUI_TEXTBOX_NONE); rtgui_label_create(view, "邮件: ", 5, 80, 50, 20); rtgui_textbox_create(view, "*****@*****.**", 5, 100, 200, 20, RTGUI_TEXTBOX_NONE); rtgui_label_create(view, "密码: ", 5, 120, 50, 20); rtgui_textbox_create(view, "rt-thread", 5, 140, 200, 20, RTGUI_TEXTBOX_MASK); rtgui_label_create(view, "主页: ", 5, 160, 50, 20); rtgui_textbox_create(view, "http://www.rt-thread.org", 5, 180, 200, 20, RTGUI_TEXTBOX_NONE); return view; }
rtgui_container_t *demo_view_bmp(void) { rtgui_rect_t rect; rtgui_container_t *container, *showbox; rtgui_button_t *button; rtgui_textbox_t *box; /* 用bmpdt结构体记录一些参数 */ rt_memset(&bmpdt, 0, sizeof(struct demo_bmp_dt)); bmpdt.scale = 1.0; bmpdt.angle = 0.0; /* 创建用于演示本代码的容器控件 */ container = demo_view("Bmp File:"); demo_view_get_rect(container, &rect); rect.x1 += 85; rect.x2 -= 5; rect.y1 -= 42; rect.y2 = rect.y1 + 20; box = rtgui_textbox_create("", RTGUI_TEXTBOX_SINGLE); rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(box)); bmpdt.box = box; /* create a button "open" */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 = rect.x1 + 60; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("open"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_bitmap_open); /* create a button "zoom in" */ demo_view_get_rect(container, &rect); rect.x1 += 85; rect.x2 = rect.x1 + 70; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("zoom in"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_image_zoom_in); /* create a button "zoom out" */ demo_view_get_rect(container, &rect); rect.x1 += 165; rect.x2 = rect.x1 + 70; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("zoom out"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_image_zoom_out); /* create a button "rotate" */ demo_view_get_rect(container, &rect); rect.x1 += 245; rect.x2 = rect.x1 + 70; rect.y1 -= 10; rect.y2 = rect.y1 + 24; button = rtgui_button_create("rotate"); rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(button)); rtgui_button_set_onbutton(button, demo_image_rotate); /* create a container "showbox" */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 20; rect.y2 -= 0; showbox = rtgui_container_create(); rtgui_widget_set_rect(RTGUI_WIDGET(showbox), &rect); rtgui_container_add_child(container, RTGUI_WIDGET(showbox)); rtgui_widget_set_border(RTGUI_WIDGET(showbox), RTGUI_BORDER_SIMPLE); bmpdt.showbox = showbox; rtgui_object_set_event_handler(RTGUI_OBJECT(showbox), demo_bitmap_showbox); rtgui_widget_get_rect(RTGUI_WIDGET(showbox), &bmpdt.lastrect); rtgui_rect_inflate(&bmpdt.lastrect, -RTGUI_WIDGET_BORDER(showbox)); return container; }
rtgui_combo_t* rtgui_combo_create(pvoid parent,const char* text,int left,int top,int w,int h) { rtgui_container_t *container; rtgui_combo_t* cbo; RT_ASSERT(parent != RT_NULL); container = RTGUI_CONTAINER(parent); cbo = rtgui_widget_create(RTGUI_COMBO_TYPE); if(cbo != 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+RTGUI_COMBO_HEIGHT; rtgui_widget_set_rect(cbo,&rect); rtgui_container_add_child(container, cbo); if(cbo->tbox == RT_NULL) { int tw,th; tw = w-RTGUI_COMBO_BUTTON_WIDTH-RTGUI_WIDGET_BORDER_SIZE(cbo)*2; th = h-RTGUI_WIDGET_BORDER_SIZE(cbo)*2; cbo->tbox = rtgui_textbox_create(cbo,text, RTGUI_WIDGET_BORDER_SIZE(cbo), RTGUI_WIDGET_BORDER_SIZE(cbo), tw,th,RTGUI_TEXTBOX_NONE); if(cbo->tbox == RT_NULL) return RT_NULL; rtgui_widget_set_border_style(cbo->tbox,RTGUI_BORDER_NONE); cbo->tbox->isedit = RT_FALSE;/* default combo textbox cannot edit */ } if(cbo->lbox == RT_NULL) { rtgui_point_t point; rt_uint32_t mleft,mtop,mwidth; rtgui_widget_get_position(cbo, &point); mleft = point.x; mtop = point.y+RTGUI_COMBO_HEIGHT; mwidth = rtgui_widget_get_width(cbo); /* create pull down listbox */ cbo->lbox = rtgui_listbox_create(parent,mleft,mtop,mwidth,4); if(cbo->lbox == RT_NULL)return RT_NULL; rtgui_widget_set_border_style(cbo->lbox,RTGUI_BORDER_SIMPLE); cbo->lbox->ispopup = RT_TRUE; cbo->lbox->widget_link = cbo; rtgui_listbox_set_onitem(cbo->lbox,rtgui_combo_onitem); RTGUI_WIDGET_HIDE(cbo->lbox); } } return cbo; }
/* * 构建应用视图 */ int app_view_structure(struct rtgui_workbench *workbench, struct rtgui_view *view) { int ret = SUCC; rtgui_rect_t rect, body_rect; rtgui_label_t* label; char str[48]; //rtgui_radiobox_t *radiobox; //rtgui_button_t* button; struct tm *ptime; #if 1==DISPLAY_OVERLOAD_INFO rtgui_label_t *rx_overload_label; #endif app_view_get_can_use_rect(view, &rect); zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, rect.x1, rect.y1, rect.x2, rect.y2)); body_rect.x1 = 0; body_rect.y1 = 0; body_rect.x2 = rect.x2; body_rect.y2 = TITLE_PANEL_HEIGHT; label = rtgui_label_create(DEVICE_NAME); if (NULL != label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(label), &body_rect); /* view是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); } else { printf_syn("creat title label fail\n"); } body_rect.x1 = 0; body_rect.y1 = TITLE_PANEL_HEIGHT; body_rect.x2 = rect.x2; body_rect.y2 = rect.y2; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); zvd_notebook = rtgui_notebook_create(&body_rect, RTGUI_NOTEBOOK_TOP); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(zvd_notebook)); re_form = rtgui_form_create(re_form_head, RE_FORM_ROWS, RE_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "接收端", RTGUI_WIDGET(re_form)); #if 1 set_form_px_col(re_form); i2str(str, avg_val[AVI_RE_PA]); rtgui_form_set_item(re_form, str, RE_PA_AVG_VALUE_ROW, RE_PA_AVG_VALUE_COL, 0); rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PA_OVER_RANGE_ROW, RE_PA_OVER_RANGE_COL, 0); i2str(str, avg_val[AVI_RE_PB]); rtgui_form_set_item(re_form, str, RE_PB_AVG_VALUE_ROW, RE_PB_AVG_VALUE_COL, 0); rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PB_OVER_RANGE_ROW, RE_PB_OVER_RANGE_COL, 0); i2str(str, avg_val[AVI_RE_PC]); rtgui_form_set_item(re_form, str, RE_PC_AVG_VALUE_ROW, RE_PC_AVG_VALUE_COL, 0); rtgui_form_set_item(re_form, print_info_str[PIS_ID_ZHENGCHANG], RE_PC_OVER_RANGE_ROW, RE_PC_OVER_RANGE_COL, 0); #endif se_form = rtgui_form_create(se_form_head, SE_FORM_ROWS, SE_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "发射端", RTGUI_WIDGET(se_form)); #if 1 set_form_px_col(se_form); rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PA_OVER_RANGE_ROW, SE_PA_OVER_RANGE_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PA_POWER_DOWN_ROW, SE_PA_POWER_DOWN_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PB_OVER_RANGE_ROW, SE_PB_OVER_RANGE_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PB_POWER_DOWN_ROW, SE_PB_POWER_DOWN_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_ZHENGCHANG], SE_PC_OVER_RANGE_ROW, SE_PC_OVER_RANGE_COL, 0); rtgui_form_set_item(se_form, print_info_str[PIS_ID_FOU], SE_PC_POWER_DOWN_ROW, SE_PC_POWER_DOWN_COL, 0); #endif sys_form = rtgui_form_create(sys_form_head, SYS_FORM_ROWS, SYS_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "系统", RTGUI_WIDGET(sys_form)); #if 1 rtgui_form_set_item(sys_form, "接收端", 1, 0, 0); i2str(str, sys_temper[STI_RE_CPU_T]); rtgui_form_set_item(sys_form, str, RE_RE_CPU_TEMP_ROW, RE_RE_CPU_TEMP_COL, 0); i2str(str, sys_temper[STI_RE_CTB_T]); rtgui_form_set_item(sys_form, str, RE_RE_BOX_TEMP_ROW, RE_RE_BOX_TEMP_COL, 0); convert_ver2str(re_version, str); rtgui_form_set_item(sys_form, str, RE_RE_SOFT_VER_ROW, RE_RE_SOFT_VER_COL, 0); rtgui_form_set_item(sys_form, "发射端", 2, 0, 0); i2str(str, sys_temper[STI_SE_CPU_T]); rtgui_form_set_item(sys_form, str, RE_SE_CPU_TEMP_ROW, RE_SE_CPU_TEMP_COL, 0); i2str(str, sys_temper[STI_SE_CTB_T]); rtgui_form_set_item(sys_form, str, RE_SE_BOX_TEMP_ROW, RE_SE_BOX_TEMP_COL, 0); convert_ver2str(se_version, str); rtgui_form_set_item(sys_form, str, RE_SE_SOFT_VER_ROW, RE_SE_SOFT_VER_COL, 0); creat_devsn(str, sizeof(str), 0); rtgui_form_set_row(sys_form, str, TE_SN_ROW); creat_devsn(str, sizeof(str), 1); rtgui_form_set_row(sys_form, str, RE_SN_ROW); #endif other_form = rtgui_form_create(other_form_head, OTHER_FORM_ROWS, OTHER_FORM_COLS, &body_rect); rtgui_notebook_add(zvd_notebook, "掉电", RTGUI_WIDGET(other_form)); #if 1 rtgui_form_set_item(other_form, "次数", 1, 0, 0); rtgui_form_set_item(other_form, "n", 2, 0, 0); rtgui_form_set_item(other_form, "n-1", 3, 0, 0); rtgui_form_set_item(other_form, "n-2", 4, 0, 0); update_tx_poweroff_info_of_otherform(); update_rx_poweroff_info_of_otherform(); #endif body_rect.x1 = FRAME_GAP; body_rect.y1 = body_rect.y2 + WIDGET_ROW_GAP; body_rect.x2 = FRAME_GAP + 8 * rt_strlen(RE_IF_SWITCH2CABLE_STR); body_rect.y2 = body_rect.y1 + 16; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); switch_cable_label = rtgui_label_create(RE_IF_SWITCH2CABLE_STR); if (NULL != switch_cable_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch_cable_label)) = RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch_cable_label)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(switch_cable_label), &body_rect); /* view是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch_cable_label)); } else { printf_syn("creat cable label fail\n"); } #if 1 body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 16 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); switch_cable_yn_textview = rtgui_textview_create(print_info_str[PIS_ID_FOU], &body_rect); if (NULL != switch_cable_yn_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch_cable_yn_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch_cable_yn_textview)) = red; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch_cable_yn_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #if 1 body_rect.x1 = body_rect.x2 + 2 + 2*8; body_rect.x2 = body_rect.x1 + 8*rt_strlen(TE_HAD_POWEROFF_STR); zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); tx_poweroff_label = rtgui_label_create(TE_HAD_POWEROFF_STR); if (NULL != tx_poweroff_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(tx_poweroff_label)) = RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(tx_poweroff_label), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(tx_poweroff_label)); } else { printf_syn("tx poweroff label fail\n"); } body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 16 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); tx_poweroff_yn_textview = rtgui_textview_create(print_info_str[PIS_ID_FOU], &body_rect); if (NULL != tx_poweroff_yn_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(tx_poweroff_yn_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(tx_poweroff_yn_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #if 1 body_rect.x1 = FRAME_GAP; body_rect.y1 = body_rect.y2 + WIDGET_ROW_GAP; body_rect.x2 = FRAME_GAP + (8+1) * rt_strlen(RE_BUZZER_DISABLE_STR); body_rect.y2 = body_rect.y1 + 16 + 2*WIDGET_ROW_GAP; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); buzzer_button = rtgui_pushbutton_create(RE_BUZZER_DISABLE_STR); if (NULL != buzzer_button) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(buzzer_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(buzzer_button)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(buzzer_button), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(buzzer_button)); rtgui_button_set_onbutton(buzzer_button, buzzer_btn_onbutton); } else { printf_syn("creat buzzer pushbutton fail\n"); } body_rect.x1 = body_rect.x2 + FRAME_GAP; /* body_rect.y1 = body_rect.y1; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ body_rect.x2 = body_rect.x1 + (8+1) * rt_strlen(SWITCH_TO_PT_STR);; /* body_rect.y2 = body_rect.y2; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ switch2pt_button = rtgui_pushbutton_create(SWITCH_TO_PT_STR); if (NULL != switch2pt_button) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(switch2pt_button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(switch2pt_button)) = blue; rtgui_widget_set_rect(RTGUI_WIDGET(switch2pt_button), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(switch2pt_button)); rtgui_button_set_onbutton(switch2pt_button, switch2pt_btn_onbutton); } else { printf_syn("creat switch button fail\n"); } #if USE_OPTICX_200S_VERSION body_rect.x1 = body_rect.x2 + FRAME_GAP; /* body_rect.y1 = body_rect.y1; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ body_rect.x2 = body_rect.x1 + (8) * rt_strlen(RE_CUR_CHANNEL_NO_STR) + 2; /* body_rect.y2 = body_rect.y2; */ /* 与前一个按钮在同一行, 所以, y1, y2保持不变 */ zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); rxe_cur_channel_label = rtgui_label_create(RE_CUR_CHANNEL_NO_STR); if (NULL != rxe_cur_channel_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rxe_cur_channel_label)) = RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(rxe_cur_channel_label), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rxe_cur_channel_label)); } else { printf_syn("rxe cru channel label fail\n"); } body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 8 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); str[0] = convert_cur_channel_to_char(); str[1] = '\0'; rxe_cur_channel_no_textview = rtgui_textview_create(str, &body_rect); if (NULL != rxe_cur_channel_no_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rxe_cur_channel_no_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rxe_cur_channel_no_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #endif #if 1==DISPLAY_OVERLOAD_INFO body_rect.x1 = body_rect.x2 + 2 + 7*8; body_rect.x2 = body_rect.x1 + 8*rt_strlen(RE_OVERLOAD_CNT_STR); zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); rx_overload_label = rtgui_label_create(RE_OVERLOAD_CNT_STR); if (NULL != rx_overload_label) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rx_overload_label)) = RTGUI_ALIGN_CENTER_VERTICAL; rtgui_widget_set_rect(RTGUI_WIDGET(rx_overload_label), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rx_overload_label)); } else { printf_syn("tx poweroff label fail\n"); } body_rect.x1 = body_rect.x2 + 2; body_rect.x2 = body_rect.x1 + 16 + 8; zvd_gui_debug(("fun:%s(), line:%d, (%d,%d) (%d,%d)!\n", __FUNCTION__, __LINE__, body_rect.x1, body_rect.y1, body_rect.x2, body_rect.y2)); rx_overload_cnt_textview = rtgui_textview_create("0", &body_rect); if (NULL != rx_overload_cnt_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(rx_overload_cnt_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(rx_overload_cnt_textview)); } else { printf_syn("creat cable yn textview fail\n"); } #endif #if 1 /* 创建时间标签, 2013-03-18 09:20 */ rtc_dev = rt_device_find("rtc"); if (NULL != rtc_dev) { time_t time; rt_device_control(rtc_dev, RT_DEVICE_CTRL_RTC_GET_TIME, &time); ptime = localtime(&time); rt_sprintf(sys_time_str, "%4d-%02d-%02d %02d:%02d:%02d", (ptime->tm_year+1900), (ptime->tm_mon+1), ptime->tm_mday, ptime->tm_hour, ptime->tm_min, ptime->tm_sec); body_rect.x2 = rtgui_graphic_driver_get_default()->width; body_rect.y2 = rtgui_graphic_driver_get_default()->height; body_rect.x1 = body_rect.x2 - (8+1) * 19; body_rect.y1 = body_rect.y2 - 20; #if SYS_TIME_USE_TEXTBOX sys_time_textbox = rtgui_textbox_create(sys_time_str, RTGUI_TEXTBOX_SINGLE | RTGUI_TEXTBOX_CARET_HIDE); if (NULL != sys_time_textbox) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(sys_time_textbox)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue; RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue; //default_background; //RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)); rtgui_widget_set_rect(RTGUI_WIDGET(sys_time_textbox), &body_rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(sys_time_textbox)); } else { printf_syn("creat sys time textbox fail\n"); } #else sys_time_textview = rtgui_textview_create(sys_time_str, &body_rect); if (NULL != sys_time_textview) { RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(sys_time_textview)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; //RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(sys_time_textbox)) = blue; rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(sys_time_textview)); } else { printf_syn("creat sys time textview fail\n"); } #endif } else { printf_syn("find rtc device fail\n"); } #endif rtgui_view_show(view, RT_FALSE); /* 显示视图 */ return ret; }
/* 创建用于演示textbox控件的视图 */ rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench) { rtgui_rect_t rect, textbox_rect; rtgui_view_t* view; rtgui_label_t* label; rtgui_textbox_t* text; /* 先创建一个演示用的视图 */ 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; /* 创建一个label控件 */ label = rtgui_label_create("名字: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* view是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); /* 让textbox_rect赋值到rect,以计算textbox控件的位置 */ textbox_rect = rect; textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160; /* 创建一个textbox控件 */ text = rtgui_textbox_create("bernard",RTGUI_TEXTBOX_SINGLE); /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); /* 计算下一个label控件的位置 */ rect.y1 += 23; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("邮件: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加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控件 */ text = rtgui_textbox_create("*****@*****.**",RTGUI_TEXTBOX_SINGLE); /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rect.y1 += 23; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("密码: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加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控件 */ text = rtgui_textbox_create("rt-thread",RTGUI_TEXTBOX_SINGLE); /* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */ text->flag |= RTGUI_TEXTBOX_MASK; /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); rect.y1 += 23; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("主页: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* 添加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控件 */ text = rtgui_textbox_create("http://www.rt-thread.org",RTGUI_TEXTBOX_SINGLE); /* 设置textbox控件的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect); /* 添加textbox控件到视图中 */ rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text)); return view; }