fix UIText dimension error when set ignoreContentSize to false

This commit is contained in:
andyque 2014-11-25 18:16:34 +08:00
parent 0d9b679bb7
commit a2883aa097
1 changed files with 16 additions and 10 deletions

View File

@ -76,7 +76,8 @@ bool Text::init()
Text* Text::create(const std::string &textContent, const std::string &fontName, int fontSize)
{
Text *text = new (std::nothrow) Text;
if (text && text->init(textContent, fontName, fontSize)) {
if (text && text->init(textContent, fontName, fontSize))
{
text->autorelease();
return text;
}
@ -87,8 +88,10 @@ Text* Text::create(const std::string &textContent, const std::string &fontName,
bool Text::init(const std::string &textContent, const std::string &fontName, int fontSize)
{
bool ret = true;
do {
if (!Widget::init()) {
do
{
if (!Widget::init())
{
ret = false;
break;
}
@ -129,10 +132,12 @@ ssize_t Text::getStringLength()const
void Text::setFontSize(int size)
{
if (_type == Type::SYSTEM) {
if (_type == Type::SYSTEM)
{
_labelRenderer->setSystemFontSize(size);
}
else{
else
{
TTFConfig config = _labelRenderer->getTTFConfig();
config.fontSize = size;
_labelRenderer->setTTFConfig(config);
@ -157,7 +162,8 @@ void Text::setFontName(const std::string& name)
_labelRenderer->setTTFConfig(config);
_type = Type::TTF;
}
else{
else
{
_labelRenderer->setSystemFontName(name);
if (_type == Type::TTF)
{
@ -183,6 +189,10 @@ Text::Type Text::getType() const
void Text::setTextAreaSize(const Size &size)
{
_labelRenderer->setDimensions(size.width,size.height);
if (!_ignoreSize)
{
_customSize=size;
}
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
}
@ -195,8 +205,6 @@ const Size& Text::getTextAreaSize()const
void Text::setTextHorizontalAlignment(TextHAlignment alignment)
{
_labelRenderer->setHorizontalAlignment(alignment);
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
}
TextHAlignment Text::getTextHorizontalAlignment()const
@ -207,8 +215,6 @@ TextHAlignment Text::getTextHorizontalAlignment()const
void Text::setTextVerticalAlignment(TextVAlignment alignment)
{
_labelRenderer->setVerticalAlignment(alignment);
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
}
TextVAlignment Text::getTextVerticalAlignment()const