VerticalLayout.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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::Border border = container->getBorder(container->getState());
  39. Theme::Padding padding = container->getPadding();
  40. float yPosition = 0;
  41. std::vector<Control*> controls = container->getControls();
  42. unsigned int i, end, iter;
  43. if (_bottomToTop)
  44. {
  45. i = controls.size() - 1;
  46. end = -1;
  47. iter = -1;
  48. }
  49. else
  50. {
  51. i = 0;
  52. end = controls.size();
  53. iter = 1;
  54. }
  55. while (i != end)
  56. {
  57. Control* control = controls.at(i);
  58. align(control, container);
  59. const Rectangle& bounds = control->getClipBounds();
  60. const Theme::Margin& margin = control->getMargin();
  61. yPosition += margin.top;
  62. control->setPosition(0, yPosition);
  63. if (control->isDirty() || control->isContainer())
  64. {
  65. control->update(container->getClip());
  66. }
  67. yPosition += bounds.height + margin.bottom;
  68. i += iter;
  69. }
  70. }
  71. }