| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "Base.h"
- #include "Control.h"
- #include "FlowLayout.h"
- #include "Container.h"
- namespace gameplay
- {
- static FlowLayout* __instance;
- FlowLayout::FlowLayout()
- {
- }
- FlowLayout::FlowLayout(const FlowLayout& copy)
- {
- }
- FlowLayout::~FlowLayout()
- {
- }
- FlowLayout* FlowLayout::create()
- {
- if (!__instance)
- {
- __instance = new FlowLayout();
- }
- else
- {
- __instance->addRef();
- }
- return __instance;
- }
- Layout::Type FlowLayout::getType()
- {
- return Layout::LAYOUT_FLOW;
- }
- void FlowLayout::update(const Container* container, const Vector2& offset)
- {
- GP_ASSERT(container);
- const Rectangle& containerBounds = container->getBounds();
- const Theme::Border& containerBorder = container->getBorder(container->getState());
- const Theme::Padding& containerPadding = container->getPadding();
- float clipWidth = containerBounds.width - containerBorder.left - containerBorder.right - containerPadding.left - containerPadding.right;
- float clipHeight = containerBounds.height - containerBorder.top - containerBorder.bottom - containerPadding.top - containerPadding.bottom;
- float xPosition = 0;
- float yPosition = 0;
- float rowY = 0;
- float tallestHeight = 0;
- std::vector<Control*> controls = container->getControls();
- unsigned int controlsCount = controls.size();
- for (unsigned int i = 0; i < controlsCount; i++)
- {
- Control* control = controls.at(i);
- GP_ASSERT(control);
- //align(control, container);
- const Rectangle& bounds = control->getBounds();
- const Theme::Margin& margin = control->getMargin();
- xPosition += margin.left;
- // Wrap to next row if we've gone past the edge of the container.
- if (xPosition + bounds.width >= clipWidth)
- {
- xPosition = margin.left;
- rowY += tallestHeight;
- }
- yPosition = rowY + margin.top;
- control->setPosition(xPosition, yPosition);
- control->update(container, offset);
- xPosition += bounds.width + margin.right;
- float height = bounds.height + margin.top + margin.bottom;
- if (height > tallestHeight)
- {
- tallestHeight = height;
- }
- }
- }
- }
|