demo_view_textbox.c 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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; rect.x2 = rect.x1 + 30;
  21. rect.y1 += 5; rect.y2 = rect.y1 + 20;
  22. /* 创建一个label控件 */
  23. label = rtgui_label_create("名字: ");
  24. /* 设置label的位置 */
  25. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  26. /* view是一个container控件,调用add_child方法添加这个label控件 */
  27. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  28. /* 让textbox_rect赋值到rect,以计算textbox控件的位置 */
  29. textbox_rect = rect;
  30. textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
  31. /* 创建一个textbox控件 */
  32. text = rtgui_textbox_create("bernard",RTGUI_TEXTBOX_SINGLE);
  33. /* 设置textbox控件的位置 */
  34. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  35. /* 添加textbox控件到视图中 */
  36. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  37. /* 计算下一个label控件的位置 */
  38. rect.y1 += 23; rect.y2 = rect.y1 + 20;
  39. /* 创建一个label控件 */
  40. label = rtgui_label_create("邮件: ");
  41. /* 设置label的位置 */
  42. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  43. /* 添加label控件到视图中 */
  44. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  45. textbox_rect = rect;
  46. textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
  47. /* 创建一个textbox控件 */
  48. text = rtgui_textbox_create("bernard.xiong@gmail.com",RTGUI_TEXTBOX_SINGLE);
  49. /* 设置textbox控件的位置 */
  50. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  51. /* 添加textbox控件到视图中 */
  52. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  53. rect.y1 += 23; rect.y2 = rect.y1 + 20;
  54. /* 创建一个label控件 */
  55. label = rtgui_label_create("密码: ");
  56. /* 设置label的位置 */
  57. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  58. /* 添加label控件到视图中 */
  59. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  60. textbox_rect = rect;
  61. textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
  62. /* 创建一个textbox控件 */
  63. text = rtgui_textbox_create("rt-thread",RTGUI_TEXTBOX_SINGLE);
  64. /* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */
  65. text->flag |= RTGUI_TEXTBOX_MASK;
  66. /* 设置textbox控件的位置 */
  67. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  68. /* 添加textbox控件到视图中 */
  69. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  70. rect.y1 += 23; rect.y2 = rect.y1 + 20;
  71. /* 创建一个label控件 */
  72. label = rtgui_label_create("主页: ");
  73. /* 设置label的位置 */
  74. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  75. /* 添加label控件到视图中 */
  76. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  77. textbox_rect = rect;
  78. textbox_rect.x1 = textbox_rect.x2 + 5; textbox_rect.x2 = textbox_rect.x1 + 160;
  79. /* 创建一个textbox控件 */
  80. text = rtgui_textbox_create("http://www.rt-thread.org",RTGUI_TEXTBOX_SINGLE);
  81. /* 设置textbox控件的位置 */
  82. rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
  83. /* 添加textbox控件到视图中 */
  84. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(text));
  85. return view;
  86. }