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

Method refreshLayout

core/ui/UILayoutComponent.cpp:528–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526}
527
528void LayoutComponent::refreshLayout()
529{
530 if (!_actived)
531 return;
532
533 Node* parent = this->getOwnerParent();
534 if (parent == nullptr)
535 return;
536
537 const Vec2& parentSize = parent->getContentSize();
538 const Point& ownerAnchor = _owner->getAnchorPoint();
539 Vec2 ownerSize = _owner->getContentSize();
540 Point ownerPosition = _owner->getPosition();
541
542 switch (this->_horizontalEdge)
543 {
544 case HorizontalEdge::None:
545 if (_usingStretchWidth && !_isPercentOnly)
546 {
547 ownerSize.width = parentSize.width * _percentWidth;
548 ownerPosition.x = _leftMargin + ownerAnchor.x * ownerSize.width;
549 }
550 else
551 {
552 if (_usingPositionPercentX)
553 ownerPosition.x = parentSize.width * _positionPercentX;
554 if (_usingPercentWidth)
555 ownerSize.width = parentSize.width * _percentWidth;
556 }
557 break;
558 case HorizontalEdge::Left:
559 if (_isPercentOnly)
560 break;
561 if (_usingPercentWidth || _usingStretchWidth)
562 ownerSize.width = parentSize.width * _percentWidth;
563 ownerPosition.x = _leftMargin + ownerAnchor.x * ownerSize.width;
564 break;
565 case HorizontalEdge::Right:
566 if (_isPercentOnly)
567 break;
568 if (_usingPercentWidth || _usingStretchWidth)
569 ownerSize.width = parentSize.width * _percentWidth;
570 ownerPosition.x = parentSize.width - (_rightMargin + (1 - ownerAnchor.x) * ownerSize.width);
571 break;
572 case HorizontalEdge::Center:
573 if (_isPercentOnly)
574 break;
575 if (_usingStretchWidth)
576 {
577 ownerSize.width = parentSize.width - _leftMargin - _rightMargin;
578 if (ownerSize.width < 0)
579 ownerSize.width = 0;
580 ownerPosition.x = _leftMargin + ownerAnchor.x * ownerSize.width;
581 }
582 else
583 {
584 if (_usingPercentWidth)
585 ownerSize.width = parentSize.width * _percentWidth;

Callers 4

setSizePercentMethod · 0.80
setPositionPercentMethod · 0.80
doLayoutMethod · 0.80

Calls 7

getOwnerParentMethod · 0.95
getAnchorPointMethod · 0.80
forceDoLayoutMethod · 0.80
getContentSizeMethod · 0.45
getPositionMethod · 0.45
setPositionMethod · 0.45
setContentSizeMethod · 0.45

Tested by

no test coverage detected