demo_view_progressbar.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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) value = 0;
  13. rtgui_progressbar_set_value(hbar, value);
  14. rtgui_progressbar_set_value(vbar, value);
  15. }
  16. rtgui_view_t *demo_view_progressbar(rtgui_workbench_t* workbench)
  17. {
  18. rtgui_view_t *view;
  19. rtgui_rect_t rect;
  20. rtgui_label_t *label;
  21. /* create a demo view */
  22. view = demo_view(workbench, "ProgressBar View");
  23. /* get demo view rect */
  24. demo_view_get_rect(view, &rect);
  25. label = rtgui_label_create("ˮƽ½ø¶ÈÌõ:");
  26. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  27. rect.x1 += 5; rect.x2 -= 5;
  28. rect.y1 += 5; rect.y2 = rect.y1 + 18;
  29. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  30. rect.y1 += 20; rect.y2 = rect.y1 + 18;
  31. hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
  32. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(hbar));
  33. /* get demo view rect */
  34. demo_view_get_rect(view, &rect);
  35. label = rtgui_label_create("´¹Ö±½ø¶ÈÌõ:");
  36. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  37. rect.x1 += 5; rect.x2 -= 5;
  38. rect.y1 += 45; rect.y2 = rect.y1 + 18;
  39. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  40. rect.x1 += 110; rect.x2 = rect.x1 + 20;
  41. rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150;
  42. vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
  43. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(vbar));
  44. bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
  45. progressbar_timeout, RT_NULL);
  46. rtgui_timer_start(bar_timer);
  47. return view;
  48. }