VerticalLayout.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "Base.h"
  2. #include "VerticalLayout.h"
  3. namespace gameplay
  4. {
  5. VerticalLayout::VerticalLayout() : _bottomToTop(false)
  6. {
  7. }
  8. VerticalLayout::~VerticalLayout()
  9. {
  10. }
  11. VerticalLayout* VerticalLayout::create()
  12. {
  13. return new VerticalLayout();
  14. }
  15. void VerticalLayout::setBottomToTop(bool bottomToTop)
  16. {
  17. _bottomToTop = bottomToTop;
  18. }
  19. bool VerticalLayout::getBottomToTop()
  20. {
  21. return _bottomToTop;
  22. }
  23. Layout::Type VerticalLayout::getType()
  24. {
  25. return Layout::LAYOUT_VERTICAL;
  26. }
  27. void VerticalLayout::update(const Container* container, const Vector2& offset)
  28. {
  29. GP_ASSERT(container);
  30. // Need border, padding.
  31. Theme::Border border = container->getBorder(container->getState());
  32. Theme::Padding padding = container->getPadding();
  33. float yPosition = 0;
  34. std::vector<Control*> controls = container->getControls();
  35. int i, end, iter;
  36. if (_bottomToTop)
  37. {
  38. i = (int)controls.size() - 1;
  39. end = -1;
  40. iter = -1;
  41. }
  42. else
  43. {
  44. i = 0;
  45. end = (int)controls.size();
  46. iter = 1;
  47. }
  48. while (i != end)
  49. {
  50. Control* control = controls.at(i);
  51. GP_ASSERT(control);
  52. align(control, container);
  53. const Rectangle& bounds = control->getBounds();
  54. const Theme::Margin& margin = control->getMargin();
  55. yPosition += margin.top;
  56. control->setPosition(margin.left, yPosition);
  57. control->update(container, offset);
  58. yPosition += bounds.height + margin.bottom;
  59. i += iter;
  60. }
  61. }
  62. }