| 41 | } |
| 42 | |
| 43 | void LinearHorizontalLayoutManager::doLayout(LayoutProtocol* layout) |
| 44 | { |
| 45 | Vec2 layoutSize = layout->getLayoutContentSize(); |
| 46 | Vector<Node*> container = layout->getLayoutElements(); |
| 47 | float leftBoundary = 0.0f; |
| 48 | for (auto&& subWidget : container) |
| 49 | { |
| 50 | Widget* child = dynamic_cast<Widget*>(subWidget); |
| 51 | if (child) |
| 52 | { |
| 53 | LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter()); |
| 54 | if (layoutParameter) |
| 55 | { |
| 56 | LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity(); |
| 57 | Vec2 ap = child->getAnchorPoint(); |
| 58 | Vec2 cs = child->getBoundingBox().size; |
| 59 | float finalPosX = leftBoundary + (ap.x * cs.width); |
| 60 | float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height; |
| 61 | switch (childGravity) |
| 62 | { |
| 63 | case LinearLayoutParameter::LinearGravity::NONE: |
| 64 | case LinearLayoutParameter::LinearGravity::TOP: |
| 65 | break; |
| 66 | case LinearLayoutParameter::LinearGravity::BOTTOM: |
| 67 | finalPosY = ap.y * cs.height; |
| 68 | break; |
| 69 | case LinearLayoutParameter::LinearGravity::CENTER_VERTICAL: |
| 70 | finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y); |
| 71 | break; |
| 72 | default: |
| 73 | break; |
| 74 | } |
| 75 | Margin mg = layoutParameter->getMargin(); |
| 76 | finalPosX += mg.left; |
| 77 | finalPosY -= mg.top; |
| 78 | child->setPosition(Vec2(finalPosX, finalPosY)); |
| 79 | leftBoundary = child->getRightBoundary() + mg.right; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // LinearVerticalLayoutManager |
| 86 | LinearVerticalLayoutManager* LinearVerticalLayoutManager::create() |
nothing calls this directly
no test coverage detected