/* 触发文件列表视图的按钮回调函数 */ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event) { rtgui_filelist_view_t *view; rtgui_workbench_t *workbench; rtgui_rect_t rect; /* 获得顶层的workbench对象 */ workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget)); rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); /* 针对Win32平台和其他平台做的不同的其实目录位置 */ #ifdef _WIN32 view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect); #else view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect); #endif /* 采用模式形式显示文件列表视图 */ if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK) { char path[32]; /* 在文件列表视图中成功选择文件,这里获得相应的路径名 */ rtgui_filelist_view_get_fullpath(view, path, sizeof(path)); /* 设置文件路径到文本标签 */ rtgui_label_set_text(label, path); } /* 删除 文件列表 视图 */ rtgui_view_destroy(RTGUI_VIEW(view)); }
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; }
/* 触发正常窗口显示 */ static void demo_normal_window_onbutton(struct rtgui_object *object, rtgui_event_t *event) { rt_sprintf(normal_window_label_text, "第 %d 次显示", normal_window_show_count); rtgui_label_set_text(normal_window_label, normal_window_label_text); if (RTGUI_WIDGET_IS_HIDE(normal_window)) rtgui_win_show(normal_window, RT_FALSE); else rtgui_win_activate(normal_window); }
/* 关闭对话框时的回调函数 */ void diag_close(struct rtgui_timer *timer, void *parameter) { cnt --; rt_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(autowin); } }
rtgui_button_t* rtgui_button_create(const char* text) { struct rtgui_button* btn; btn = (struct rtgui_button*) rtgui_widget_create (RTGUI_BUTTON_TYPE); if (btn != RT_NULL) { rtgui_rect_t rect; /* set default rect */ rtgui_font_get_metrics(rtgui_font_default(), text, &rect); rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); rtgui_widget_set_rect(RTGUI_WIDGET(btn), &rect); rtgui_label_set_text(RTGUI_LABEL(btn), text); } return btn; }