demo_view_progressbar.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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; rect.x2 -= 5;
  41. rect.y1 += 5; rect.y2 = rect.y1 + 18;
  42. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  43. rect.y1 += 20; rect.y2 = rect.y1 + 18;
  44. hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
  45. rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
  46. /* get demo container rect */
  47. demo_view_get_rect(container, &rect);
  48. label = rtgui_label_create("´¹Ö±½ø¶ÈÌõ:");
  49. rtgui_container_add_child(container, RTGUI_WIDGET(label));
  50. rect.x1 += 5; rect.x2 -= 5;
  51. rect.y1 += 45; rect.y2 = rect.y1 + 18;
  52. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  53. rect.x1 += 110; rect.x2 = rect.x1 + 20;
  54. rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150;
  55. vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
  56. rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
  57. bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
  58. progressbar_timeout, RT_NULL);
  59. rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
  60. rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);
  61. return container;
  62. }