2012-04-18 23:06:12 +08:00
|
|
|
|
/*
|
2013-02-01 10:27:10 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵥<EFBFBD><EFBFBD>menu<EFBFBD>ؼ<EFBFBD><EFBFBD><EFBFBD>ʾ
|
2012-04-18 23:06:12 +08:00
|
|
|
|
*
|
2013-02-01 10:27:10 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>container<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>label<EFBFBD>ؼ<EFBFBD>
|
2012-04-18 23:06:12 +08:00
|
|
|
|
*/
|
|
|
|
|
#include "demo_view.h"
|
|
|
|
|
#include <rtgui/widgets/menu.h>
|
|
|
|
|
#include <rtgui/widgets/button.h>
|
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rt_bool_t _onmenuitem(struct rtgui_object *object, struct rtgui_event *event)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rt_kprintf("menu action!!\n");
|
|
|
|
|
return RT_TRUE;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static const rtgui_menu_item_t sub_items[] =
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, _onmenuitem},
|
|
|
|
|
{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
|
|
|
|
|
{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
|
|
|
|
|
{RTGUI_ITEM_NORMAL, "item #3", RT_NULL, RT_NULL, 0, RT_NULL},
|
2012-04-18 23:06:12 +08:00
|
|
|
|
};
|
|
|
|
|
static const rtgui_menu_item_t items[] =
|
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, RT_NULL},
|
|
|
|
|
{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
|
|
|
|
|
{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
|
|
|
|
|
{
|
|
|
|
|
RTGUI_ITEM_SUBMENU, "item #3", RT_NULL,
|
|
|
|
|
(struct rtgui_menu_item_t *)sub_items,
|
|
|
|
|
sizeof(sub_items) / sizeof(sub_items[0]), RT_NULL
|
|
|
|
|
},
|
2012-04-18 23:06:12 +08:00
|
|
|
|
};
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rtgui_menu_t *menu;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
static rt_bool_t _onmenu(struct rtgui_object *object, struct rtgui_event *event)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_rect_t rect;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
|
|
|
|
|
rtgui_widget_rect_to_device(RTGUI_WIDGET(object), &rect);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
if (menu != RT_NULL)
|
|
|
|
|
rtgui_menu_pop(menu, rect.x1, rect.y2 + 5);
|
2012-07-20 20:37:56 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
return RT_TRUE;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-01 10:27:10 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾmenu<6E>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>ͼ */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_container_t *demo_view_menu(void)
|
2012-04-18 23:06:12 +08:00
|
|
|
|
{
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
rtgui_container_t *container;
|
|
|
|
|
rtgui_button_t *button;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2013-02-01 10:27:10 +08:00
|
|
|
|
/* <20>ȴ<EFBFBD><C8B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʾ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ͼ */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
container = demo_view("MENU View");
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2013-02-01 10:27:10 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ϣ */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
demo_view_get_rect(container, &rect);
|
|
|
|
|
rect.x1 += 5;
|
|
|
|
|
rect.x2 = rect.x1 + 100;
|
|
|
|
|
rect.y1 += 5;
|
|
|
|
|
rect.y2 = rect.y1 + 20;
|
2013-02-01 10:27:10 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>button<6F>ؼ<EFBFBD> */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
button = rtgui_button_create("Pop Menu");
|
2013-02-01 10:27:10 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>button<6F><6E>λ<EFBFBD><CEBB> */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
2013-02-01 10:27:10 +08:00
|
|
|
|
/* container<65><72>һ<EFBFBD><D2BB>container<65>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>add_child<6C><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>button<6F>ؼ<EFBFBD> */
|
2012-08-13 16:32:01 +08:00
|
|
|
|
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
|
|
|
|
rtgui_button_set_onbutton(button, _onmenu);
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
menu = rtgui_menu_create("Menu Test", RT_NULL, items, sizeof(items) / sizeof(items[0]));
|
2012-04-18 23:06:12 +08:00
|
|
|
|
|
2012-08-13 16:32:01 +08:00
|
|
|
|
return container;
|
2012-04-18 23:06:12 +08:00
|
|
|
|
}
|