2013-09-16 20:54:13 +08:00
|
|
|
#include "UIScrollViewTest.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UIScrollViewTests::UIScrollViewTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(UIScrollViewTest_Vertical);
|
|
|
|
ADD_TEST_CASE(UIScrollViewTest_Horizontal);
|
|
|
|
ADD_TEST_CASE(UIScrollViewTest_Both);
|
|
|
|
ADD_TEST_CASE(UIScrollViewTest_ScrollToPercentBothDirection);
|
|
|
|
ADD_TEST_CASE(UIScrollViewTest_ScrollToPercentBothDirection_Bounce);
|
|
|
|
ADD_TEST_CASE(UIScrollViewNestTest);
|
|
|
|
ADD_TEST_CASE(UIScrollViewRotated);
|
2015-08-06 22:50:53 +08:00
|
|
|
ADD_TEST_CASE(UIScrollViewDisableTest);
|
2015-04-03 14:31:03 +08:00
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
// UIScrollViewTest_Vertical
|
|
|
|
|
|
|
|
UIScrollViewTest_Vertical::UIScrollViewTest_Vertical()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewTest_Vertical::~UIScrollViewTest_Vertical()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewTest_Vertical::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add a label in which the scrollview alert will be displayed
|
2014-04-03 15:22:23 +08:00
|
|
|
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-04-03 15:22:23 +08:00
|
|
|
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:22:23 +08:00
|
|
|
Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
|
|
|
|
|
|
|
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the scrollview by vertical
|
2014-02-24 18:56:45 +08:00
|
|
|
ui::ScrollView* scrollView = ui::ScrollView::create();
|
2014-10-17 11:31:00 +08:00
|
|
|
scrollView->setContentSize(Size(280.0f, 100.0f));
|
2013-09-16 20:54:13 +08:00
|
|
|
Size backgroundSize = background->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
2013-12-23 15:35:35 +08:00
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
|
2015-07-03 20:32:29 +08:00
|
|
|
scrollView->setScrollBarWidth(4);
|
2015-07-03 23:11:01 +08:00
|
|
|
scrollView->setScrollBarPositionFromCorner(Vec2(2, 2));
|
2015-07-03 20:32:29 +08:00
|
|
|
scrollView->setScrollBarColor(Color3B::WHITE);
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(scrollView);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
float innerWidth = scrollView->getContentSize().width;
|
|
|
|
float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
2014-06-20 11:18:53 +08:00
|
|
|
button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
|
2013-09-16 20:54:13 +08:00
|
|
|
scrollView->addChild(button);
|
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
titleButton->setTitleText("Title Button");
|
2014-06-20 11:18:53 +08:00
|
|
|
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
|
2013-12-23 15:35:35 +08:00
|
|
|
scrollView->addChild(titleButton);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
2013-09-16 20:54:13 +08:00
|
|
|
button_scale9->setScale9Enabled(true);
|
2014-06-20 14:03:33 +08:00
|
|
|
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
|
2014-06-20 11:18:53 +08:00
|
|
|
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
|
2013-09-16 20:54:13 +08:00
|
|
|
scrollView->addChild(button_scale9);
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
scrollView->addChild(imageView);
|
2014-10-17 11:31:00 +08:00
|
|
|
|
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UIScrollViewTest_Horizontal
|
|
|
|
|
|
|
|
UIScrollViewTest_Horizontal::UIScrollViewTest_Horizontal()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewTest_Horizontal::~UIScrollViewTest_Horizontal()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewTest_Horizontal::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add a label in which the scrollview alert will be displayed
|
2014-04-03 15:22:23 +08:00
|
|
|
_displayValueLabel = Text::create("Move by horizontal direction","fonts/Marker Felt.ttf",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Text* alert = Text::create("ScrollView horizontal","fonts/Marker Felt.ttf",30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
|
|
|
|
|
|
|
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the scrollview by horizontal
|
2014-02-24 18:56:45 +08:00
|
|
|
ui::ScrollView* scrollView = ui::ScrollView::create();
|
2013-11-06 16:04:06 +08:00
|
|
|
scrollView->setBounceEnabled(true);
|
2014-05-12 11:08:10 +08:00
|
|
|
scrollView->setDirection(ui::ScrollView::Direction::HORIZONTAL);
|
2014-06-20 14:03:33 +08:00
|
|
|
scrollView->setContentSize(Size(280.0f, 150.0f));
|
2014-06-20 11:18:53 +08:00
|
|
|
scrollView->setInnerContainerSize(scrollView->getContentSize());
|
2015-07-03 23:11:01 +08:00
|
|
|
scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
|
2015-07-03 20:32:29 +08:00
|
|
|
scrollView->setScrollBarColor(Color3B::YELLOW);
|
2013-09-16 20:54:13 +08:00
|
|
|
Size backgroundSize = background->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
2013-12-23 15:35:35 +08:00
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(scrollView);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
float innerWidth = scrollView->getContentSize().width + imageView->getContentSize().width;
|
|
|
|
float innerHeight = scrollView->getContentSize().height;
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
2014-06-20 11:18:53 +08:00
|
|
|
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
|
|
|
|
scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
|
2013-09-16 20:54:13 +08:00
|
|
|
scrollView->addChild(button);
|
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
titleButton->setTitleText("Title Button");
|
2014-06-20 11:18:53 +08:00
|
|
|
titleButton->setPosition(Vec2(button->getRightBoundary() + button->getContentSize().width / 2.0f,
|
|
|
|
button->getBottomBoundary() - button->getContentSize().height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
scrollView->addChild(titleButton);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
2013-09-16 20:54:13 +08:00
|
|
|
button_scale9->setScale9Enabled(true);
|
2014-06-20 14:03:33 +08:00
|
|
|
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
|
2014-06-20 11:18:53 +08:00
|
|
|
button_scale9->setPosition(Vec2(titleButton->getRightBoundary() + titleButton->getContentSize().width / 2.0f,
|
|
|
|
titleButton->getBottomBoundary() - titleButton->getContentSize().height / 2.0f));
|
2013-09-16 20:54:13 +08:00
|
|
|
scrollView->addChild(button_scale9);
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
imageView->setPosition(Vec2(innerWidth - imageView->getContentSize().width / 2.0f,
|
|
|
|
button_scale9->getBottomBoundary() - button_scale9->getContentSize().height / 2.0f));
|
2013-09-16 20:54:13 +08:00
|
|
|
scrollView->addChild(imageView);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UIScrollViewTest_Both
|
|
|
|
UIScrollViewTest_Both::UIScrollViewTest_Both()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewTest_Both::~UIScrollViewTest_Both()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewTest_Both::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();;
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
// Add a label in which the dragpanel events will be displayed
|
2014-04-03 15:22:23 +08:00
|
|
|
_displayValueLabel = Text::create("Move by any direction","fonts/Marker Felt.ttf",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:22:23 +08:00
|
|
|
Text* alert = Text::create("ScrollView both","fonts/Marker Felt.ttf",30);
|
2013-12-23 15:35:35 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
|
|
|
|
|
|
|
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
|
|
|
|
|
|
|
|
// Create the dragpanel
|
2014-02-24 18:56:45 +08:00
|
|
|
ui::ScrollView* scrollView = ui::ScrollView::create();
|
2014-05-12 11:08:10 +08:00
|
|
|
scrollView->setDirection(ui::ScrollView::Direction::BOTH);
|
2013-12-23 15:35:35 +08:00
|
|
|
scrollView->setTouchEnabled(true);
|
|
|
|
scrollView->setBounceEnabled(true);
|
|
|
|
scrollView->setBackGroundImageScale9Enabled(true);
|
2014-03-11 17:13:54 +08:00
|
|
|
scrollView->setBackGroundImage("cocosui/green_edit.png");
|
2014-06-20 14:03:33 +08:00
|
|
|
scrollView->setContentSize(Size(210, 122.5));
|
2015-07-03 20:32:29 +08:00
|
|
|
scrollView->setScrollBarWidth(4);
|
2015-07-03 23:11:01 +08:00
|
|
|
scrollView->setScrollBarPositionFromCorner(Vec2(6, 6));
|
2013-12-23 15:35:35 +08:00
|
|
|
Size backgroundSize = background->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
2013-12-23 15:35:35 +08:00
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
|
2014-04-03 15:22:23 +08:00
|
|
|
ImageView* imageView = ImageView::create("Hello.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
scrollView->addChild(imageView);
|
|
|
|
|
|
|
|
scrollView->setInnerContainerSize(imageView->getContentSize());
|
|
|
|
Size innerSize = scrollView->getInnerContainerSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
imageView->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
_uiLayer->addChild(scrollView);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UIScrollViewTest_ScrollToPercentBothDirection
|
|
|
|
UIScrollViewTest_ScrollToPercentBothDirection::UIScrollViewTest_ScrollToPercentBothDirection()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewTest_ScrollToPercentBothDirection::~UIScrollViewTest_ScrollToPercentBothDirection()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewTest_ScrollToPercentBothDirection::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
// Add a label in which the dragpanel events will be displayed
|
2014-04-03 15:22:23 +08:00
|
|
|
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",30);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
2015-07-01 11:41:47 +08:00
|
|
|
Text* alert = Text::create("ScrollView scroll to percent both direction without scroll bar","fonts/Marker Felt.ttf",20);
|
2013-12-23 15:35:35 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
|
|
|
|
|
|
|
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
ui::ScrollView* sc = ui::ScrollView::create();
|
2013-12-23 15:35:35 +08:00
|
|
|
sc->setBackGroundColor(Color3B::GREEN);
|
2014-05-09 17:05:36 +08:00
|
|
|
sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
|
2014-05-12 11:08:10 +08:00
|
|
|
sc->setDirection(ui::ScrollView::Direction::BOTH);
|
2013-12-23 15:35:35 +08:00
|
|
|
sc->setInnerContainerSize(Size(480, 320));
|
2014-06-20 14:03:33 +08:00
|
|
|
sc->setContentSize(Size(100,100));
|
2015-07-03 20:32:29 +08:00
|
|
|
sc->setScrollBarEnabled(false);
|
2013-12-23 15:35:35 +08:00
|
|
|
Size backgroundSize = background->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.width - sc->getContentSize().width) / 2.0f,
|
2013-12-23 15:35:35 +08:00
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.height - sc->getContentSize().height) / 2.0f));
|
2014-05-15 01:07:09 +08:00
|
|
|
sc->scrollToPercentBothDirection(Vec2(50, 50), 1, true);
|
2014-04-03 15:22:23 +08:00
|
|
|
ImageView* iv = ImageView::create("cocosui/Hello.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
iv->setPosition(Vec2(240, 160));
|
2013-12-23 15:35:35 +08:00
|
|
|
sc->addChild(iv);
|
|
|
|
_uiLayer->addChild(sc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UIScrollViewTest_ScrollToPercentBothDirection_Bounce
|
|
|
|
UIScrollViewTest_ScrollToPercentBothDirection_Bounce::UIScrollViewTest_ScrollToPercentBothDirection_Bounce()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewTest_ScrollToPercentBothDirection_Bounce::~UIScrollViewTest_ScrollToPercentBothDirection_Bounce()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
// Add a label in which the dragpanel events will be displayed
|
2014-04-03 15:22:23 +08:00
|
|
|
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
2015-07-01 11:41:47 +08:00
|
|
|
Text* alert = Text::create("ScrollView scroll to percent both direction bounce","fonts/Marker Felt.ttf",20);
|
2013-12-23 15:35:35 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
|
|
|
|
|
|
|
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
ui::ScrollView* sc = ui::ScrollView::create();
|
2013-12-23 15:35:35 +08:00
|
|
|
sc->setBackGroundColor(Color3B::GREEN);
|
2014-05-09 17:05:36 +08:00
|
|
|
sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
|
2013-12-23 15:35:35 +08:00
|
|
|
sc->setBounceEnabled(true);
|
2014-05-12 11:08:10 +08:00
|
|
|
sc->setDirection(ui::ScrollView::Direction::BOTH);
|
2013-12-23 15:35:35 +08:00
|
|
|
sc->setInnerContainerSize(Size(480, 320));
|
2014-06-20 14:03:33 +08:00
|
|
|
sc->setContentSize(Size(100,100));
|
2015-07-03 23:11:01 +08:00
|
|
|
sc->setScrollBarPositionFromCornerForHorizontal(Vec2(5, sc->getContentSize().height - 5));
|
|
|
|
sc->setScrollBarPositionFromCornerForVertical(Vec2(sc->getContentSize().width - 5, 5));
|
2015-07-03 20:32:29 +08:00
|
|
|
sc->setScrollBarAutoHideEnabled(false);
|
2013-12-23 15:35:35 +08:00
|
|
|
Size backgroundSize = background->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.width - sc->getContentSize().width) / 2.0f,
|
2013-12-23 15:35:35 +08:00
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
2014-06-20 11:18:53 +08:00
|
|
|
(backgroundSize.height - sc->getContentSize().height) / 2.0f));
|
2014-05-15 01:07:09 +08:00
|
|
|
sc->scrollToPercentBothDirection(Vec2(50, 50), 1, true);
|
2014-04-03 15:22:23 +08:00
|
|
|
ImageView* iv = ImageView::create("cocosui/Hello.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
iv->setPosition(Vec2(240, 160));
|
2013-12-23 15:35:35 +08:00
|
|
|
sc->addChild(iv);
|
|
|
|
_uiLayer->addChild(sc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-15 16:21:27 +08:00
|
|
|
|
|
|
|
// UIScrollViewNestTest
|
|
|
|
|
|
|
|
UIScrollViewNestTest::UIScrollViewNestTest()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewNestTest::~UIScrollViewNestTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewNestTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the scrollview alert will be displayed
|
|
|
|
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("ScrollView vertical", "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 scrollview by vertical
|
|
|
|
ui::ScrollView* scrollView = ui::ScrollView::create();
|
|
|
|
scrollView->setContentSize(Size(280.0f, 150.0f));
|
2015-07-01 11:41:47 +08:00
|
|
|
scrollView->setDirection(ui::ScrollView::Direction::VERTICAL);
|
2015-07-03 23:11:01 +08:00
|
|
|
scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
|
2014-08-15 16:21:27 +08:00
|
|
|
Size backgroundSize = background->getContentSize();
|
|
|
|
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
|
|
|
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
|
|
|
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
|
2015-07-04 14:40:47 +08:00
|
|
|
scrollView->setScrollBarPositionFromCornerForVertical(Vec2(scrollView->getContentSize().width - 4, 4));
|
|
|
|
scrollView->setScrollBarColor(Color3B::BLUE);
|
2014-08-15 16:21:27 +08:00
|
|
|
_uiLayer->addChild(scrollView);
|
|
|
|
|
|
|
|
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
|
|
|
|
|
|
|
float innerWidth = scrollView->getContentSize().width;
|
|
|
|
float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
|
|
|
|
|
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
|
|
|
|
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
|
|
|
button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
|
|
|
|
scrollView->addChild(button);
|
|
|
|
|
|
|
|
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
|
|
|
titleButton->setTitleText("Title Button");
|
|
|
|
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
|
|
|
|
scrollView->addChild(titleButton);
|
|
|
|
|
|
|
|
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
|
|
|
button_scale9->setScale9Enabled(true);
|
|
|
|
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
|
|
|
|
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
|
|
|
|
scrollView->addChild(button_scale9);
|
|
|
|
|
|
|
|
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
|
|
|
|
scrollView->addChild(imageView);
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-04 14:40:47 +08:00
|
|
|
// Create the scrollview by both
|
2014-08-15 16:21:27 +08:00
|
|
|
ui::ScrollView* sc = ui::ScrollView::create();
|
|
|
|
sc->setBackGroundColor(Color3B::GREEN);
|
|
|
|
sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
|
|
|
|
sc->setBounceEnabled(true);
|
|
|
|
sc->setDirection(ui::ScrollView::Direction::BOTH);
|
|
|
|
sc->setInnerContainerSize(Size(480, 320));
|
|
|
|
sc->setContentSize(Size(100,100));
|
|
|
|
sc->setPropagateTouchEvents(false);
|
|
|
|
sc->setPosition(Vec2(180,100));
|
|
|
|
sc->scrollToPercentBothDirection(Vec2(50, 50), 1, true);
|
2015-07-03 23:11:01 +08:00
|
|
|
sc->setScrollBarPositionFromCorner(Vec2(4, 4));
|
2014-08-15 16:21:27 +08:00
|
|
|
ImageView* iv = ImageView::create("cocosui/Hello.png");
|
|
|
|
iv->setPosition(Vec2(240, 160));
|
|
|
|
sc->addChild(iv);
|
|
|
|
|
|
|
|
|
|
|
|
scrollView->addChild(sc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-03 23:11:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-17 14:02:49 +08:00
|
|
|
// UIScrollViewRotated
|
|
|
|
|
|
|
|
UIScrollViewRotated::UIScrollViewRotated()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewRotated::~UIScrollViewRotated()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewRotated::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the scrollview alert will be displayed
|
|
|
|
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("ScrollView vertical", "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 scrollview by vertical
|
|
|
|
ui::ScrollView* scrollView = ui::ScrollView::create();
|
|
|
|
scrollView->setContentSize(Size(280.0f, 150.0f));
|
2015-07-01 11:41:47 +08:00
|
|
|
scrollView->setDirection(ui::ScrollView::Direction::VERTICAL);
|
2014-10-17 14:02:49 +08:00
|
|
|
Size backgroundSize = background->getContentSize();
|
|
|
|
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
|
|
|
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
|
|
|
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f + 100) );
|
|
|
|
scrollView->setRotation(45);
|
2015-07-03 23:11:01 +08:00
|
|
|
scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
|
2015-07-03 21:17:54 +08:00
|
|
|
scrollView->setScrollBarColor(Color3B::WHITE);
|
2014-10-17 14:02:49 +08:00
|
|
|
_uiLayer->addChild(scrollView);
|
|
|
|
|
|
|
|
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
|
|
|
|
|
|
|
float innerWidth = scrollView->getContentSize().width;
|
|
|
|
float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
|
|
|
|
|
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
|
|
|
|
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
|
|
|
button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
|
|
|
|
scrollView->addChild(button);
|
|
|
|
|
|
|
|
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
|
|
|
titleButton->setTitleText("Title Button");
|
|
|
|
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
|
|
|
|
scrollView->addChild(titleButton);
|
|
|
|
|
|
|
|
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
|
|
|
button_scale9->setScale9Enabled(true);
|
|
|
|
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
|
|
|
|
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
|
|
|
|
scrollView->addChild(button_scale9);
|
|
|
|
|
|
|
|
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
|
|
|
|
scrollView->addChild(imageView);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-08-06 22:50:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UIScrollViewDisableTest
|
|
|
|
|
|
|
|
UIScrollViewDisableTest::UIScrollViewDisableTest()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UIScrollViewDisableTest::~UIScrollViewDisableTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIScrollViewDisableTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the scrollview alert will be displayed
|
|
|
|
_displayValueLabel = Text::create("ScrollView Disable Test", "fonts/Marker Felt.ttf", 32);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("ScrollView vertical", "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 scrollview by vertical
|
|
|
|
ui::ScrollView* scrollView = ui::ScrollView::create();
|
|
|
|
scrollView->setContentSize(Size(280.0f, 100.0f));
|
|
|
|
Size backgroundSize = background->getContentSize();
|
|
|
|
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
|
|
|
|
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
|
|
|
|
(widgetSize.height - backgroundSize.height) / 2.0f +
|
|
|
|
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
|
|
|
|
scrollView->setScrollBarWidth(4);
|
|
|
|
scrollView->setTouchEnabled(false);
|
|
|
|
scrollView->setScrollBarPositionFromCorner(Vec2(2, 2));
|
|
|
|
scrollView->setScrollBarColor(Color3B::WHITE);
|
|
|
|
_uiLayer->addChild(scrollView);
|
|
|
|
|
|
|
|
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
|
|
|
|
|
|
|
float innerWidth = scrollView->getContentSize().width;
|
|
|
|
float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
|
|
|
|
|
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
|
|
|
|
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
|
|
|
button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
|
|
|
|
scrollView->addChild(button);
|
|
|
|
|
|
|
|
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
|
|
|
titleButton->setTitleText("Title Button");
|
|
|
|
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
|
|
|
|
scrollView->addChild(titleButton);
|
|
|
|
|
|
|
|
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
|
|
|
button_scale9->setScale9Enabled(true);
|
|
|
|
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
|
|
|
|
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
|
|
|
|
scrollView->addChild(button_scale9);
|
|
|
|
|
|
|
|
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
|
|
|
|
scrollView->addChild(imageView);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|