demo_view_radiobox.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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; rect.x2 -= 5;
  33. rect.y1 += 5; rect.y2 = rect.y1 + 5 * 25;
  34. /* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
  35. radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
  36. /* 设置当前选择的数组是第0项 */
  37. rtgui_radiobox_set_selection(radiobox, 0);
  38. /* 添加radiobox控件到视图中 */
  39. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
  40. /* 设置radiobox控件的位置信息 */
  41. rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
  42. /* 获得视图的位置信息 */
  43. demo_view_get_rect(view, &rect);
  44. rect.x1 += 5; rect.x2 -= 5;
  45. rect.y1 += 5 + 5 * 25; rect.y2 = rect.y1 + 60;
  46. /* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */
  47. radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
  48. /* 设置当前选择的数组是第0项 */
  49. rtgui_radiobox_set_selection(radiobox, 0);
  50. /* 添加radiobox控件到视图中 */
  51. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(radiobox));
  52. /* 设置radiobox控件的位置信息 */
  53. rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
  54. return view;
  55. }