static void _rtgui_fileview_constructor(rtgui_fileview_t *fview) { /* set default widget rect and set event handler */ rtgui_widget_set_event_handler(fview, rtgui_fileview_event_handler); rtgui_widget_set_onunfocus(fview, rtgui_fileview_onunfocus); RTGUI_WIDGET_FLAG(fview) |= RTGUI_WIDGET_FLAG_FOCUSABLE; fview->first_item = 0; fview->now_item = 0; fview->item_count = 0; fview->item_per_page = 0; fview->current_dir = RT_NULL; fview->pattern = RT_NULL; RTGUI_WIDGET_BC(fview) = theme.blankspace; RTGUI_WIDGET_TEXTALIGN(fview) = RTGUI_ALIGN_CENTER_VERTICAL; if(theme.style == RTGUI_BORDER_UP) rtgui_widget_set_border_style(fview,RTGUI_BORDER_DOWN); else if(theme.style == RTGUI_BORDER_EXTRA) rtgui_widget_set_border_style(fview,RTGUI_BORDER_SUNKEN); fview->on_item = RT_NULL; fview->dlg = RT_NULL; if(file_image==RT_NULL) file_image = rtgui_image_create_from_mem("xpm",(rt_uint8_t*)file_xpm, sizeof(file_xpm), RT_TRUE); if(folder_image==RT_NULL) folder_image = rtgui_image_create_from_mem("xpm",(rt_uint8_t*)folder_xpm, sizeof(folder_xpm), RT_TRUE); }
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); }
/* 创建用于演示列表视图的视图 */ 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 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 info_entry(void* parameter) { rt_mq_t mq; struct rtgui_view* view; struct rtgui_workbench* workbench; mq = rt_mq_create("qInfo", 256, 4, RT_IPC_FLAG_FIFO); rtgui_thread_register(rt_thread_self(), mq); network_image = rtgui_image_create_from_mem("xpm", (rt_uint8_t*)network_xpm, sizeof(network_xpm), RT_TRUE); workbench = rtgui_workbench_create("info", "workbench"); if (workbench == RT_NULL) return; view = rtgui_view_create("view"); RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white; rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler); rtgui_workbench_add_view(workbench, view); rtgui_view_show(view, RT_FALSE); rtgui_workbench_event_loop(workbench); rtgui_thread_deregister(rt_thread_self()); rt_mq_delete(mq); }
/* 创建用于演示label控件的视图 */ rtgui_container_t *demo_view_listctrl(void) { rtgui_rect_t rect; rtgui_container_t *container; rtgui_label_t *label; rtgui_listctrl_t *box; /* 先创建一个演示用的视图 */ container = demo_view("List Control Demo"); if (item_icon == RT_NULL) item_icon = rtgui_image_create_from_mem("xpm", (const rt_uint8_t *)image_xpm, sizeof(image_xpm), RT_TRUE); items[1].image = item_icon; /* 获得视图的位置信息 */ demo_view_get_rect(container, &rect); rect.x1 += 5; rect.x2 -= 5; rect.y1 += 5; rect.y2 = rect.y1 + 20; /* 创建一个label控件 */ label = rtgui_label_create("List Control: "); /* 设置label的位置 */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* container是一个container控件,调用add_child方法添加这个label控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(label)); rect.y1 = rect.y2 + 3; rect.y2 = 250; box = rtgui_listctrl_create(items, sizeof(items) / sizeof(items[0]), &rect, _rtgui_listctrl_item_draw); rtgui_listctrl_set_onitem(box, on_items); /* container是一个container控件,调用add_child方法添加这个listctrl控件 */ rtgui_container_add_child(container, RTGUI_WIDGET(box)); return container; }
void app_mgr_win_init(void) { struct rtgui_win* win; rtgui_rect_t rect; struct rtgui_notebook *notebook; rtgui_listbox_t* box; struct rtgui_image* pressed_image; struct rtgui_image* unpressed_image; int font_size; struct block_panel* block; int angle_y; /* create main window of Application Manager */ win = rtgui_mainwin_create(RT_NULL, "AppMgr", RTGUI_WIN_STYLE_MAINWIN); RTGUI_WIDGET_BACKGROUND(win) = RTGUI_RGB(241, 241, 241); /* create icon image */ pressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_xpm, sizeof(home_xpm), RT_FALSE); unpressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_gray_xpm, sizeof(home_gray_xpm), RT_FALSE); rtgui_font_get_metrics(RTGUI_WIDGET_FONT(win), "AppMgr", &rect); font_size = rtgui_rect_height(rect); /* create notebook */ rtgui_widget_get_extent(RTGUI_WIDGET(win), &rect); notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_LEFT); RTGUI_WIDGET_BACKGROUND(notebook) = RTGUI_RGB(241, 241, 241); rtgui_notebook_set_tab_height(notebook, pressed_image->h + font_size + 3 * RTGUI_WIDGET_DEFAULT_MARGIN); rtgui_notebook_set_tab_width(notebook, 65); angle_y = rect.x1; /* create navigation */ rtgui_notebook_get_client_rect(notebook, &rect); block = block_panel_create(angle_y + notebook->tab_h/2, &rect); RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241); rtgui_notebook_add_image(notebook, "AppTask", RTGUI_WIDGET(block), pressed_image, unpressed_image); apps_list_create(RTGUI_PANEL(block)); angle_y += notebook->tab_h; block = block_panel_create(angle_y + notebook->tab_h/2, &rect); RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241); rtgui_notebook_add_image(notebook, "Tab 1", RTGUI_WIDGET(block), pressed_image, unpressed_image); { struct rtgui_rect box_rect; block_panel_get_client_extent(block, &box_rect); // rtgui_widget_get_extent(RTGUI_WIDGET(block), &box_rect); // rtgui_rect_inflate(&box_rect, -15); box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &box_rect); rtgui_container_add_child(RTGUI_CONTAINER(block), RTGUI_WIDGET(box)); } angle_y += notebook->tab_h; block = block_panel_create(angle_y + notebook->tab_h/2, &rect); RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241); rtgui_notebook_add_image(notebook, "Tab 2", RTGUI_WIDGET(block), pressed_image, unpressed_image); angle_y += notebook->tab_h; rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(notebook)); rtgui_win_show(win, RT_FALSE); /* set as main window */ rtgui_app_set_main_win(win); }