mirror of https://github.com/axmolengine/axmol.git
Improves the test to reproduce issue 12996
This commit is contained in:
parent
b1bd8338aa
commit
a1e682ca65
|
@ -1520,96 +1520,42 @@ LabelAlignmentTest::LabelAlignmentTest()
|
|||
menu->setPosition(Vec2(s.width - 50, s.height / 2 - 20));
|
||||
this->addChild(menu);
|
||||
|
||||
_horizAlign = TextHAlignment::LEFT;
|
||||
_vertAlign = TextVAlignment::TOP;
|
||||
|
||||
TTFConfig ttfConfig("fonts/arial.ttf", 32);
|
||||
_label = Label::create();
|
||||
_label->setDimensions(200,160);
|
||||
_label->setAlignment(_horizAlign,_vertAlign);
|
||||
_label->setTTFConfig(ttfConfig);
|
||||
_label->setString(getCurrentAlignment());
|
||||
TTFConfig ttfConfig("fonts/arial.ttf", 50);
|
||||
_label = Label::createWithTTF(ttfConfig, "abc efg hijk lmn opq rst uvw xyz");
|
||||
_label->setDimensions(200, 160);
|
||||
_label->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
||||
_label->setPosition(pos);
|
||||
addChild(_label);
|
||||
|
||||
}
|
||||
|
||||
LabelAlignmentTest::~LabelAlignmentTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LabelAlignmentTest::setAlignmentLeft(Ref* sender)
|
||||
{
|
||||
_horizAlign = TextHAlignment::LEFT;
|
||||
_label->setHorizontalAlignment(_horizAlign);
|
||||
_label->setString(getCurrentAlignment());
|
||||
_label->setHorizontalAlignment(TextHAlignment::LEFT);
|
||||
}
|
||||
|
||||
void LabelAlignmentTest::setAlignmentCenter(Ref* sender)
|
||||
{
|
||||
_horizAlign = TextHAlignment::CENTER;
|
||||
_label->setHorizontalAlignment(_horizAlign);
|
||||
_label->setString(getCurrentAlignment());
|
||||
_label->setHorizontalAlignment(TextHAlignment::CENTER);
|
||||
}
|
||||
|
||||
void LabelAlignmentTest::setAlignmentRight(Ref* sender)
|
||||
{
|
||||
_horizAlign = TextHAlignment::RIGHT;
|
||||
_label->setHorizontalAlignment(_horizAlign);
|
||||
_label->setString(getCurrentAlignment());
|
||||
_label->setHorizontalAlignment(TextHAlignment::RIGHT);
|
||||
}
|
||||
|
||||
void LabelAlignmentTest::setAlignmentTop(Ref* sender)
|
||||
{
|
||||
_vertAlign = TextVAlignment::TOP;
|
||||
_label->setVerticalAlignment(_vertAlign);
|
||||
_label->setString(getCurrentAlignment());
|
||||
_label->setVerticalAlignment(TextVAlignment::TOP);
|
||||
}
|
||||
|
||||
void LabelAlignmentTest::setAlignmentMiddle(Ref* sender)
|
||||
{
|
||||
_vertAlign = TextVAlignment::CENTER;
|
||||
_label->setVerticalAlignment(_vertAlign);
|
||||
_label->setString(getCurrentAlignment());
|
||||
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
||||
}
|
||||
|
||||
void LabelAlignmentTest::setAlignmentBottom(Ref* sender)
|
||||
{
|
||||
_vertAlign = TextVAlignment::BOTTOM;
|
||||
_label->setVerticalAlignment(_vertAlign);
|
||||
_label->setString(getCurrentAlignment());
|
||||
}
|
||||
|
||||
std::string LabelAlignmentTest::getCurrentAlignment()
|
||||
{
|
||||
const char* vertical = nullptr;
|
||||
const char* horizontal = nullptr;
|
||||
switch (_vertAlign) {
|
||||
case TextVAlignment::TOP:
|
||||
vertical = "Top";
|
||||
break;
|
||||
case TextVAlignment::CENTER:
|
||||
vertical = "Middle";
|
||||
break;
|
||||
case TextVAlignment::BOTTOM:
|
||||
vertical = "Bottom";
|
||||
break;
|
||||
}
|
||||
switch (_horizAlign) {
|
||||
case TextHAlignment::LEFT:
|
||||
horizontal = "Left";
|
||||
break;
|
||||
case TextHAlignment::CENTER:
|
||||
horizontal = "Center";
|
||||
break;
|
||||
case TextHAlignment::RIGHT:
|
||||
horizontal = "Right";
|
||||
break;
|
||||
}
|
||||
|
||||
return StringUtils::format("Alignment %s %s", vertical, horizontal);
|
||||
_label->setVerticalAlignment(TextVAlignment::BOTTOM);
|
||||
}
|
||||
|
||||
std::string LabelAlignmentTest::title() const
|
||||
|
@ -1619,7 +1565,7 @@ std::string LabelAlignmentTest::title() const
|
|||
|
||||
std::string LabelAlignmentTest::subtitle() const
|
||||
{
|
||||
return "Select the buttons on the sides to change alignment";
|
||||
return "Test text alignment";
|
||||
}
|
||||
|
||||
LabelIssue4428Test::LabelIssue4428Test()
|
||||
|
|
|
@ -428,7 +428,6 @@ public:
|
|||
CREATE_FUNC(LabelAlignmentTest);
|
||||
|
||||
LabelAlignmentTest();
|
||||
virtual ~LabelAlignmentTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
private:
|
||||
|
@ -438,11 +437,8 @@ private:
|
|||
void setAlignmentTop(cocos2d::Ref* sender);
|
||||
void setAlignmentMiddle(cocos2d::Ref* sender);
|
||||
void setAlignmentBottom(cocos2d::Ref* sender);
|
||||
std::string getCurrentAlignment();
|
||||
|
||||
cocos2d::Label* _label;
|
||||
cocos2d::TextHAlignment _horizAlign;
|
||||
cocos2d::TextVAlignment _vertAlign;
|
||||
};
|
||||
|
||||
class LabelIssue4428Test : public AtlasDemoNew
|
||||
|
|
Loading…
Reference in New Issue