539 Size widgetSize =
_widget->getContentSize();
542 Text* alert = Text::create(
"Layout Relative Align Parent",
"fonts/Marker Felt.ttf", 20);
543 alert->setColor(Color3B(159, 168, 176));
544 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
547 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
549 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
552 Layout* layout = Layout::create();
553 layout->setLayoutType(Layout::Type::RELATIVE);
554 layout->setContentSize(Size(280, 150));
555 layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
556 layout->setBackGroundColor(Color3B::GREEN);
557 Size backgroundSize = background->getContentSize();
558 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
559 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
560 (widgetSize.height - backgroundSize.height) / 2.0f +
561 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
565 Button* button_TopLeft = Button::create(
"cocosui/animationbuttonnormal.png",
566 "cocosui/animationbuttonpressed.png");
567 layout->addChild(button_TopLeft);
569 RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create();
570 rp_TopLeft->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT);
571 button_TopLeft->setLayoutParameter(rp_TopLeft);
575 Button* button_TopCenter = Button::create(
"cocosui/animationbuttonnormal.png",
576 "cocosui/animationbuttonpressed.png");
577 layout->addChild(button_TopCenter);
579 RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create();
580 rp_TopCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);
581 button_TopCenter->setLayoutParameter(rp_TopCenter);
585 Button* button_TopRight = Button::create(
"cocosui/animationbuttonnormal.png",
586 "cocosui/animationbuttonpressed.png");
587 layout->addChild(button_TopRight);
589 RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create();
590 rp_TopRight->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT);
591 button_TopRight->setLayoutParameter(rp_TopRight);
595 Button* button_LeftCenter = Button::create(
"cocosui/animationbuttonnormal.png",
596 "cocosui/animationbuttonpressed.png");
597 layout->addChild(button_LeftCenter);
599 RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();
600 rp_LeftCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL);
601 button_LeftCenter->setLayoutParameter(rp_LeftCenter);
605 Button* buttonCenter = Button::create(
"cocosui/animationbuttonnormal.png",
606 "cocosui/animationbuttonpressed.png");
607 layout->addChild(buttonCenter);
609 RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create();
610 rpCenter->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);
611 buttonCenter->setLayoutParameter(rpCenter);
615 Button* button_RightCenter = Button::create(
"cocosui/animationbuttonnormal.png",
616 "cocosui/animationbuttonpressed.png");
617 layout->addChild(button_RightCenter);
619 RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();
620 rp_RightCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_CENTER_VERTICAL);
621 button_RightCenter->setLayoutParameter(rp_RightCenter);
625 Button* button_LeftBottom = Button::create(
"cocosui/animationbuttonnormal.png",
626 "cocosui/animationbuttonpressed.png");
627 layout->addChild(button_LeftBottom);
629 RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create();
630 rp_LeftBottom->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM);
631 button_LeftBottom->setLayoutParameter(rp_LeftBottom);
635 Button* button_BottomCenter = Button::create(
"cocosui/animationbuttonnormal.png",
636 "cocosui/animationbuttonpressed.png");
637 layout->addChild(button_BottomCenter);
639 RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create();
640 rp_BottomCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL);
641 button_BottomCenter->setLayoutParameter(rp_BottomCenter);
645 Button* button_RightBottom = Button::create(
"cocosui/animationbuttonnormal.png",
646 "cocosui/animationbuttonpressed.png");
647 layout->addChild(button_RightBottom);
649 RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create();
650 rp_RightBottom->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_BOTTOM);
651 button_RightBottom->setLayoutParameter(rp_RightBottom);
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget