| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "Base.h"
- #include "VerticalLayout.h"
- namespace gameplay
- {
- static VerticalLayout* __instance;
- VerticalLayout::VerticalLayout() : _bottomToTop(false)
- {
- }
- VerticalLayout::VerticalLayout(const VerticalLayout& copy)
- {
- }
- VerticalLayout::~VerticalLayout()
- {
- __instance = NULL;
- }
- VerticalLayout* VerticalLayout::create()
- {
- if (!__instance)
- {
- __instance = new VerticalLayout();
- }
- else
- {
- __instance->addRef();
- }
- return __instance;
- }
- void VerticalLayout::setBottomToTop(bool bottomToTop)
- {
- _bottomToTop = bottomToTop;
- }
- Layout::Type VerticalLayout::getType()
- {
- return Layout::LAYOUT_VERTICAL;
- }
- void VerticalLayout::update(const Container* container, const Vector2& offset)
- {
- GP_ASSERT(container);
- // Need border, padding.
- Theme::Border border = container->getBorder(container->getState());
- Theme::Padding padding = container->getPadding();
- float yPosition = 0;
- std::vector<Control*> controls = container->getControls();
- unsigned int i, end, iter;
- if (_bottomToTop)
- {
- i = controls.size() - 1;
- end = -1;
- iter = -1;
- }
- else
- {
- i = 0;
- end = controls.size();
- iter = 1;
- }
- while (i != end)
- {
- Control* control = controls.at(i);
- GP_ASSERT(control);
- align(control, container);
- const Rectangle& bounds = control->getBounds();
- const Theme::Margin& margin = control->getMargin();
- yPosition += margin.top;
- control->setPosition(margin.left, yPosition);
- control->update(container, offset);
- yPosition += bounds.height + margin.bottom;
- i += iter;
- }
- }
- }
|