VerticalLayout.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "Base.h"
  2. #include "VerticalLayout.h"
  3. namespace gameplay
  4. {
  5. VerticalLayout::VerticalLayout() : _bottomToTop(false), _spacing(0)
  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. int VerticalLayout::getSpacing() const
  28. {
  29. return _spacing;
  30. }
  31. void VerticalLayout::setSpacing(int spacing)
  32. {
  33. _spacing = spacing;
  34. }
  35. void VerticalLayout::update(const Container* container)
  36. {
  37. GP_ASSERT(container);
  38. // Need border, padding.
  39. Theme::Border border = container->getBorder(container->getState());
  40. Theme::Padding padding = container->getPadding();
  41. float yPosition = 0;
  42. const std::vector<Control*>& controls = container->getControls();
  43. int i, end, iter;
  44. if (_bottomToTop)
  45. {
  46. i = (int)controls.size() - 1;
  47. end = -1;
  48. iter = -1;
  49. }
  50. else
  51. {
  52. i = 0;
  53. end = (int)controls.size();
  54. iter = 1;
  55. }
  56. while (i != end)
  57. {
  58. Control* control = controls.at(i);
  59. GP_ASSERT(control);
  60. if (control->isVisible())
  61. {
  62. const Rectangle& bounds = control->getBounds();
  63. const Theme::Margin& margin = control->getMargin();
  64. yPosition += margin.top;
  65. control->setPosition(margin.left, yPosition);
  66. yPosition += bounds.height + margin.bottom + _spacing;
  67. }
  68. i += iter;
  69. }
  70. }
  71. }