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