add test case for new API of Label.

This commit is contained in:
Dhilan007 2014-06-18 18:01:55 +08:00
parent b2d8e4fc93
commit 9351172baf
3 changed files with 128 additions and 5 deletions

View File

@ -215,20 +215,23 @@ public:
bool isClipMarginEnabled() const { return _clipEnabled; }
/** Sets the line height of the label
* @warning Not support system font
@warning Not support system font
@since v3.2.0
*/
void setLineHeight(float height);
/** Returns the line height of this label
* @warning Not support system font
@warning Not support system font
*/
float getLineHeight() const;
/** Sets the additional kerning of the label
* @warning Not support system font
@warning Not support system font
@since v3.2.0
*/
void setAdditionalKerning(float space);
/** Returns the additional kerning of this label
* @warning Not support system font
@warning Not support system font
@since v3.2.0
*/
float getAdditionalKerning() const;

View File

@ -78,7 +78,9 @@ static std::function<Layer*()> createFunctions[] =
CL(LabelFontNameTest),
CL(LabelAlignmentTest),
CL(LabelIssue4428Test),
CL(LabelIssue4999Test)
CL(LabelIssue4999Test),
CL(LabelLineHeightTest),
CL(LabelAdditionalKerningTest)
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
@ -1773,3 +1775,91 @@ std::string LabelIssue4999Test::subtitle() const
{
return "Reorder issue #4999.The label should be display cleanly.";
}
LabelLineHeightTest::LabelLineHeightTest()
{
auto size = Director::getInstance()->getWinSize();
auto bg = LayerColor::create(Color4B(200,191,231,255));
this->addChild(bg);
TTFConfig ttfConfig("fonts/arial.ttf", 25, GlyphCollection::DYNAMIC,nullptr,false);
label = Label::createWithTTF(ttfConfig,"Test\nLine\nHeight");
label->setPosition( Vec2(size.width/2, size.height*0.5f) );
label->setTextColor( Color4B::RED );
addChild(label);
auto slider = ui::Slider::create();
slider->setTouchEnabled(true);
slider->loadBarTexture("cocosui/sliderTrack.png");
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getSize().height * 2.0f));
slider->setPercent(label->getLineHeight());
slider->addEventListener(CC_CALLBACK_2(LabelLineHeightTest::sliderEvent, this));
addChild(slider);
}
void LabelLineHeightTest::sliderEvent(Ref *sender, ui::Slider::EventType type)
{
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
{
Slider* slider = (Slider*)sender;
label->setLineHeight(slider->getPercent());
}
}
std::string LabelLineHeightTest::title() const
{
return "New Label";
}
std::string LabelLineHeightTest::subtitle() const
{
return "Testing line height of label";
}
LabelAdditionalKerningTest::LabelAdditionalKerningTest()
{
auto size = Director::getInstance()->getWinSize();
auto bg = LayerColor::create(Color4B(200,191,231,255));
this->addChild(bg);
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,nullptr,false);
label = Label::createWithTTF(ttfConfig,"Test additional kerning");
label->setPosition( Vec2(size.width/2, size.height*0.65f) );
label->setTextColor( Color4B::RED );
addChild(label);
auto slider = ui::Slider::create();
slider->setTouchEnabled(true);
slider->loadBarTexture("cocosui/sliderTrack.png");
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getSize().height * 2.0f));
slider->setPercent(0);
slider->addEventListener(CC_CALLBACK_2(LabelAdditionalKerningTest::sliderEvent, this));
addChild(slider);
}
void LabelAdditionalKerningTest::sliderEvent(Ref *sender, ui::Slider::EventType type)
{
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
{
Slider* slider = (Slider*)sender;
label->setAdditionalKerning(slider->getPercent());
}
}
std::string LabelAdditionalKerningTest::title() const
{
return "New Label";
}
std::string LabelAdditionalKerningTest::subtitle() const
{
return "Testing additional kerning of label";
}

View File

@ -496,6 +496,36 @@ public:
virtual std::string subtitle() const override;
};
class LabelLineHeightTest : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelLineHeightTest);
LabelLineHeightTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void sliderEvent(Ref *sender, ui::Slider::EventType type);
private:
Label* label;
};
class LabelAdditionalKerningTest : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelAdditionalKerningTest);
LabelAdditionalKerningTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void sliderEvent(Ref *sender, ui::Slider::EventType type);
private:
Label* label;
};
// we don't support linebreak mode
#endif