mirror of https://github.com/axmolengine/axmol.git
add test case for new API of Label.
This commit is contained in:
parent
b2d8e4fc93
commit
9351172baf
|
@ -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;
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue