demo_simple_workbench.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * A simple workbench
  3. */
  4. #include <rtthread.h>
  5. #include <rtgui/rtgui_server.h>
  6. #include <rtgui/rtgui_system.h>
  7. #include <rtgui/widgets/label.h>
  8. #include <rtgui/widgets/workbench.h>
  9. static void workbench_entry(void* parameter)
  10. {
  11. rt_mq_t mq;
  12. rtgui_view_t* view;
  13. rtgui_label_t* label;
  14. struct rtgui_workbench* workbench;
  15. rtgui_rect_t rect;
  16. mq = rt_mq_create("wmq", 256, 8, RT_IPC_FLAG_FIFO);
  17. /* 注册当前线程为GUI线程 */
  18. rtgui_thread_register(rt_thread_self(), mq);
  19. /* 创建一个工作台 */
  20. workbench = rtgui_workbench_create("main", "workbench #1");
  21. if (workbench == RT_NULL) return;
  22. view = rtgui_view_create("view");
  23. if (view == RT_NULL) return;
  24. /* 指定视图的背景色 */
  25. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
  26. /* 添加一个label */
  27. label = rtgui_label_create("你好!RT-Thread!");
  28. rect.x1 = 10; rect.y1 = 10;
  29. rect.x2 = 210; rect.y2 = 30;
  30. /* 设置label的位置 */
  31. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  32. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  33. /* 添加到父workbench中 */
  34. rtgui_workbench_add_view(workbench, view);
  35. /* 非模式方式显示视图 */
  36. rtgui_view_show(view, RT_FALSE);
  37. /* 执行工作台事件循环 */
  38. rtgui_workbench_event_loop(workbench);
  39. /* 去注册GUI线程 */
  40. rtgui_thread_deregister(rt_thread_self());
  41. /* delete message queue */
  42. rt_mq_delete(mq);
  43. }
  44. /* 初始化workbench */
  45. void wb_init()
  46. {
  47. rt_thread_t tid;
  48. tid = rt_thread_create("wb1", workbench_entry, RT_NULL, 2048, 20, 5);
  49. if (tid != RT_NULL) rt_thread_startup(tid);
  50. }