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; }
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); }
/* 创建用于演示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; }