MCPcopy Create free account
hub / github.com/axmolengine/axmol / doLayout

Method doLayout

core/ui/UILayoutManager.cpp:43–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void 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
86LinearVerticalLayoutManager* LinearVerticalLayoutManager::create()

Callers

nothing calls this directly

Calls 14

getAllWidgetsMethod · 0.95
getLayoutContentSizeMethod · 0.80
getLayoutParameterMethod · 0.80
getAnchorPointMethod · 0.80
getRightBoundaryMethod · 0.80
Vec2Function · 0.50
getGravityMethod · 0.45
getBoundingBoxMethod · 0.45
getMarginMethod · 0.45
setPositionMethod · 0.45

Tested by

no test coverage detected