diff options
| author | [email protected] <[email protected]> | 2010-12-22 00:13:32 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2010-12-22 00:13:32 +0000 |
| commit | 990d052de1c6eae325b4072723319d5cb3281ce2 (patch) | |
| tree | f40adfdcf8c3c09411a7b19166043d481eaa6e92 /examples | |
| parent | 297405c3c662c8b8f09c1abb9579f151c7128dfe (diff) | |
update menu demo.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1221 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/gui/demo_simple_workbench.c | 60 | ||||
| -rw-r--r-- | examples/gui/demo_view_menu.c | 16 |
2 files changed, 70 insertions, 6 deletions
diff --git a/examples/gui/demo_simple_workbench.c b/examples/gui/demo_simple_workbench.c new file mode 100644 index 0000000000..d0432428c7 --- /dev/null +++ b/examples/gui/demo_simple_workbench.c @@ -0,0 +1,60 @@ +/*
+ * A simple workbench
+ */
+#include <rtthread.h>
+#include <rtgui/rtgui_server.h>
+#include <rtgui/rtgui_system.h>
+#include <rtgui/widgets/label.h>
+#include <rtgui/widgets/workbench.h>
+
+static void workbench_entry(void* parameter)
+{
+ rt_mq_t mq;
+ rtgui_view_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_view_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_view_show(view, RT_FALSE);
+
+ /* ִ�й���̨�¼�ѭ�� */
+ rtgui_workbench_event_loop(workbench);
+
+ /* ȥע��GUI�߳� */
+ rtgui_thread_deregister(rt_thread_self());
+
+ /* delete message queue */
+ rt_mq_delete(mq);
+}
+
+/* ��ʼ��workbench */
+void wb_init()
+{
+ rt_thread_t tid;
+
+ tid = rt_thread_create("wb1", workbench_entry, RT_NULL, 2048, 20, 5);
+ if (tid != RT_NULL) rt_thread_startup(tid);
+}
diff --git a/examples/gui/demo_view_menu.c b/examples/gui/demo_view_menu.c index f3b421a36c..c0dabbb8df 100644 --- a/examples/gui/demo_view_menu.c +++ b/examples/gui/demo_view_menu.c @@ -7,21 +7,25 @@ #include <rtgui/widgets/menu.h>
#include <rtgui/widgets/button.h>
+static rt_bool_t _onmenuitem(struct rtgui_widget *widget, struct rtgui_event* event)
+{
+ rt_kprintf("menu action!!\n");
+ return RT_TRUE;
+}
-static rtgui_menu_item_t sub_items[] =
+static const rtgui_menu_item_t sub_items[] =
{
- {RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, RT_NULL},
+ {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},
};
-static rtgui_menu_item_t items[] =
+static const rtgui_menu_item_t items[] =
{
{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_NORMAL, "item #3", RT_NULL, RT_NULL, 0, RT_NULL},
- // {RTGUI_ITEM_SUBMENU, "item #3", RT_NULL, sub_items, sizeof(sub_items)/sizeof(sub_items[0]), RT_NULL},
+ {RTGUI_ITEM_SUBMENU, "item #3", RT_NULL, sub_items, sizeof(sub_items)/sizeof(sub_items[0]), RT_NULL},
};
static rtgui_menu_t* menu;
@@ -33,7 +37,7 @@ static _onmenu(struct rtgui_widget* widget, struct rtgui_event* event) rtgui_widget_rect_to_device(widget, &rect);
if (menu != RT_NULL)
- rtgui_menu_pop(menu, rect.x1, rect.y2);
+ rtgui_menu_pop(menu, rect.x1, rect.y2 + 5);
}
/* 创建用于演示menu控件的视图 */
|
