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);
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget