demo_simple_workbench.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_container_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_container_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;
  29. rect.y1 = 10;
  30. rect.x2 = 210;
  31. rect.y2 = 30;
  32. /* 设置label的位置 */
  33. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  34. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  35. /* 添加到父workbench中 */
  36. rtgui_workbench_add_view(workbench, view);
  37. /* 非模式方式显示视图 */
  38. rtgui_container_show(view, RT_FALSE);
  39. /* 执行工作台事件循环 */
  40. rtgui_workbench_event_loop(workbench);
  41. /* 去注册GUI线程 */
  42. rtgui_thread_deregister(rt_thread_self());
  43. /* delete message queue */
  44. rt_mq_delete(mq);
  45. }
  46. /* 初始化workbench */
  47. void wb_init()
  48. {
  49. rt_thread_t tid;
  50. tid = rt_thread_create("wb1", workbench_entry, RT_NULL, 2048, 20, 5);
  51. if (tid != RT_NULL) rt_thread_startup(tid);
  52. }