demo_view_scrollbar.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "demo_view.h"
  2. #include <rtgui/rtgui_system.h>
  3. #include <rtgui/widgets/label.h>
  4. #include <rtgui/widgets/scrollbar.h>
  5. static rtgui_scrollbar_t* hbar;
  6. static rtgui_scrollbar_t* vbar;
  7. rtgui_view_t *demo_view_scrollbar(rtgui_workbench_t* workbench)
  8. {
  9. rtgui_view_t *view;
  10. rtgui_rect_t rect;
  11. rtgui_label_t *label;
  12. /* create a demo view */
  13. view = demo_view(workbench, "ScrollBar View");
  14. /* get demo view rect */
  15. demo_view_get_rect(view, &rect);
  16. label = rtgui_label_create("horizontal bar:");
  17. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  18. rect.x1 += 5; rect.x2 -= 5;
  19. rect.y1 += 5; rect.y2 = rect.y1 + 18;
  20. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  21. rect.y1 += 20; rect.y2 = rect.y1 + 18;
  22. hbar = rtgui_scrollbar_create(RTGUI_HORIZONTAL, &rect);
  23. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(hbar));
  24. /* get demo view rect */
  25. demo_view_get_rect(view, &rect);
  26. label = rtgui_label_create("vertical bar:");
  27. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  28. rect.x1 += 5; rect.x2 -= 5;
  29. rect.y1 += 45; rect.y2 = rect.y1 + 18;
  30. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  31. rect.x1 += 110; rect.x2 = rect.x1 + 20;
  32. rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150;
  33. vbar = rtgui_scrollbar_create(RTGUI_VERTICAL, &rect);
  34. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(vbar));
  35. return view;
  36. }