demo_view_textbox.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * 程序清单:texbox控件演示
  3. *
  4. * 这个例子会在创建出的view上添加几个不同类型的textbox控件
  5. */
  6. #include "demo_view.h"
  7. #include <rtgui/widgets/label.h>
  8. #include <rtgui/widgets/textbox.h>
  9. /* 创建用于演示textbox控件的视图 */
  10. rtgui_view_t* demo_view_textbox(rtgui_workbench_t* workbench)
  11. {
  12. rtgui_rect_t rect, textbox_rect;
  13. rtgui_view_t* view;
  14. rtgui_label_t* label;
  15. rtgui_textbox_t* text;
  16. /* 先创建一个演示用的视图 */
  17. view = demo_view(workbench, "TextBox View");
  18. /* 获得视图的位置信息 */
  19. demo_view_get_rect(view, &rect);
  20. rect.x1 += 5;
  21. rect.x2 = rect.x1 + 30;
  22. rect.y1 += 5;
  23. rect.y2 = rect.y1 + 20;
  24. /* 创建一个label控件 */
  25. label = rtgui_label_create("名字: ");
  26. /* 设置label的位置 */
  27. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  28. /* view是一个container控件,调用add_child方法添加这个label控件 */
  29. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  30. /* 让textbox_rect赋值到rect,以计算textbox控件的位置 */
  31. textbox_rect = rect;
  32. textbox_rect.x1 = textbox_rect.x2 + 5;
  33. textbox_rect.x2 = textbox_rect.x1 + 160;
  34. /* 创建一个textbox控件 */
  35. text = rtgui_textbox_create("bernard",RTGUI_TEXTBOX_SINGLE);
  36. /* 设置textbox控件的位置 */
  37. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  38. /* 添加textbox控件到视图中 */
  39. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  40. /* 计算下一个label控件的位置 */
  41. rect.y1 += 23;
  42. rect.y2 = rect.y1 + 20;
  43. /* 创建一个label控件 */
  44. label = rtgui_label_create("邮件: ");
  45. /* 设置label的位置 */
  46. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  47. /* 添加label控件到视图中 */
  48. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  49. textbox_rect = rect;
  50. textbox_rect.x1 = textbox_rect.x2 + 5;
  51. textbox_rect.x2 = textbox_rect.x1 + 160;
  52. /* 创建一个textbox控件 */
  53. text = rtgui_textbox_create("bernard.xiong@gmail.com",RTGUI_TEXTBOX_SINGLE);
  54. /* 设置textbox控件的位置 */
  55. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  56. /* 添加textbox控件到视图中 */
  57. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  58. rect.y1 += 23;
  59. rect.y2 = rect.y1 + 20;
  60. /* 创建一个label控件 */
  61. label = rtgui_label_create("密码: ");
  62. /* 设置label的位置 */
  63. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  64. /* 添加label控件到视图中 */
  65. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  66. textbox_rect = rect;
  67. textbox_rect.x1 = textbox_rect.x2 + 5;
  68. textbox_rect.x2 = textbox_rect.x1 + 160;
  69. /* 创建一个textbox控件 */
  70. text = rtgui_textbox_create("rt-thread",RTGUI_TEXTBOX_SINGLE);
  71. /* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */
  72. text->flag |= RTGUI_TEXTBOX_MASK;
  73. /* 设置textbox控件的位置 */
  74. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  75. /* 添加textbox控件到视图中 */
  76. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  77. rect.y1 += 23;
  78. rect.y2 = rect.y1 + 20;
  79. /* 创建一个label控件 */
  80. label = rtgui_label_create("主页: ");
  81. /* 设置label的位置 */
  82. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  83. /* 添加label控件到视图中 */
  84. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  85. textbox_rect = rect;
  86. textbox_rect.x1 = textbox_rect.x2 + 5;
  87. textbox_rect.x2 = textbox_rect.x1 + 160;
  88. /* 创建一个textbox控件 */
  89. text = rtgui_textbox_create("http://www.rt-thread.org",RTGUI_TEXTBOX_SINGLE);
  90. /* 设置textbox控件的位置 */
  91. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  92. /* 添加textbox控件到视图中 */
  93. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  94. return view;
  95. }