update ui button size changed logic

This commit is contained in:
Liam 2014-10-24 17:38:32 +08:00
parent e5ac916a17
commit 92bdfea638
2 changed files with 56 additions and 29 deletions

View File

@ -194,16 +194,7 @@ void Button::ignoreContentAdaptWithSize(bool ignore)
{ {
if (_unifySize) if (_unifySize)
{ {
if (_scale9Enabled) this->updateContentSize();
{
ProtectedNode::setContentSize(_customSize);
}
else
{
Size s = getVirtualRendererSize();
ProtectedNode::setContentSize(s);
}
onSizeChanged();
return; return;
} }
if (!_scale9Enabled || (_scale9Enabled && !ignore)) if (!_scale9Enabled || (_scale9Enabled && !ignore))
@ -249,7 +240,17 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType)
updateFlippedY(); updateFlippedY();
this->updateChildrenDisplayedRGBA(); this->updateChildrenDisplayedRGBA();
if (_unifySize )
{
if (!_scale9Enabled)
{
updateContentSizeWithTextureSize(this->getNormalSize());
}
}
else
{
updateContentSizeWithTextureSize(_normalTextureSize); updateContentSizeWithTextureSize(_normalTextureSize);
}
_normalTextureLoaded = true; _normalTextureLoaded = true;
_normalTextureAdaptDirty = true; _normalTextureAdaptDirty = true;
} }
@ -532,6 +533,20 @@ void Button::updateTitleLocation()
void Button::updateContentSize() void Button::updateContentSize()
{ {
if (_unifySize)
{
if (_scale9Enabled)
{
ProtectedNode::setContentSize(_customSize);
}
else
{
Size s = getNormalSize();
ProtectedNode::setContentSize(s);
}
onSizeChanged();
return;
}
if (_ignoreSize) { if (_ignoreSize) {
this->setContentSize(getVirtualRendererSize()); this->setContentSize(getVirtualRendererSize());
} }
@ -596,11 +611,8 @@ Node* Button::getVirtualRenderer()
void Button::normalTextureScaleChangedWithSize() void Button::normalTextureScaleChangedWithSize()
{ {
if (_unifySize)
{ if (_ignoreSize && !_unifySize)
_buttonNormalRenderer->setPreferredSize(_contentSize);
}
else if (_ignoreSize)
{ {
if (!_scale9Enabled) if (!_scale9Enabled)
{ {
@ -638,11 +650,8 @@ void Button::normalTextureScaleChangedWithSize()
void Button::pressedTextureScaleChangedWithSize() void Button::pressedTextureScaleChangedWithSize()
{ {
if (_unifySize)
{ if (_ignoreSize && !_unifySize)
_buttonClickedRenderer->setPreferredSize(_contentSize);
}
else if (_ignoreSize)
{ {
if (!_scale9Enabled) if (!_scale9Enabled)
{ {
@ -679,11 +688,8 @@ void Button::pressedTextureScaleChangedWithSize()
void Button::disabledTextureScaleChangedWithSize() void Button::disabledTextureScaleChangedWithSize()
{ {
if (_unifySize)
{ if (_ignoreSize && !_unifySize)
_buttonDisableRenderer->setPreferredSize(_contentSize);
}
else if (_ignoreSize)
{ {
if (!_scale9Enabled) if (!_scale9Enabled)
{ {
@ -784,9 +790,11 @@ void Button::setTitleFontName(const std::string& fontName)
{ {
_titleRenderer->requestSystemFontRefresh(); _titleRenderer->requestSystemFontRefresh();
} }
_titleRenderer->setSystemFontSize(_fontSize);
_type = FontType::SYSTEM; _type = FontType::SYSTEM;
} }
_fontName = fontName; _fontName = fontName;
this->updateContentSize();
} }
Label* Button::getTitleRenderer()const Label* Button::getTitleRenderer()const
@ -829,6 +837,24 @@ void Button::copySpecialProperties(Widget *widget)
setPressedActionEnabled(button->_pressedActionEnabled); setPressedActionEnabled(button->_pressedActionEnabled);
setZoomScale(button->_zoomScale); setZoomScale(button->_zoomScale);
} }
}
Size Button::getNormalSize()
{
Size titleSize;
if (_titleRenderer != nullptr)
{
titleSize = _titleRenderer->getContentSize();
}
Size imageSize;
if (_buttonNormalRenderer != nullptr)
{
imageSize = _buttonNormalRenderer->getContentSize();
}
float width = titleSize.width > imageSize.width ? titleSize.width : imageSize.width;
float height = titleSize.height > imageSize.height ? titleSize.height : imageSize.height;
return Size(width,height);
} }
} }

View File

@ -234,6 +234,7 @@ protected:
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual Size getNormalSize();
protected: protected:
Scale9Sprite* _buttonNormalRenderer; Scale9Sprite* _buttonNormalRenderer;
Scale9Sprite* _buttonClickedRenderer; Scale9Sprite* _buttonClickedRenderer;