Skip to content

[cpp-tests] improve items location of part cases #19210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/cpp-tests/Classes/BaseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void TestList::runThisTest()
auto autoTestItem = MenuItemLabel::create(autoTestLabel, [&](Ref* sender){
TestController::getInstance()->startAutoTest();
});
autoTestItem->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + 50));
autoTestItem->setPosition(Vec2(VisibleRect::right().x - 60, VisibleRect::bottom().y + 50));

auto menu = Menu::create(closeItem, autoTestItem, nullptr);
menu->setPosition(Vec2::ZERO);
Expand Down Expand Up @@ -487,4 +487,4 @@ void TestCase::onBackCallback(Ref* sender)
{
_testSuite->backsUpOneLevel();
}
}
}
16 changes: 8 additions & 8 deletions tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ bool LabelFNTMultiLineAlignment::init()
this->_arrowsBar = Sprite::create("Images/arrowsBar.png");
this->_arrows = Sprite::create("Images/arrows.png");

MenuItemFont::setFontSize(20);
MenuItemFont::setFontSize(15);
auto longSentences = MenuItemFont::create("Long Flowing Sentences", CC_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
auto lineBreaks = MenuItemFont::create("Short Sentences With Intentional Line Breaks", CC_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
auto mixed = MenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks", CC_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
Expand All @@ -620,7 +620,7 @@ bool LabelFNTMultiLineAlignment::init()
_menuItems.push_back(lineBreaks);
_menuItems.push_back(mixed);

MenuItemFont::setFontSize(30);
MenuItemFont::setFontSize(20);

auto left = MenuItemFont::create("Left", CC_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
auto center = MenuItemFont::create("Center", CC_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
Expand All @@ -642,8 +642,8 @@ bool LabelFNTMultiLineAlignment::init()
this->_arrowsBar->setScaleX(arrowsWidth / this->_arrowsBar->getContentSize().width);
this->_arrowsBar->setPosition(Vec2(((ArrowsMax + ArrowsMin) / 2) * size.width, this->_label->getPosition().y));

stringMenu->setPosition(Vec2(size.width/2, size.height - menuItemPaddingCenter));
alignmentMenu->setPosition(Vec2(size.width/2, menuItemPaddingCenter+15));
stringMenu->setPosition(VisibleRect::top() + Vec2(0, - menuItemPaddingCenter));
alignmentMenu->setPosition(VisibleRect::bottom() + Vec2(0, menuItemPaddingCenter + 15));

this->selectSentenceItem(longSentences);
this->selectAlignmentItem(center);
Expand Down Expand Up @@ -1062,12 +1062,12 @@ LabelTTFCJKWrappingTest::LabelTTFCJKWrappingTest()
Vec2(size.width * 0.85, size.height * 0.8),
Vec2(size.width * 0.85, 0), 1, Color4F(1, 0, 0, 1));

TTFConfig ttfConfig("fonts/HKYuanMini.ttf", 25, GlyphCollection::DYNAMIC);
TTFConfig ttfConfig("fonts/HKYuanMini.ttf", 20, GlyphCollection::DYNAMIC);
auto label1 = Label::createWithTTF(ttfConfig,
"你好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75);
if(label1) {
label1->setTextColor(Color4B(128, 255, 255, 255));
label1->setPosition(Vec2(size.width * 0.1, size.height * 0.6));
label1->setPosition(Vec2(size.width * 0.1, VisibleRect::top().y * 0.7));
label1->setAnchorPoint(Vec2(0, 0.5));
this->addChild(label1);
// Demo for unloadFontAtlasTTF function, after it been called, all UI widget
Expand All @@ -1080,7 +1080,7 @@ LabelTTFCJKWrappingTest::LabelTTFCJKWrappingTest()
"早上好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75);
if(label2) {
label2->setTextColor(Color4B(255, 128, 255, 255));
label2->setPosition(Vec2(size.width * 0.1, size.height * 0.4));
label2->setPosition(Vec2(size.width * 0.1, VisibleRect::top().y * 0.5));
label2->setAnchorPoint(Vec2(0, 0.5));
this->addChild(label2);
}
Expand All @@ -1089,7 +1089,7 @@ LabelTTFCJKWrappingTest::LabelTTFCJKWrappingTest()
"美好的一天啊美好的一天啊美好的一天啊", TextHAlignment::LEFT, size.width * 0.75);
if(label3) {
label3->setTextColor(Color4B(255, 255, 128, 255));
label3->setPosition(Vec2(size.width * 0.1, size.height * 0.2));
label3->setPosition(Vec2(size.width * 0.1, VisibleRect::top().y * 0.3));
label3->setAnchorPoint(Vec2(0, 0.5));
this->addChild(label3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void RemoveListenerWhenDispatching::onEnter()
}
}, MenuItemFont::create("Enabled"), MenuItemFont::create("Disabled"), nullptr);

toggleItem->setPosition(origin + Vec2(size.width/2, 80));
toggleItem->setPosition(origin + Vec2(size.width * 0.8, 80));
auto menu = Menu::create(toggleItem, nullptr);
menu->setPosition(Vec2(0, 0));
menu->setAnchorPoint(Vec2(0, 0));
Expand Down Expand Up @@ -650,7 +650,7 @@ void RemoveListenerAfterAddingTest::onEnter()
_eventDispatcher->removeEventListener(listener);
});

item1->setPosition(VisibleRect::center() + Vec2(0, 80));
item1->setPosition(VisibleRect::leftBottom() + Vec2(0, 80));

auto addNextButton = [this](){
auto next = MenuItemFont::create("Please Click Me To Reset!", [this](Ref* sender){
Expand All @@ -677,7 +677,7 @@ void RemoveListenerAfterAddingTest::onEnter()
addNextButton();
});

item2->setPosition(VisibleRect::center() + Vec2(0, 40));
item2->setPosition(VisibleRect::leftBottom() + Vec2(0, 40));

auto item3 = MenuItemFont::create("Click Me 3", [=](Ref* sender){
auto listener = EventListenerTouchOneByOne::create();
Expand All @@ -692,10 +692,10 @@ void RemoveListenerAfterAddingTest::onEnter()
addNextButton();
});

item3->setPosition(VisibleRect::center());
item3->setPosition(VisibleRect::leftBottom());

auto menu = Menu::create(item1, item2, item3, nullptr);
menu->setPosition(VisibleRect::leftBottom());
menu->setPosition(VisibleRect::rightBottom() * 0.8 + Vec2(0, 40));
menu->setAnchorPoint(Vec2::ZERO);

addChild(menu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,21 @@ bool UIFocusTestBase::init()

_dpadMenu = Menu::create();

auto winSize = Director::getInstance()->getVisibleSize();
auto leftItem = MenuItemFont::create("Left", CC_CALLBACK_0(UIFocusTestBase::onLeftKeyPressed, this));
leftItem->setPosition(Vec2(winSize.width - 100, winSize.height/2));
leftItem->setPosition(VisibleRect::right() + Vec2(-100, 0));
_dpadMenu->addChild(leftItem);


auto rightItem = MenuItemFont::create("Right", CC_CALLBACK_0(UIFocusTestBase::onRightKeyPressed, this));
rightItem->setPosition(Vec2(winSize.width - 30, winSize.height/2));
rightItem->setPosition(VisibleRect::right() + Vec2(-30, 0));
_dpadMenu->addChild(rightItem);

auto upItem = MenuItemFont::create("Up", CC_CALLBACK_0(UIFocusTestBase::onUpKeyPressed, this));
upItem->setPosition(Vec2(winSize.width - 60, winSize.height/2 + 50));
upItem->setPosition(VisibleRect::right() + Vec2(-60, 50));
_dpadMenu->addChild(upItem);

auto downItem = MenuItemFont::create("Down", CC_CALLBACK_0(UIFocusTestBase::onDownKeyPressed, this));
downItem->setPosition(Vec2(winSize.width - 60, winSize.height/2 - 50));
downItem->setPosition(VisibleRect::right() + Vec2(-60, -50));
_dpadMenu->addChild(downItem);

_dpadMenu->setPosition(Vec2::ZERO);
Expand All @@ -95,7 +94,7 @@ bool UIFocusTestBase::init()

_toggleButton = Button::create("cocosui/switch-mask.png");
_toggleButton->setTitleText("Toggle Loop");
_toggleButton->setPosition(Vec2(60, winSize.height - 50));
_toggleButton->setPosition(VisibleRect::leftTop() + Vec2(60, -50));
_toggleButton->setTitleColor(Color3B::RED);
_toggleButton->setFocusEnabled(false);
this->addChild(_toggleButton);
Expand Down Expand Up @@ -181,10 +180,8 @@ bool UIFocusTestHorizontal::init()
{
if (UIFocusTestBase::init()) {

Size winSize = Director::getInstance()->getVisibleSize();

_horizontalLayout = HBox::create();
_horizontalLayout->setPosition(Vec2(20, winSize.height/2 + 40));
_horizontalLayout->setPosition(VisibleRect::left() + Vec2(20, 40));
_uiLayer->addChild(_horizontalLayout);

_horizontalLayout->setFocused(true);
Expand All @@ -202,7 +199,7 @@ bool UIFocusTestHorizontal::init()
}

_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
_loopText->setPosition(VisibleRect::top() + Vec2(0, -50));
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);

Expand Down Expand Up @@ -244,10 +241,8 @@ bool UIFocusTestVertical::init()
{
if (UIFocusTestBase::init()) {

Size winSize = Director::getInstance()->getVisibleSize();

_verticalLayout = VBox::create();
_verticalLayout->setPosition(Vec2(winSize.width/2 - 100, winSize.height - 70));
_verticalLayout->setPosition(VisibleRect::top() + Vec2(-100, -70));
_uiLayer->addChild(_verticalLayout);
_verticalLayout->setTag(100);
_verticalLayout->setScale(0.5);
Expand All @@ -266,7 +261,7 @@ bool UIFocusTestVertical::init()
}

_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
_loopText->setPosition(VisibleRect::top() + Vec2(0, -50));
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);

Expand Down Expand Up @@ -305,10 +300,8 @@ bool UIFocusTestNestedLayout1::init()
{
if (UIFocusTestBase::init()) {

Size winSize = Director::getInstance()->getVisibleSize();

_verticalLayout = VBox::create();
_verticalLayout->setPosition(Vec2(winSize.width/2 - 80, winSize.height - 70));
_verticalLayout->setPosition(VisibleRect::top() + Vec2(-80, -70));
_uiLayer->addChild(_verticalLayout);
_verticalLayout->setScale(0.5);

Expand Down Expand Up @@ -362,7 +355,7 @@ bool UIFocusTestNestedLayout1::init()
}

_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
_loopText->setPosition(VisibleRect::top() + Vec2(0, -50));
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);

Expand Down Expand Up @@ -401,10 +394,8 @@ bool UIFocusTestNestedLayout2::init()
{
if (UIFocusTestBase::init()) {

Size winSize = Director::getInstance()->getVisibleSize();

_horizontalLayout = HBox::create();
_horizontalLayout->setPosition(Vec2(winSize.width/2 - 200, winSize.height - 70));
_horizontalLayout->setPosition(VisibleRect::top() + Vec2(-200, -70));
_uiLayer->addChild(_horizontalLayout);
_horizontalLayout->setScale(0.6f);

Expand Down Expand Up @@ -458,7 +449,7 @@ bool UIFocusTestNestedLayout2::init()
}

_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
_loopText->setPosition(VisibleRect::top() + Vec2(0, -50));
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);

Expand Down Expand Up @@ -497,10 +488,9 @@ bool UIFocusTestNestedLayout3::init()
{
if (UIFocusTestBase::init()) {

Size winSize = Director::getInstance()->getVisibleSize();

_verticalLayout = VBox::create();
_verticalLayout->setPosition(Vec2(40, winSize.height - 70));
_verticalLayout->setPosition(VisibleRect::leftTop() + Vec2(40, -70));

_uiLayer->addChild(_verticalLayout);
_verticalLayout->setScale(0.8f);

Expand Down Expand Up @@ -562,7 +552,7 @@ bool UIFocusTestNestedLayout3::init()


_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
_loopText->setPosition(VisibleRect::top() + Vec2(0, -50));
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ WebViewTests::WebViewTests()
bool WebViewTest::init()
{
if (UIScene::init()) {
Size winSize = Director::getInstance()->getVisibleSize();
Size visableSize = Director::getInstance()->getVisibleSize();


_webView = cocos2d::experimental::ui::WebView::create();
_webView->setPosition(winSize/2);
_webView->setContentSize(winSize * 0.5);
_webView->setPosition(VisibleRect::center());
_webView->setContentSize(visableSize * 0.5);
_webView->loadURL("https://www.baidu.com");
_webView->setScalesPageToFit(true);

Expand All @@ -52,13 +51,14 @@ bool WebViewTest::init()
this->addChild(_webView);

auto spriteHello = Sprite::create("Hello.png");
spriteHello->setPosition(winSize/2);
spriteHello->setContentSize(visableSize * 0.5);
spriteHello->setPosition(VisibleRect::center());
this->addChild(spriteHello);

TextField *urlTextField = TextField::create("Input a URL here", "Arial", 20);
urlTextField->setPlaceHolderColor(Color3B::RED);
urlTextField->setPosition(Vec2(winSize/2) + Vec2(-80, _webView->getContentSize().height/2 +
urlTextField->getContentSize().height/2 + 10));
urlTextField->setPosition(VisibleRect::center() + Vec2(-80, _webView->getContentSize().height/2 +
urlTextField->getContentSize().height/2 + 10));
this->addChild(urlTextField);

Text *httpLabel = Text::create("https:// ", "Arial", 20);
Expand All @@ -71,8 +71,8 @@ bool WebViewTest::init()
Button *resetBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
resetBtn->setTitleText("Visit URL");
resetBtn->setPosition(Vec2(winSize/2) + Vec2(50, _webView->getContentSize().height/2 +
resetBtn->getContentSize().height/2 + 10));
resetBtn->setPosition(VisibleRect::center() + Vec2(50, _webView->getContentSize().height/2 +
resetBtn->getContentSize().height/2 + 10));
resetBtn->addClickEventListener([=](Ref*){
if (urlTextField->getString().size() != 0)
{
Expand All @@ -85,7 +85,7 @@ bool WebViewTest::init()
Button *reloadBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
reloadBtn->setTitleText("Reload");
reloadBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
reloadBtn->setPosition(VisibleRect::center() + Vec2( _webView->getContentSize().width/2 +
reloadBtn->getContentSize().width/2 + 10,50 ));
reloadBtn->addClickEventListener([=](Ref*){
_webView->reload();
Expand All @@ -95,7 +95,7 @@ bool WebViewTest::init()
Button *forwardBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
forwardBtn->setTitleText("Forward");
forwardBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
forwardBtn->setPosition(VisibleRect::center() + Vec2( _webView->getContentSize().width/2 +
forwardBtn->getContentSize().width/2 + 10,0 ));
forwardBtn->addClickEventListener([=](Ref*){
_webView->goForward();
Expand All @@ -107,7 +107,7 @@ bool WebViewTest::init()
Button *backBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
backBtn->setTitleText("Back");
backBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
backBtn->setPosition(VisibleRect::center() + Vec2( _webView->getContentSize().width/2 +
backBtn->getContentSize().width/2 + 10,-50 ));
backBtn->addClickEventListener([=](Ref*){
_webView->goBack();
Expand All @@ -118,7 +118,7 @@ bool WebViewTest::init()
Button *loadFileBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
loadFileBtn->setTitleText("Load FILE");
loadFileBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
loadFileBtn->setPosition(VisibleRect::center() - Vec2( _webView->getContentSize().width/2 +
loadFileBtn->getContentSize().width/2 + 10,50 ));
loadFileBtn->addClickEventListener([=](Ref*){
_webView->loadFile("Test.html");
Expand All @@ -128,7 +128,7 @@ bool WebViewTest::init()
Button *loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
loadHTMLBtn->setTitleText("Load Data");
loadHTMLBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
loadHTMLBtn->setPosition(VisibleRect::center() - Vec2( _webView->getContentSize().width/2 +
loadHTMLBtn->getContentSize().width/2 + 10,0 ));
loadHTMLBtn->addClickEventListener([=](Ref*){
_webView->loadHTMLString("<body style=\"font-size:50px;\">Hello World <img src=\"Icon.png\"/> </body>","Images/");
Expand All @@ -141,7 +141,7 @@ bool WebViewTest::init()
Button *evalJsBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
evalJsBtn->setTitleText("Evaluate JS");
evalJsBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
evalJsBtn->setPosition(VisibleRect::center() - Vec2( _webView->getContentSize().width/2 +
evalJsBtn->getContentSize().width/2 + 10,-50 ));
evalJsBtn->addClickEventListener([=](Ref*){
_webView->evaluateJS("alert(\"hello\")");
Expand All @@ -152,7 +152,7 @@ bool WebViewTest::init()
Button *opacityBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
opacityBtn->setTitleText("Opacity 1.f");
opacityBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 +
opacityBtn->setPosition(VisibleRect::center() - Vec2( _webView->getContentSize().width/2 +
opacityBtn->getContentSize().width/2 + 10, 100 ));
opacityBtn->addClickEventListener([=](Ref*){
auto currentOpacity = _webView->getOpacityWebView();
Expand All @@ -175,7 +175,7 @@ bool WebViewTest::init()
Button *transparentBgBtn = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
transparentBgBtn->setTitleText("Transparent BG");
transparentBgBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 +
transparentBgBtn->setPosition(VisibleRect::center() + Vec2( _webView->getContentSize().width/2 +
transparentBgBtn->getContentSize().width/2 + 10,-100 ));
transparentBgBtn->addClickEventListener([=](Ref*){
_webView->setBackgroundTransparent();
Expand Down