/* 打开按钮的回调函数 */ 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_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK) { char path[32], name[8]; /* 设置文件路径的标签 */ rtgui_filelist_view_get_fullpath(view, path, sizeof(path)); rt_memset(name, 0, sizeof(name)); /* 获得应用模块的类型 */ if (rt_strstr(path, ".mo") != RT_NULL || rt_strstr(path, ".so") != RT_NULL) { rt_module_open(path); } } /* 删除 文件列表 视图 */ rtgui_container_destroy(RTGUI_CONTAINER(view)); rtgui_container_show(_view, 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; }
static void workbench_entry(void* parameter) { rt_mq_t mq; rtgui_container_t* view; rtgui_label_t* label; struct rtgui_workbench* workbench; rtgui_rect_t rect; mq = rt_mq_create("wmq", 256, 8, RT_IPC_FLAG_FIFO); /* 注册当前线程为GUI线程 */ rtgui_thread_register(rt_thread_self(), mq); /* 创建一个工作台 */ workbench = rtgui_workbench_create("main", "workbench #1"); if (workbench == RT_NULL) return; view = rtgui_container_create("view"); if (view == RT_NULL) return; /* 指定视图的背景色 */ RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white; /* 添加一个label */ label = rtgui_label_create("你好!RT-Thread!"); rect.x1 = 10; rect.y1 = 10; rect.x2 = 210; rect.y2 = 30; /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); /* 添加到父workbench中 */ rtgui_workbench_add_view(workbench, view); /* 非模式方式显示视图 */ rtgui_container_show(view, RT_FALSE); /* 执行工作台事件循环 */ rtgui_workbench_event_loop(workbench); /* 去注册GUI线程 */ rtgui_thread_deregister(rt_thread_self()); /* delete message queue */ rt_mq_delete(mq); }