mirror of https://github.com/axmolengine/axmol.git
Add test for page view indicator tune
This commit is contained in:
parent
23d074ea34
commit
2246495cc3
|
@ -14,6 +14,7 @@ UIPageViewTests::UIPageViewTests()
|
|||
ADD_TEST_CASE(UIPageViewVerticalTest);
|
||||
ADD_TEST_CASE(UIPageViewDisableTouchTest);
|
||||
ADD_TEST_CASE(UIPageViewChildSizeTest);
|
||||
ADD_TEST_CASE(UIPageViewIndicatorTest);
|
||||
}
|
||||
|
||||
// UIPageViewTest
|
||||
|
@ -962,3 +963,84 @@ void UIPageViewChildSizeTest::pageViewEvent(Ref *pSender, PageView::EventType ty
|
|||
}
|
||||
}
|
||||
|
||||
// UIPageViewIndicatorTest
|
||||
UIPageViewIndicatorTest::UIPageViewIndicatorTest()
|
||||
: _displayValueLabel(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UIPageViewIndicatorTest::~UIPageViewIndicatorTest()
|
||||
{
|
||||
}
|
||||
|
||||
bool UIPageViewIndicatorTest::init()
|
||||
{
|
||||
if (UIScene::init())
|
||||
{
|
||||
Size widgetSize = _widget->getContentSize();
|
||||
|
||||
// Add a label in which the dragpanel events will be displayed
|
||||
_displayValueLabel = Text::create("PageView indidcator custom texture\nscale : 0.5, index color: RED", "fonts/Marker Felt.ttf", 16);
|
||||
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||
widgetSize.height / 2.0f +
|
||||
_displayValueLabel->getContentSize().height));
|
||||
_uiLayer->addChild(_displayValueLabel);
|
||||
|
||||
// Add the black background
|
||||
Text* alert = Text::create("PageView", "fonts/Marker Felt.ttf", 30);
|
||||
alert->setColor(Color3B(159, 168, 176));
|
||||
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
||||
_uiLayer->addChild(alert);
|
||||
|
||||
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
||||
|
||||
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
||||
|
||||
// Create the page view
|
||||
PageView* pageView = PageView::create();
|
||||
pageView->setContentSize(Size(240.0f, 130.0f));
|
||||
Size backgroundSize = background->getContentSize();
|
||||
pageView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
||||
(backgroundSize.width - pageView->getContentSize().width) / 2.0f,
|
||||
(widgetSize.height - backgroundSize.height) / 2.0f +
|
||||
(backgroundSize.height - pageView->getContentSize().height) / 2.0f));
|
||||
pageView->setDirection(ui::PageView::Direction::VERTICAL);
|
||||
pageView->removeAllItems();
|
||||
|
||||
pageView->setIndicatorEnabled(true);
|
||||
pageView->setIndicatorSpaceBetweenIndexNodes(5);
|
||||
pageView->setIndicatorIndexNodesScale(0.5);
|
||||
pageView->setIndicatorIndexNodesTexture("cocosui/green_edit.png");
|
||||
pageView->setIndicatorIndexNodesColor(Color3B::RED);
|
||||
|
||||
int pageCount = 4;
|
||||
for (int i = 0; i < pageCount; ++i)
|
||||
{
|
||||
Layout* layout = Layout::create();
|
||||
layout->setContentSize(Size(240.0f, 130.0f));
|
||||
|
||||
ImageView* imageView = ImageView::create("cocosui/scrollviewbg.png");
|
||||
imageView->setScale9Enabled(true);
|
||||
imageView->setContentSize(Size(240, 130));
|
||||
imageView->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
|
||||
layout->addChild(imageView);
|
||||
|
||||
Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30);
|
||||
label->setColor(Color3B(192, 192, 192));
|
||||
label->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
|
||||
layout->addChild(label);
|
||||
|
||||
pageView->insertCustomItem(layout, i);
|
||||
}
|
||||
|
||||
_uiLayer->addChild(pageView);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -155,4 +155,18 @@ protected:
|
|||
cocos2d::ui::Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
class UIPageViewIndicatorTest : public UIScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(UIPageViewIndicatorTest);
|
||||
|
||||
UIPageViewIndicatorTest();
|
||||
~UIPageViewIndicatorTest();
|
||||
virtual bool init() override;
|
||||
|
||||
protected:
|
||||
|
||||
cocos2d::ui::Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__UIPageViewTest__) */
|
||||
|
|
Loading…
Reference in New Issue