VerticalLayout.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "Base.h"
  2. #include "VerticalLayout.h"
  3. namespace gameplay
  4. {
  5. static VerticalLayout* __instance;
  6. VerticalLayout::VerticalLayout() : _bottomToTop(false)
  7. {
  8. }
  9. VerticalLayout::VerticalLayout(const VerticalLayout& copy)
  10. {
  11. }
  12. VerticalLayout::~VerticalLayout()
  13. {
  14. }
  15. VerticalLayout* VerticalLayout::create()
  16. {
  17. if (!__instance)
  18. {
  19. __instance = new VerticalLayout();
  20. }
  21. else
  22. {
  23. __instance->addRef();
  24. }
  25. return __instance;
  26. }
  27. void VerticalLayout::setBottomToTop(bool bottomToTop)
  28. {
  29. _bottomToTop = bottomToTop;
  30. }
  31. Layout::Type VerticalLayout::getType()
  32. {
  33. return Layout::LAYOUT_VERTICAL;
  34. }
  35. void VerticalLayout::update(const Container* container)
  36. {
  37. // Need border, padding.
  38. Theme::Style* style = container->getStyle();
  39. Theme::Border border;
  40. Theme::ContainerRegion* containerRegion = style->getOverlay(container->getOverlayType())->getContainerRegion();
  41. if (containerRegion)
  42. {
  43. border = containerRegion->getBorder();
  44. }
  45. Theme::Padding padding = style->getPadding();
  46. float yPosition = 0;
  47. std::vector<Control*> controls = container->getControls();
  48. unsigned int i, end, iter;
  49. if (_bottomToTop)
  50. {
  51. i = controls.size() - 1;
  52. end = -1;
  53. iter = -1;
  54. }
  55. else
  56. {
  57. i = 0;
  58. end = controls.size();
  59. iter = 1;
  60. }
  61. while (i != end)
  62. {
  63. Control* control = controls.at(i);
  64. const Rectangle& bounds = control->getBounds();
  65. const Theme::Margin& margin = control->getStyle()->getMargin();
  66. yPosition += margin.top;
  67. control->setPosition(0, yPosition);
  68. if (control->isDirty())
  69. {
  70. control->update(container->getClip());
  71. }
  72. yPosition += bounds.height + margin.bottom;
  73. i += iter;
  74. }
  75. }
  76. }