demo_view_progressbar.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "demo_view.h"
  2. #include <rtgui/rtgui_system.h>
  3. #include <rtgui/widgets/label.h>
  4. #include <rtgui/widgets/progressbar.h>
  5. static rtgui_progressbar_t *hbar;
  6. static rtgui_progressbar_t *vbar;
  7. static rtgui_timer_t *bar_timer = RT_NULL;
  8. void progressbar_timeout(struct rtgui_timer *timer, void *parameter)
  9. {
  10. static rt_uint32_t value = 0;
  11. value++;
  12. if (value == 100)
  13. value = 0;
  14. rtgui_progressbar_set_value(hbar, value);
  15. rtgui_progressbar_set_value(vbar, value);
  16. }
  17. static rt_bool_t start_timer(struct rtgui_object *object, struct rtgui_event *event)
  18. {
  19. if (bar_timer != RT_NULL)
  20. rtgui_timer_start(bar_timer);
  21. return RT_TRUE;
  22. }
  23. static rt_bool_t stop_timer(struct rtgui_object *object, struct rtgui_event *event)
  24. {
  25. if (bar_timer != RT_NULL)
  26. rtgui_timer_stop(bar_timer);
  27. return RT_TRUE;
  28. }
  29. rtgui_container_t *demo_view_progressbar(void)
  30. {
  31. rtgui_container_t *container;
  32. rtgui_rect_t rect;
  33. rtgui_label_t *label;
  34. /* create a demo container */
  35. container = demo_view("ProgressBar View");
  36. /* get demo container rect */
  37. demo_view_get_rect(container, &rect);
  38. label = rtgui_label_create("ˮƽ½ø¶ÈÌõ:");
  39. rtgui_container_add_child(container, RTGUI_WIDGET(label));
  40. rect.x1 += 5;
  41. rect.x2 -= 5;
  42. rect.y1 += 5;
  43. rect.y2 = rect.y1 + 18;
  44. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  45. rect.y1 += 20;
  46. rect.y2 = rect.y1 + 18;
  47. hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
  48. rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
  49. /* get demo container rect */
  50. demo_view_get_rect(container, &rect);
  51. label = rtgui_label_create("´¹Ö±½ø¶ÈÌõ:");
  52. rtgui_container_add_child(container, RTGUI_WIDGET(label));
  53. rect.x1 += 5;
  54. rect.x2 -= 5;
  55. rect.y1 += 45;
  56. rect.y2 = rect.y1 + 18;
  57. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  58. rect.x1 += 110;
  59. rect.x2 = rect.x1 + 20;
  60. rect.y1 += 18 + 5;
  61. rect.y2 = rect.y1 + 150;
  62. vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
  63. rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
  64. bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
  65. progressbar_timeout, RT_NULL);
  66. rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
  67. rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);
  68. return container;
  69. }