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

Method needsLayout

extensions/GUI/src/GUI/ControlExtension/ControlButton.cpp:488–598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486}
487
488void ControlButton::needsLayout()
489{
490 if (!_parentInited)
491 {
492 return;
493 }
494 // Hide the background and the label
495 if (_titleLabel != nullptr)
496 {
497 _titleLabel->setVisible(false);
498 }
499 if (_backgroundSprite)
500 {
501 _backgroundSprite->setVisible(false);
502 }
503 // Update anchor of all labels
504 this->setLabelAnchorPoint(this->_labelAnchorPoint);
505
506 // Update the label to match with the current state
507 _currentTitle = getTitleForState(_state);
508
509 _currentTitleColor = getTitleColorForState(_state);
510
511 this->setTitleLabel(getTitleLabelForState(_state));
512
513 LabelProtocol* label = dynamic_cast<LabelProtocol*>(_titleLabel);
514 if (label && !_currentTitle.empty())
515 {
516 label->setString(_currentTitle);
517 }
518
519 if (_titleLabel)
520 {
521 _titleLabel->setColor(_currentTitleColor);
522 }
523 if (_titleLabel != nullptr)
524 {
525 _titleLabel->setPosition(getContentSize().width / 2, getContentSize().height / 2);
526 }
527
528 // Update the background sprite
529 this->setBackgroundSprite(this->getBackgroundSpriteForState(_state));
530 if (_backgroundSprite != nullptr)
531 {
532 _backgroundSprite->setPosition(getContentSize().width / 2, getContentSize().height / 2);
533 }
534
535 // Get the title label size
536 Size titleLabelSize;
537 if (_titleLabel != nullptr)
538 {
539 titleLabelSize = _titleLabel->getBoundingBox().size;
540 }
541
542 // Adjust the background image if necessary
543 if (_doesAdjustBackgroundImage)
544 {
545 // Add the margins

Callers

nothing calls this directly

Calls 12

setLabelAnchorPointMethod · 0.95
setTitleLabelMethod · 0.80
getPreferredSizeMethod · 0.80
SizeClass · 0.50
setVisibleMethod · 0.45
emptyMethod · 0.45
setStringMethod · 0.45
setColorMethod · 0.45
setPositionMethod · 0.45
getBoundingBoxMethod · 0.45
setContentSizeMethod · 0.45

Tested by

no test coverage detected