demo_view_radiobox.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * 程序清单:radiobox控件演示
  3. *
  4. * 这个例子会在创建出的view上添加两个不同方向的radiobox控件
  5. */
  6. #include "demo_view.h"
  7. #include <rtgui/widgets/radiobox.h>
  8. /* 用于显示垂直方向的radio文本项数组 */
  9. static char* radio_item_v[5] =
  10. {
  11. "one",
  12. "two",
  13. "three",
  14. "item 1",
  15. "item 2"
  16. };
  17. /* 用于显示水平方向的radio文本项数组 */
  18. static char* radio_item_h[3] =
  19. {
  20. "one", "two", "three"
  21. };
  22. /* 创建用于演示radiobox控件的视图 */
  23. rtgui_view_t* demo_view_radiobox(rtgui_workbench_t* workbench)
  24. {
  25. rtgui_rect_t rect;
  26. rtgui_view_t* view;
  27. rtgui_radiobox_t* radiobox;
  28. /* 先创建一个演示用的视图 */
  29. view = demo_view(workbench, "RadioBox View");
  30. /* 获得视图的位置信息 */
  31. demo_view_get_rect(view, &rect);
  32. rect.x1 += 5;
  33. rect.x2 -= 5;
  34. rect.y1 += 5;
  35. rect.y2 = rect.y1 + 5 * 25;
  36. /* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
  37. radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
  38. /* 设置当前选择的数组是第0项 */
  39. rtgui_radiobox_set_selection(radiobox, 0);
  40. /* 添加radiobox控件到视图中 */
  41. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
  42. /* 设置radiobox控件的位置信息 */
  43. rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
  44. /* 获得视图的位置信息 */
  45. demo_view_get_rect(view, &rect);
  46. rect.x1 += 5;
  47. rect.x2 -= 5;
  48. rect.y1 += 5 + 5 * 25;
  49. rect.y2 = rect.y1 + 60;
  50. /* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */
  51. radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
  52. /* 设置当前选择的数组是第0项 */
  53. rtgui_radiobox_set_selection(radiobox, 0);
  54. /* 添加radiobox控件到视图中 */
  55. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
  56. /* 设置radiobox控件的位置信息 */
  57. rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
  58. return view;
  59. }