28using namespace cocos2d::ui;
30UIScrollViewTests::UIScrollViewTests()
47: _displayValueLabel(nullptr)
59 Size widgetSize =
_widget->getContentSize();
62 _displayValueLabel = Text::create(
"Move by vertical direction",
"fonts/Marker Felt.ttf", 32);
69 Text* alert = Text::create(
"ScrollView vertical",
"fonts/Marker Felt.ttf", 30);
70 alert->setColor(Color3B(159, 168, 176));
71 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
74 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
76 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
79 ui::ScrollView* scrollView = ui::ScrollView::create();
80 scrollView->setContentSize(Size(280.0f, 100.0f));
81 Size backgroundSize = background->getContentSize();
82 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
83 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
84 (widgetSize.height - backgroundSize.height) / 2.0f +
85 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
86 scrollView->setScrollBarWidth(4);
87 scrollView->setScrollBarPositionFromCorner(Vec2(2, 2));
88 scrollView->setScrollBarColor(Color3B::WHITE);
89 scrollView->setGlobalZOrder(200);
92 ImageView* imageView = ImageView::create(
"cocosui/ccicon.png");
94 float innerWidth = scrollView->getContentSize().width;
95 float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
97 scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
99 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
100 button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
101 scrollView->addChild(button);
103 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
104 titleButton->setTitleText(
"Title Button");
105 titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
106 scrollView->addChild(titleButton);
108 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
109 button_scale9->setScale9Enabled(
true);
110 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
111 button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
112 scrollView->addChild(button_scale9);
114 imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
115 scrollView->addChild(imageView);
116 scrollView->scrollToBottom(2.0,
true);
126: _displayValueLabel(nullptr)
138 Size widgetSize =
_widget->getContentSize();
141 _displayValueLabel = Text::create(
"Move by horizontal direction",
"fonts/Marker Felt.ttf",32);
146 Text* alert = Text::create(
"ScrollView horizontal",
"fonts/Marker Felt.ttf",30);
147 alert->setColor(Color3B(159, 168, 176));
148 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
151 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
153 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
156 ui::ScrollView* scrollView = ui::ScrollView::create();
157 scrollView->setBounceEnabled(
true);
158 scrollView->setDirection(ui::ScrollView::Direction::HORIZONTAL);
159 scrollView->setContentSize(Size(280.0f, 150.0f));
160 scrollView->setInnerContainerSize(scrollView->getContentSize());
161 scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
162 scrollView->setScrollBarColor(Color3B::YELLOW);
163 Size backgroundSize = background->getContentSize();
164 scrollView->setPosition((widgetSize - scrollView->getContentSize()) / 2.0f);
167 ImageView* imageView = ImageView::create(
"cocosui/ccicon.png");
169 float innerWidth = scrollView->getContentSize().width + imageView->getContentSize().width;
170 float innerHeight = scrollView->getContentSize().height;
172 scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
174 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
175 button->setPosition(Vec2(button->getContentSize().width / 2.0f,
176 scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
177 scrollView->addChild(button);
179 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
180 titleButton->setTitleText(
"Title Button");
181 titleButton->setPosition(Vec2(button->getRightBoundary() + button->getContentSize().width / 2.0f,
182 button->getBottomBoundary() - button->getContentSize().height / 2.0f));
183 scrollView->addChild(titleButton);
185 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
186 button_scale9->setScale9Enabled(
true);
187 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
188 button_scale9->setPosition(Vec2(titleButton->getRightBoundary() + titleButton->getContentSize().width / 2.0f,
189 titleButton->getBottomBoundary() - titleButton->getContentSize().height / 2.0f));
190 scrollView->addChild(button_scale9);
192 imageView->setPosition(Vec2(innerWidth - imageView->getContentSize().width / 2.0f,
193 button_scale9->getBottomBoundary() - button_scale9->getContentSize().height / 2.0f));
194 scrollView->addChild(imageView);
197 scrollView->jumpToRight();
207: _displayValueLabel(nullptr)
220 Size widgetSize =
_widget->getContentSize();
223 _displayValueLabel = Text::create(
"Move by any direction",
"fonts/Marker Felt.ttf",32);
229 Text* alert = Text::create(
"ScrollView both",
"fonts/Marker Felt.ttf",30);
230 alert->setColor(Color3B(159, 168, 176));
231 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
234 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
236 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
239 ui::ScrollView* scrollView = ui::ScrollView::create();
240 scrollView->setDirection(ui::ScrollView::Direction::BOTH);
241 scrollView->setTouchEnabled(
true);
242 scrollView->setBounceEnabled(
true);
243 scrollView->setBackGroundImageScale9Enabled(
true);
244 scrollView->setBackGroundImage(
"cocosui/green_edit.png");
245 scrollView->setContentSize(Size(210, 122.5));
246 scrollView->setScrollBarWidth(4);
247 scrollView->setScrollBarPositionFromCorner(Vec2(6, 6));
248 Size backgroundSize = background->getContentSize();
249 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
250 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
251 (widgetSize.height - backgroundSize.height) / 2.0f +
252 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
253 ImageView* imageView = ImageView::create(
"Hello.png");
254 scrollView->addChild(imageView);
256 scrollView->setInnerContainerSize(imageView->getContentSize());
257 Size innerSize = scrollView->getInnerContainerSize();
258 imageView->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
263 scrollView->jumpToBottomRight();
273: _displayValueLabel(nullptr)
286 Size widgetSize =
_widget->getContentSize();
295 Text* alert = Text::create(
"ScrollView scroll to percent both direction without scroll bar",
"fonts/Marker Felt.ttf",20);
296 alert->setColor(Color3B(159, 168, 176));
297 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5));
300 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
302 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
304 ui::ScrollView* sc = ui::ScrollView::create();
305 sc->setBackGroundColor(Color3B::GREEN);
306 sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
307 sc->setDirection(ui::ScrollView::Direction::BOTH);
308 sc->setInnerContainerSize(Size(480.0f, 320.0f));
309 sc->setContentSize(Size(100.0f,100.0f));
310 sc->setScrollBarEnabled(
false);
311 Size backgroundSize = background->getContentSize();
312 sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
313 (backgroundSize.width - sc->getContentSize().width) / 2.0f,
314 (widgetSize.height - backgroundSize.height) / 2.0f +
315 (backgroundSize.height - sc->getContentSize().height) / 2.0f));
316 sc->scrollToPercentBothDirection(Vec2(50, 50), 1,
true);
317 ImageView* iv = ImageView::create(
"cocosui/Hello.png");
318 iv->setPosition(Vec2(240.0f, 160.0f));
329: _displayValueLabel(nullptr)
342 Size widgetSize =
_widget->getContentSize();
351 Text* alert = Text::create(
"ScrollView scroll to percent both direction bounce",
"fonts/Marker Felt.ttf",20);
352 alert->setColor(Color3B(159, 168, 176));
353 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5));
356 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
358 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
360 ui::ScrollView* sc = ui::ScrollView::create();
361 sc->setBackGroundColor(Color3B::GREEN);
362 sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
363 sc->setBounceEnabled(
true);
364 sc->setDirection(ui::ScrollView::Direction::BOTH);
365 sc->setInnerContainerSize(Size(480.0f, 320.0f));
366 sc->setContentSize(Size(100.0f,100.0f));
367 sc->setScrollBarPositionFromCornerForHorizontal(Vec2(5.0f, sc->getContentSize().height - 5));
368 sc->setScrollBarPositionFromCornerForVertical(Vec2(sc->getContentSize().width - 5, 5.0f));
369 sc->setScrollBarAutoHideEnabled(
false);
370 Size backgroundSize = background->getContentSize();
371 sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
372 (backgroundSize.width - sc->getContentSize().width) / 2.0f,
373 (widgetSize.height - backgroundSize.height) / 2.0f +
374 (backgroundSize.height - sc->getContentSize().height) / 2.0f));
375 sc->scrollToPercentBothDirection(Vec2(50.0f, 50.0f), 1,
true);
376 ImageView* iv = ImageView::create(
"cocosui/Hello.png");
377 iv->setPosition(Vec2(240.0f, 160.0f));
389: _displayValueLabel(nullptr)
401 Size widgetSize =
_widget->getContentSize();
404 _displayValueLabel = Text::create(
"Move by vertical direction",
"fonts/Marker Felt.ttf", 32);
411 Text* alert = Text::create(
"ScrollView vertical",
"fonts/Marker Felt.ttf", 30);
412 alert->setColor(Color3B(159, 168, 176));
413 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
416 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
418 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
421 ui::ScrollView* scrollView = ui::ScrollView::create();
422 scrollView->setContentSize(Size(280.0f, 150.0f));
423 scrollView->setDirection(ui::ScrollView::Direction::VERTICAL);
424 scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
425 Size backgroundSize = background->getContentSize();
426 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
427 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
428 (widgetSize.height - backgroundSize.height) / 2.0f +
429 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
430 scrollView->setScrollBarPositionFromCornerForVertical(Vec2(scrollView->getContentSize().width - 4, 4.0f));
431 scrollView->setScrollBarColor(Color3B::BLUE);
434 ImageView* imageView = ImageView::create(
"cocosui/ccicon.png");
436 float innerWidth = scrollView->getContentSize().width;
437 float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
439 scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
441 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
442 button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
443 scrollView->addChild(button);
445 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
446 titleButton->setTitleText(
"Title Button");
447 titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
448 scrollView->addChild(titleButton);
450 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
451 button_scale9->setScale9Enabled(
true);
452 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
453 button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
454 scrollView->addChild(button_scale9);
456 imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
457 scrollView->addChild(imageView);
462 ui::ScrollView* sc = ui::ScrollView::create();
463 sc->setBackGroundColor(Color3B::GREEN);
464 sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
465 sc->setBounceEnabled(
true);
466 sc->setDirection(ui::ScrollView::Direction::BOTH);
467 sc->setInnerContainerSize(Size(480.0f, 320.0f));
468 sc->setContentSize(Size(100.0f,100.0f));
469 sc->setPropagateTouchEvents(
false);
470 sc->setPosition(Vec2(180.0f,100.0f));
471 sc->scrollToPercentBothDirection(Vec2(50.0f, 50.0f), 1,
true);
472 sc->setScrollBarPositionFromCorner(Vec2(4.0f, 4.0f));
473 ImageView* iv = ImageView::create(
"cocosui/Hello.png");
474 iv->setPosition(Vec2(240.0f, 160.0f));
478 scrollView->addChild(sc);
492: _displayValueLabel(nullptr)
504 Size widgetSize =
_widget->getContentSize();
507 _displayValueLabel = Text::create(
"Move by vertical direction",
"fonts/Marker Felt.ttf", 32);
514 Text* alert = Text::create(
"ScrollView vertical",
"fonts/Marker Felt.ttf", 30);
515 alert->setColor(Color3B(159, 168, 176));
516 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
519 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
521 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
524 ui::ScrollView* scrollView = ui::ScrollView::create();
525 scrollView->setContentSize(Size(280.0f, 150.0f));
526 scrollView->setDirection(ui::ScrollView::Direction::VERTICAL);
527 Size backgroundSize = background->getContentSize();
528 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
529 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
530 (widgetSize.height - backgroundSize.height) / 2.0f +
531 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f + 100) );
532 scrollView->setRotation(45);
533 scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
534 scrollView->setScrollBarColor(Color3B::WHITE);
537 ImageView* imageView = ImageView::create(
"cocosui/ccicon.png");
539 float innerWidth = scrollView->getContentSize().width;
540 float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
542 scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
544 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
545 button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
546 scrollView->addChild(button);
548 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
549 titleButton->setTitleText(
"Title Button");
550 titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
551 scrollView->addChild(titleButton);
553 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
554 button_scale9->setScale9Enabled(
true);
555 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
556 button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
557 scrollView->addChild(button_scale9);
559 imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
560 scrollView->addChild(imageView);
573: _displayValueLabel(nullptr)
585 Size widgetSize =
_widget->getContentSize();
588 _displayValueLabel = Text::create(
"ScrollView Disable Test",
"fonts/Marker Felt.ttf", 32);
595 Text* alert = Text::create(
"ScrollView vertical",
"fonts/Marker Felt.ttf", 30);
596 alert->setColor(Color3B(159, 168, 176));
597 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
600 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
602 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
605 ui::ScrollView* scrollView = ui::ScrollView::create();
606 scrollView->setContentSize(Size(280.0f, 100.0f));
607 Size backgroundSize = background->getContentSize();
608 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
609 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
610 (widgetSize.height - backgroundSize.height) / 2.0f +
611 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
612 scrollView->setScrollBarWidth(4);
613 scrollView->setTouchEnabled(
false);
614 scrollView->setScrollBarPositionFromCorner(Vec2(2, 2));
615 scrollView->setScrollBarColor(Color3B::WHITE);
618 ImageView* imageView = ImageView::create(
"cocosui/ccicon.png");
620 float innerWidth = scrollView->getContentSize().width;
621 float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
623 scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
625 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
626 button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
627 scrollView->addChild(button);
629 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
630 titleButton->setTitleText(
"Title Button");
631 titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
632 scrollView->addChild(titleButton);
634 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
635 button_scale9->setScale9Enabled(
true);
636 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
637 button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
638 scrollView->addChild(button_scale9);
640 imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
641 scrollView->addChild(imageView);
653 : _displayValueLabel(nullptr)
665 Size widgetSize =
_widget->getContentSize();
668 _displayValueLabel = Text::create(
"ScrollView InnerSize Test",
"fonts/Marker Felt.ttf", 32);
675 Text* alert = Text::create(
"ScrollView & InnerContainer should be align to the left and top point",
"fonts/Marker Felt.ttf", 10);
676 alert->setColor(Color3B(159, 168, 176));
677 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
680 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
682 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
685 ui::ScrollView* scrollView = ui::ScrollView::create();
686 scrollView->setContentSize(Size(200.0f, 50.0f));
687 Size backgroundSize = background->getContentSize();
688 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
689 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
690 (widgetSize.height - backgroundSize.height) / 2.0f +
691 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
692 scrollView->setScrollBarWidth(4);
693 scrollView->setTouchEnabled(
false);
694 scrollView->setScrollBarPositionFromCorner(Vec2(2, 2));
695 scrollView->setScrollBarColor(Color3B::WHITE);
696 scrollView->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
697 scrollView->setBackGroundColor(Color3B(150, 150, 100));
698 scrollView->getInnerContainer()->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
699 scrollView->getInnerContainer()->setBackGroundColor(Color3B(50, 100, 50));
700 scrollView->getInnerContainer()->setBackGroundColorOpacity(100);
701 scrollView->setClippingEnabled(
false);
704 scrollView->setInnerContainerSize(Size(250.f, 100.f));
715 : _displayValueLabel(nullptr)
724 Size widgetSize =
_widget->getContentSize();
733 Text* alert = Text::create(
"ScrollView events",
"fonts/Marker Felt.ttf",30);
734 alert->setColor(Color3B(159, 168, 176));
735 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
738 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
740 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
743 ui::ScrollView* scrollView = ui::ScrollView::create();
744 scrollView->setDirection(ui::ScrollView::Direction::BOTH);
745 scrollView->setTouchEnabled(
true);
746 scrollView->setBounceEnabled(
true);
747 scrollView->setBackGroundImageScale9Enabled(
true);
748 scrollView->setBackGroundImage(
"cocosui/green_edit.png");
749 scrollView->setContentSize(Size(210, 122.5));
750 scrollView->setScrollBarWidth(4);
751 scrollView->setScrollBarPositionFromCorner(Vec2(6, 6));
752 Size backgroundSize = background->getContentSize();
753 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
754 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
755 (widgetSize.height - backgroundSize.height) / 2.0f +
756 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
757 ImageView* imageView = ImageView::create(
"Hello.png");
758 scrollView->addChild(imageView);
760 scrollView->setInnerContainerSize(imageView->getContentSize());
761 Size innerSize = scrollView->getInnerContainerSize();
762 imageView->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
767 scrollView->jumpToBottomRight();
769 auto getRandomColor = [] {
770 return Color4B(random(0, 255), random(0, 255), random(0, 255), 255);
772 scrollView->addEventListener([&](Ref*, ui::ScrollView::EventType e) {
774 case ui::ScrollView::EventType::SCROLLING_BEGAN:
778 case ui::ScrollView::EventType::SCROLLING_ENDED:
795 : _displayValueLabel(nullptr)
796 , _scrollView(nullptr)
797 , _remainingTime(0.0f)
806 Size widgetSize =
_widget->getContentSize();
809 _displayValueLabel = Text::create(
"Scrolling stop isn't scheduled",
"fonts/Marker Felt.ttf", 32);
815 Text* alert = Text::create(
"Click the button and start to scroll",
"fonts/Marker Felt.ttf", 30);
816 alert->setColor(Color3B(159, 168, 176));
817 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
820 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
822 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
826 _scrollView->setDirection(ui::ScrollView::Direction::BOTH);
829 _scrollView->setBackGroundImageScale9Enabled(
true);
830 _scrollView->setBackGroundImage(
"cocosui/green_edit.png");
833 _scrollView->setScrollBarPositionFromCorner(Vec2(6, 6));
834 Size backgroundSize = background->getContentSize();
835 _scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
836 (backgroundSize.width -
_scrollView->getContentSize().width) / 2.0f,
837 (widgetSize.height - backgroundSize.height) / 2.0f +
838 (backgroundSize.height -
_scrollView->getContentSize().height) / 2.0f));
839 ImageView* imageView = ImageView::create(
"Hello.png");
841 _scrollView->setInnerContainerSize(imageView->getContentSize());
842 Size innerSize =
_scrollView->getInnerContainerSize();
843 imageView->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
847 _scrollView->addEventListener([&] (Ref*, ui::ScrollView::EventType e)
851 case ui::ScrollView::EventType::SCROLLING_BEGAN:
852 CCLOG(
"scrolling began!");
854 case ui::ScrollView::EventType::SCROLLING_ENDED:
855 CCLOG(
"scrolling ended!");
857 case ui::ScrollView::EventType::AUTOSCROLL_ENDED:
858 CCLOG(
"auto-scrolling ended!");
868 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
869 button_scale9->setTitleText(
"Stop scrolling in 3 sec.");
870 button_scale9->setScale9Enabled(
true);
871 button_scale9->setContentSize(Size(120.0f, button_scale9->getVirtualRendererSize().height));
872 button_scale9->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
873 button_scale9->addClickEventListener([
this] (Ref*) { this->
_remainingTime = 3.0f; });
877 Director::getInstance()->getScheduler()->scheduleUpdate(
this, 0,
false);
896 char strRemainingTime[100];
897 sprintf(strRemainingTime,
"Stop scrolling in %.1f sec.",
_remainingTime);
905 std::string strRemainingTime =
"Scrolling stop isn't scheduled";
909 auto hintLabel = Label::createWithTTF(
"Stopped!",
"fonts/Marker Felt.ttf", 32.0f);
910 Size contentSize =
_uiLayer->getContentSize();
911 hintLabel->setPosition(Vec2(contentSize.width / 2.0f, contentSize.height / 2.0f));
912 hintLabel->runAction(Spawn::createWithTwoActions(
913 FadeOut::create(0.3f),
914 ScaleTo::create(0.3f, 2.0f)
#define ADD_TEST_CASE(__className__)
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget