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