| 486 | } |
| 487 | |
| 488 | void 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 |
nothing calls this directly
no test coverage detected