Skip to content

Commit 792579e

Browse files
committed
add test for UILayout for Scaled Widget
1 parent 822a2fb commit 792579e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ UILayoutTests::UILayoutTests()
1414
ADD_TEST_CASE(UILayoutTest_Layout_Linear_Horizontal);
1515
ADD_TEST_CASE(UILayoutTest_Layout_Relative_Align_Parent);
1616
ADD_TEST_CASE(UILayoutTest_Layout_Relative_Location);
17+
ADD_TEST_CASE(UILayoutTest_Layout_Scaled_Widget);
1718
ADD_TEST_CASE(UILayoutComponentTest);
1819
ADD_TEST_CASE(UILayoutComponent_Berth_Test);
1920
ADD_TEST_CASE(UILayoutComponent_Berth_Stretch_Test);
@@ -726,6 +727,62 @@ bool UILayoutTest_Layout_Relative_Location::init()
726727
return false;
727728
}
728729

730+
// UILayoutTest_Layout_Relative_Location
731+
732+
UILayoutTest_Layout_Scaled_Widget::UILayoutTest_Layout_Scaled_Widget()
733+
{
734+
}
735+
736+
UILayoutTest_Layout_Scaled_Widget::~UILayoutTest_Layout_Scaled_Widget()
737+
{
738+
}
739+
740+
bool UILayoutTest_Layout_Scaled_Widget::init()
741+
{
742+
if (UIScene::init())
743+
{
744+
Size widgetSize = _widget->getContentSize();
745+
746+
// Add the alert
747+
Text* alert = Text::create("Layout Scaled Widget", "fonts/Marker Felt.ttf", 20);
748+
alert->setColor(Color3B(159, 168, 176));
749+
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
750+
_uiLayer->addChild(alert);
751+
752+
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
753+
754+
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
755+
756+
// Create the layout
757+
Layout* layout = Layout::create();
758+
layout->setLayoutType(Layout::Type::HORIZONTAL);
759+
layout->setContentSize(Size(280, 150));
760+
Size backgroundSize = background->getContentSize();
761+
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
762+
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
763+
(widgetSize.height - backgroundSize.height) / 2.0f +
764+
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
765+
_uiLayer->addChild(layout);
766+
767+
ImageView* imageView_Center1 = ImageView::create("cocosui/scrollviewbg.png");
768+
imageView_Center1->setScale(0.5);
769+
layout->addChild(imageView_Center1);
770+
771+
ImageView* imageView_Center2 = ImageView::create("cocosui/scrollviewbg.png");
772+
imageView_Center2->setScale(1.2);
773+
layout->addChild(imageView_Center2);
774+
775+
ImageView* imageView_Center3 = ImageView::create("cocosui/scrollviewbg.png");
776+
imageView_Center3->setScale(0.8);
777+
layout->addChild(imageView_Center3);
778+
779+
return true;
780+
}
781+
782+
return false;
783+
}
784+
785+
729786
bool UILayoutComponentTest::init()
730787
{
731788
if (UIScene::init())

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h

+10
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ class UILayoutTest_Layout_Relative_Location : public UIScene
123123
CREATE_FUNC(UILayoutTest_Layout_Relative_Location);
124124
};
125125

126+
class UILayoutTest_Layout_Scaled_Widget : public UIScene
127+
{
128+
public:
129+
UILayoutTest_Layout_Scaled_Widget();
130+
~UILayoutTest_Layout_Scaled_Widget();
131+
virtual bool init() override;
132+
133+
CREATE_FUNC(UILayoutTest_Layout_Scaled_Widget);
134+
};
135+
126136
class UILayoutComponentTest : public UIScene
127137
{
128138
public:

0 commit comments

Comments
 (0)