demo_view_button.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * 程序清单:button控件演示
  3. *
  4. * 这个例子会在创建出的container上添加几个不同类型的button控件
  5. */
  6. #include "demo_view.h"
  7. #include <rtgui/widgets/button.h>
  8. /* 创建用于演示button控件的视图 */
  9. rtgui_container_t *demo_view_button(void)
  10. {
  11. rtgui_rect_t rect;
  12. rtgui_container_t *container;
  13. rtgui_button_t *button;
  14. rtgui_font_t *font;
  15. /* 先创建一个演示用的视图 */
  16. container = demo_view("Button View");
  17. /* 获得视图的位置信息 */
  18. demo_view_get_rect(container, &rect);
  19. rect.x1 += 5;
  20. rect.x2 = rect.x1 + 100;
  21. rect.y1 += 5;
  22. rect.y2 = rect.y1 + 20;
  23. /* 创建一个button控件 */
  24. button = rtgui_button_create("Red");
  25. /* 设置label控件的前景色为红色 */
  26. RTGUI_WIDGET_FOREGROUND(button) = red;
  27. /* 设置button的位置 */
  28. rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
  29. rtgui_container_add_child(container, RTGUI_WIDGET(button));
  30. /* 获得视图的位置信息 */
  31. demo_view_get_rect(container, &rect);
  32. rect.x1 += 5;
  33. rect.x2 = rect.x1 + 100;
  34. rect.y1 += 5 + 25;
  35. rect.y2 = rect.y1 + 20;
  36. /* 创建一个button控件 */
  37. button = rtgui_button_create("Blue");
  38. /* 设置label控件的前景色为蓝色 */
  39. RTGUI_WIDGET_FOREGROUND(button) = blue;
  40. /* 设置button的位置 */
  41. rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
  42. rtgui_container_add_child(container, RTGUI_WIDGET(button));
  43. /* 获得视图的位置信息 */
  44. demo_view_get_rect(container, &rect);
  45. rect.x1 += 5;
  46. rect.x2 = rect.x1 + 100;
  47. rect.y1 += 5 + 25 + 25;
  48. rect.y2 = rect.y1 + 20;
  49. /* 创建一个button控件 */
  50. button = rtgui_button_create("12 font");
  51. /* 设置字体为12点阵的asc字体 */
  52. font = rtgui_font_refer("asc", 12);
  53. RTGUI_WIDGET_FONT(button) = font;
  54. /* 设置button的位置 */
  55. rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
  56. rtgui_container_add_child(container, RTGUI_WIDGET(button));
  57. /* 获得视图的位置信息 */
  58. demo_view_get_rect(container, &rect);
  59. rect.x1 += 5;
  60. rect.x2 = rect.x1 + 100;
  61. rect.y1 += 5 + 25 + 25 + 25;
  62. rect.y2 = rect.y1 + 20;
  63. /* 创建一个button控件 */
  64. button = rtgui_button_create("16 font");
  65. /* 设置字体为16点阵的asc字体 */
  66. font = rtgui_font_refer("asc", 16);
  67. RTGUI_WIDGET_FONT(button) = font;
  68. /* 设置button的位置 */
  69. rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
  70. rtgui_container_add_child(container, RTGUI_WIDGET(button));
  71. return container;
  72. }