mirror of https://github.com/axmolengine/axmol.git
add UIText bug fix tests
This commit is contained in:
parent
a2883aa097
commit
e118b085b8
|
@ -149,6 +149,13 @@ public:
|
|||
*/
|
||||
virtual std::string getDescription() const override;
|
||||
|
||||
/**
|
||||
* Set the rendering size of the text, you should call this method
|
||||
* along with calling `ignoreContentAdaptWithSize(false)`, otherwise the text area
|
||||
* size is caculated by the real size of the text content
|
||||
* @param size The text rendering area size
|
||||
*
|
||||
*/
|
||||
void setTextAreaSize(const Size &size);
|
||||
|
||||
const Size& getTextAreaSize()const;
|
||||
|
|
|
@ -163,7 +163,7 @@ g_guisTests[] =
|
|||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||
sceneManager->setCurrentUISceneId(kUITextTest);
|
||||
sceneManager->setMinUISceneId(kUITextTest);
|
||||
sceneManager->setMaxUISceneId(kUITextTest_TTF);
|
||||
sceneManager->setMaxUISceneId(kUITextTest_IgnoreConentSize);
|
||||
Scene* scene = sceneManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ static const char* s_testArray[] =
|
|||
"UITextTest_LineWrap",
|
||||
"UILabelTest_Effect",
|
||||
"UITextTest_TTF",
|
||||
"UITextTest_IgnoreConentSize",
|
||||
"UITextBMFontTest",
|
||||
|
||||
"UITextFieldTest",
|
||||
|
@ -272,7 +273,8 @@ Scene *UISceneManager::currentUIScene()
|
|||
|
||||
case kUITextTest_TTF:
|
||||
return UITextTest_TTF::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
|
||||
case kUITextTest_IgnoreConentSize:
|
||||
return UITextTest_IgnoreConentSize::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
case kUITextFieldTest:
|
||||
return UITextFieldTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
|
||||
|
|
|
@ -60,9 +60,10 @@ enum
|
|||
kUITextAtlasTest,
|
||||
kUITextTest,
|
||||
kUITextTest_LineWrap,
|
||||
|
||||
kUILabelTest_Effect,
|
||||
kUITextTest_TTF,
|
||||
kUITextTest_IgnoreConentSize,
|
||||
|
||||
kUITextBMFontTest,
|
||||
kUITextFieldTest,
|
||||
kUITextFieldTest_MaxLength,
|
||||
|
|
|
@ -141,6 +141,53 @@ bool UITextTest_TTF::init()
|
|||
text->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getContentSize().height / 4.0f));
|
||||
_uiLayer->addChild(text);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// UITextTest_IgnoreConentSize
|
||||
|
||||
bool UITextTest_IgnoreConentSize::init()
|
||||
{
|
||||
if (UIScene::init())
|
||||
{
|
||||
Size widgetSize = _widget->getContentSize();
|
||||
|
||||
Text* leftText = Text::create("ignore conent",
|
||||
"fonts/Marker Felt.ttf",10);
|
||||
leftText->setPosition(Vec2(widgetSize.width / 2.0f - 50,
|
||||
widgetSize.height / 2.0f));
|
||||
leftText->ignoreContentAdaptWithSize(false);
|
||||
leftText->setTextAreaSize(Size(60,60));
|
||||
leftText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n");
|
||||
leftText->setTouchScaleChangeEnabled(true);
|
||||
leftText->setTouchEnabled(true);
|
||||
_uiLayer->addChild(leftText);
|
||||
|
||||
|
||||
Text* rightText = Text::create("ignore conent",
|
||||
"fonts/Marker Felt.ttf",10);
|
||||
rightText->setPosition(Vec2(widgetSize.width / 2.0f + 50,
|
||||
widgetSize.height / 2.0f));
|
||||
rightText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n");
|
||||
//note: setTextAreaSize must be used with ignoreContentAdaptWithSize(false)
|
||||
rightText->setTextAreaSize(Size(100,30));
|
||||
rightText->ignoreContentAdaptWithSize(false);
|
||||
_uiLayer->addChild(rightText);
|
||||
|
||||
|
||||
auto halighButton = Button::create();
|
||||
halighButton->setTitleText("Alignment Right");
|
||||
halighButton->addClickEventListener([=](Ref*){
|
||||
leftText->setTextHorizontalAlignment(TextHAlignment::RIGHT);
|
||||
rightText->setTextHorizontalAlignment(TextHAlignment::RIGHT);
|
||||
});
|
||||
halighButton->setPosition(Vec2(widgetSize.width/2 - 50,
|
||||
widgetSize.height/2 - 50));
|
||||
_uiLayer->addChild(halighButton);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -65,4 +65,12 @@ protected:
|
|||
UI_SCENE_CREATE_FUNC(UITextTest_TTF)
|
||||
};
|
||||
|
||||
class UITextTest_IgnoreConentSize : public UIScene
|
||||
{
|
||||
public:
|
||||
bool init();
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UITextTest_IgnoreConentSize)
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__UITextTest__) */
|
||||
|
|
Loading…
Reference in New Issue