Merge pull request #11683 from WenhaiLin/v3-label-i10576

Label:Fixed the character positions could be wrong if `getLetter(letterIndex)` get called.
This commit is contained in:
minggo 2015-05-05 18:19:33 +08:00
commit 902c033838
3 changed files with 47 additions and 5 deletions

View File

@ -628,13 +628,15 @@ void Label::alignText()
letterSprite = dynamic_cast<Sprite*>(child);
if (letterSprite)
{
uvRect.size.height = _lettersInfo[tag].def.height;
uvRect.size.width = _lettersInfo[tag].def.width;
uvRect.origin.x = _lettersInfo[tag].def.U;
uvRect.origin.y = _lettersInfo[tag].def.V;
auto& letterDef = _lettersInfo[tag].def;
uvRect.size.height = letterDef.height;
uvRect.size.width = letterDef.width;
uvRect.origin.x = letterDef.U;
uvRect.origin.y = letterDef.V;
letterSprite->setTexture(textures.at(_lettersInfo[tag].def.textureID));
letterSprite->setTexture(textures.at(letterDef.textureID));
letterSprite->setTextureRect(uvRect);
letterSprite->setPosition(_lettersInfo[tag].position);
}
++index;
}

View File

@ -76,6 +76,7 @@ NewLabelTests::NewLabelTests()
ADD_TEST_CASE(LabelIssue10089Test);
ADD_TEST_CASE(LabelSystemFontColor);
ADD_TEST_CASE(LabelIssue10773Test);
ADD_TEST_CASE(LabelIssue10576Test);
};
LabelTTFAlignmentNew::LabelTTFAlignmentNew()
@ -1884,3 +1885,31 @@ std::string LabelIssue10773Test::subtitle() const
{
return "Should not crash!";
}
LabelIssue10576Test::LabelIssue10576Test()
{
auto center = VisibleRect::center();
auto label = Label::createWithTTF("abcdefg", "fonts/arial.ttf", 24);
for (int index = 0; index < label->getStringLength(); ++index)
{
label->getLetter(index);
}
this->runAction(Sequence::create(DelayTime::create(2.0f), CallFunc::create([label](){
label->setString("Hello World!");
}), nullptr));
label->setPosition(center.x, center.y);
addChild(label);
}
std::string LabelIssue10576Test::title() const
{
return "Test for Issue #10576";
}
std::string LabelIssue10576Test::subtitle() const
{
return "You should see another string displayed correctly after 2 seconds.";
}

View File

@ -565,4 +565,15 @@ public:
virtual std::string subtitle() const override;
};
class LabelIssue10576Test : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelIssue10576Test);
LabelIssue10576Test();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
#endif