28using namespace cocos2d::ui;
30UILayoutTests::UILayoutTests()
61 Size widgetSize =
_widget->getContentSize();
64 Text* alert = Text::create(
"Layout",
"fonts/Marker Felt.ttf", 30 );
65 alert->setColor(Color3B(159, 168, 176));
66 alert->setPosition(Vec2(widgetSize.width / 2.0f,
67 widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
71 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81)) ;
73 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
76 Layout* layout = Layout::create();
77 layout->setContentSize(Size(280, 150));
78 Size backgroundSize = background->getContentSize();
79 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
80 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
81 (widgetSize.height - backgroundSize.height) / 2.0f +
82 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
85 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
86 button->setPosition(Vec2(button->getContentSize().width / 2.0f,
87 layout->getContentSize().height - button->getContentSize().height / 2.0f));
88 layout->addChild(button);
90 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
91 titleButton->setTitleText(
"Title Button");
92 titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
93 layout->addChild(titleButton);
95 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
96 button_scale9->setScale9Enabled(
true);
97 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
98 button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
99 button_scale9->getContentSize().height / 2.0f));
101 layout->addChild(button_scale9);
123 Size widgetSize =
_widget->getContentSize();
126 Text* alert = Text::create(
"Layout color render",
"fonts/Marker Felt.ttf", 30);
127 alert->setColor(Color3B(159, 168, 176));
128 alert->setPosition(Vec2(widgetSize.width / 2.0f,
129 widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
133 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
135 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
138 Layout* layout = Layout::create();
139 layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
140 layout->setBackGroundColor(Color3B(128, 128, 128));
141 layout->setContentSize(Size(280, 150));
142 Size backgroundSize = background->getContentSize();
143 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
144 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
145 (widgetSize.height - backgroundSize.height) / 2.0f +
146 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
149 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
150 button->setPosition(Vec2(button->getContentSize().width / 2.0f,
151 layout->getContentSize().height - button->getContentSize().height / 2.0f));
153 layout->addChild(button);
155 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
156 titleButton->setTitleText(
"Title Button");
157 titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
158 layout->addChild(titleButton);
160 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
161 button_scale9->setScale9Enabled(
true);
162 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
163 button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
164 button_scale9->getContentSize().height / 2.0f));
166 layout->addChild(button_scale9);
187 Size widgetSize =
_widget->getContentSize();
190 Text* alert = Text::create(
"Layout gradient render",
"fonts/Marker Felt.ttf", 30);
191 alert->setColor(Color3B(159, 168, 176));
192 alert->setPosition(Vec2(widgetSize.width / 2.0f,
193 widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
197 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
199 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
202 Layout* layout = Layout::create();
203 layout->setBackGroundColorType(Layout::BackGroundColorType::GRADIENT);
204 layout->setBackGroundColor(Color3B(64, 64, 64), Color3B(192, 192, 192));
205 layout->setContentSize(Size(280, 150));
206 Size backgroundSize = background->getContentSize();
207 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
208 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
209 (widgetSize.height - backgroundSize.height) / 2.0f +
210 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
213 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
214 button->setPosition(Vec2(button->getContentSize().width / 2.0f,
215 layout->getContentSize().height - button->getContentSize().height / 2.0f));
217 layout->addChild(button);
219 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
220 titleButton->setTitleText(
"Title Button");
221 titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
222 layout->addChild(titleButton);
224 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
225 button_scale9->setScale9Enabled(
true);
226 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
227 button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
228 button_scale9->getContentSize().height / 2.0f));
230 layout->addChild(button_scale9);
251 Size widgetSize =
_widget->getContentSize();
254 Text* alert = Text::create(
"Layout background image",
"fonts/Marker Felt.ttf", 20);
255 alert->setColor(Color3B(159, 168, 176));
256 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
259 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
261 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
264 Layout* layout = Layout::create();
265 layout->setClippingEnabled(
true);
266 layout->setBackGroundImage(
"cocosui/Hello.png");
267 layout->setContentSize(Size(280, 150));
268 Size backgroundSize = background->getContentSize();
269 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
270 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
271 (widgetSize.height - backgroundSize.height) / 2.0f +
272 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
275 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
276 button->setPosition(Vec2(button->getContentSize().width / 2.0f,
277 layout->getContentSize().height - button->getContentSize().height / 2.0f));
278 layout->addChild(button);
280 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
281 titleButton->setTitleText(
"Title Button");
282 titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
283 layout->addChild(titleButton);
285 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
286 button_scale9->setScale9Enabled(
true);
287 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
288 button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
289 button_scale9->getContentSize().height / 2.0f));
291 layout->addChild(button_scale9);
295 TTFConfig ttfConfig(
"fonts/arial.ttf", 15);
296 auto label1 = Label::createWithTTF(ttfConfig,
"Print Resources");
299 auto pMenu1 = Menu::create(item1,
nullptr);
300 pMenu1->setPosition(Vec2(0, 0));
301 this->addChild(pMenu1, 10);
310 cocos2d::ResourceData textureFile =
_layout->getRenderFile();
311 CCLOG(
"textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
328 Size widgetSize =
_widget->getContentSize();
331 Text* alert = Text::create(
"Layout background image scale9",
"fonts/Marker Felt.ttf", 20);
332 alert->setColor(Color3B(159, 168, 176));
333 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
336 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
338 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
341 Layout* layout = Layout::create();
342 layout->setBackGroundImageScale9Enabled(
true);
343 layout->setBackGroundImage(
"cocosui/green_edit.png");
344 layout->setContentSize(Size(280, 150));
345 Size backgroundSize = background->getContentSize();
346 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
347 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
348 (widgetSize.height - backgroundSize.height) / 2.0f +
349 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
352 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
353 button->setPosition(Vec2(button->getContentSize().width / 2.0f,
354 layout->getContentSize().height - button->getContentSize().height / 2.0f));
356 layout->addChild(button);
358 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
359 titleButton->setTitleText(
"Title Button");
360 titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
361 layout->addChild(titleButton);
363 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
364 button_scale9->setScale9Enabled(
true);
365 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
366 button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
367 button_scale9->getContentSize().height / 2.0f));
368 layout->addChild(button_scale9);
389 Size widgetSize =
_widget->getContentSize();
392 Text* alert = Text::create(
"Layout Linear Vertical",
"fonts/Marker Felt.ttf", 20);
393 alert->setColor(Color3B(159, 168, 176));
394 alert->setPosition(Vec2(widgetSize.width / 2.0f,
395 widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
399 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
401 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
404 Layout* layout = Layout::create();
405 layout->setLayoutType(Layout::Type::VERTICAL);
406 layout->setContentSize(Size(280, 150));
407 Size backgroundSize = background->getContentSize();
408 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
409 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
410 (widgetSize.height - backgroundSize.height) / 2.0f +
411 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
415 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
416 layout->addChild(button);
418 LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
419 button->setLayoutParameter(lp1);
420 lp1->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
421 lp1->setMargin(Margin(0.0f, 5.0f, 0.0f, 10.0f));
424 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
425 titleButton->setTitleText(
"Title Button");
426 layout->addChild(titleButton);
428 LinearLayoutParameter* lp2 = LinearLayoutParameter::create();
429 titleButton->setLayoutParameter(lp2);
430 lp2->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
431 lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
434 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
435 button_scale9->setScale9Enabled(
true);
436 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
437 layout->addChild(button_scale9);
439 LinearLayoutParameter* lp3 = LinearLayoutParameter::create();
440 button_scale9->setLayoutParameter(lp3);
441 lp3->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
442 lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
465 Size widgetSize =
_widget->getContentSize();
468 Text* alert = Text::create(
"Layout Linear Horizontal",
"fonts/Marker Felt.ttf", 20);
469 alert->setColor(Color3B(159, 168, 176));
470 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
473 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
475 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
478 Layout* layout = Layout::create();
479 layout->setLayoutType(Layout::Type::HORIZONTAL);
480 layout->setClippingEnabled(
true);
481 layout->setContentSize(Size(280, 150));
482 Size backgroundSize = background->getContentSize();
483 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
484 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
485 (widgetSize.height - backgroundSize.height) / 2.0f +
486 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
489 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
490 layout->addChild(button);
492 LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
493 button->setLayoutParameter(lp1);
494 lp1->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
495 lp1->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
498 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
499 titleButton->setTitleText(
"Title Button");
500 layout->addChild(titleButton);
502 LinearLayoutParameter* lp2 = LinearLayoutParameter::create();
503 titleButton->setLayoutParameter(lp2);
504 lp2->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
505 lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
508 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
509 button_scale9->setScale9Enabled(
true);
510 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
511 layout->addChild(button_scale9);
513 LinearLayoutParameter* lp3 = LinearLayoutParameter::create();
514 button_scale9->setLayoutParameter(lp3);
515 lp3->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
516 lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
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);
674 Size widgetSize =
_widget->getContentSize();
677 Text* alert = Text::create(
"Layout Relative Location",
"fonts/Marker Felt.ttf", 20);
678 alert->setColor(Color3B(159, 168, 176));
679 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
682 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
684 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
687 Layout* layout = Layout::create();
688 layout->setLayoutType(Layout::Type::RELATIVE);
689 layout->setContentSize(Size(280, 150));
690 Size backgroundSize = background->getContentSize();
691 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
692 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
693 (widgetSize.height - backgroundSize.height) / 2.0f +
694 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
698 ImageView* imageView_Center = ImageView::create(
"cocosui/scrollviewbg.png");
699 layout->addChild(imageView_Center);
701 RelativeLayoutParameter* rp_Center = RelativeLayoutParameter::create();
702 rp_Center->setRelativeName(
"rp_Center");
703 rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);
704 imageView_Center->setLayoutParameter(rp_Center);
708 ImageView* imageView_AboveCenter = ImageView::create(
"cocosui/switch-mask.png");
709 layout->addChild(imageView_AboveCenter);
711 RelativeLayoutParameter* rp_AboveCenter = RelativeLayoutParameter::create();
712 rp_AboveCenter->setRelativeToWidgetName(
"rp_Center");
713 rp_AboveCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER);
714 imageView_AboveCenter->setLayoutParameter(rp_AboveCenter);
718 ImageView* imageView_BelowCenter = ImageView::create(
"cocosui/switch-mask.png");
719 layout->addChild(imageView_BelowCenter);
721 RelativeLayoutParameter* rp_BelowCenter = RelativeLayoutParameter::create();
722 rp_BelowCenter->setRelativeToWidgetName(
"rp_Center");
723 rp_BelowCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER);
724 imageView_BelowCenter->setLayoutParameter(rp_BelowCenter);
728 ImageView* imageView_LeftCenter = ImageView::create(
"cocosui/switch-mask.png");
729 layout->addChild(imageView_LeftCenter);
731 RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();
732 rp_LeftCenter->setRelativeToWidgetName(
"rp_Center");
733 rp_LeftCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_CENTER);
734 imageView_LeftCenter->setLayoutParameter(rp_LeftCenter);
739 ImageView* imageView_RightCenter = ImageView::create(
"cocosui/switch-mask.png");
740 layout->addChild(imageView_RightCenter);
742 RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();
743 rp_RightCenter->setRelativeToWidgetName(
"rp_Center");
744 rp_RightCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER);
745 imageView_RightCenter->setLayoutParameter(rp_RightCenter);
768 Size widgetSize =
_widget->getContentSize();
771 Text* alert = Text::create(
"Layout Scaled Widget",
"fonts/Marker Felt.ttf", 20);
772 alert->setColor(Color3B(159, 168, 176));
773 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
776 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
778 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
781 Layout* layout = Layout::create();
782 layout->setLayoutType(Layout::Type::HORIZONTAL);
783 layout->setContentSize(Size(280, 150));
784 Size backgroundSize = background->getContentSize();
785 layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
786 (backgroundSize.width - layout->getContentSize().width) / 2.0f,
787 (widgetSize.height - backgroundSize.height) / 2.0f +
788 (backgroundSize.height - layout->getContentSize().height) / 2.0f));
791 ImageView* imageView_Center1 = ImageView::create(
"cocosui/scrollviewbg.png");
792 imageView_Center1->setScale(0.5);
793 layout->addChild(imageView_Center1);
795 ImageView* imageView_Center2 = ImageView::create(
"cocosui/scrollviewbg.png");
796 imageView_Center2->setScale(1.2);
797 layout->addChild(imageView_Center2);
799 ImageView* imageView_Center3 = ImageView::create(
"cocosui/scrollviewbg.png");
800 imageView_Center3->setScale(0.8);
801 layout->addChild(imageView_Center3);
814 Size widgetSize =
_widget->getContentSize();
822 Button* button = Button::create(
"cocosui/animationbuttonnormal.png");
823 CCLOG(
"content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
824 button->getContentSize().height);
825 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
827 button->setZoomScale(0.4f);
828 button->setPressedActionEnabled(
true);
840 case Widget::TouchEventType::BEGAN:
843 case Widget::TouchEventType::MOVED:
846 case Widget::TouchEventType::ENDED:
848 Size widgetSize =
_widget->getContentSize();
849 Size layerSize =
_baseLayer->getContentSize();
850 if (layerSize.width == widgetSize.width && layerSize.height == widgetSize.height)
858 case Widget::TouchEventType::CANCELED:
870 Sprite* leftTopSprite = Sprite::create(
"cocosui/CloseSelected.png");
871 LayoutComponent* leftTop = LayoutComponent::bindLayoutComponent(leftTopSprite);
872 leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
873 leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
876 Sprite* leftBottomSprite = Sprite::create(
"cocosui/CloseSelected.png");
877 LayoutComponent* leftBottom = LayoutComponent::bindLayoutComponent(leftBottomSprite);
878 leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
879 leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
882 Sprite* rightTopSprite = Sprite::create(
"cocosui/CloseSelected.png");
883 LayoutComponent* rightTop = LayoutComponent::bindLayoutComponent(rightTopSprite);
884 rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
885 rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
888 Sprite* rightBottomSprite = Sprite::create(
"cocosui/CloseSelected.png");
889 LayoutComponent* rightBottom = LayoutComponent::bindLayoutComponent(rightBottomSprite);
890 rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
891 rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
905 ImageView* leftTopSprite = ImageView::create(
"cocosui/CloseSelected.png");
906 leftTopSprite->ignoreContentAdaptWithSize(
false);
907 LayoutComponent* leftTop = LayoutComponent::bindLayoutComponent(leftTopSprite);
908 leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
909 leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
910 leftTop->setStretchWidthEnabled(
true);
911 leftTop->setStretchHeightEnabled(
true);
913 leftTop->setSize(leftTopSprite->getContentSize());
914 leftTop->setLeftMargin(0);
915 leftTop->setTopMargin(0);
917 ImageView* leftBottomSprite = ImageView::create(
"cocosui/CloseSelected.png");
918 leftBottomSprite->ignoreContentAdaptWithSize(
false);
919 LayoutComponent* leftBottom = LayoutComponent::bindLayoutComponent(leftBottomSprite);
920 leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
921 leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
922 leftBottom->setStretchWidthEnabled(
true);
923 leftBottom->setStretchHeightEnabled(
true);
925 leftBottom->setSize(leftBottomSprite->getContentSize());
926 leftBottom->setLeftMargin(0);
927 leftBottom->setBottomMargin(0);
929 ImageView* rightTopSprite = ImageView::create(
"cocosui/CloseSelected.png");
930 rightTopSprite->ignoreContentAdaptWithSize(
false);
931 LayoutComponent* rightTop = LayoutComponent::bindLayoutComponent(rightTopSprite);
932 rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
933 rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
934 rightTop->setStretchWidthEnabled(
true);
935 rightTop->setStretchHeightEnabled(
true);
937 rightTop->setSize(rightTopSprite->getContentSize());
938 rightTop->setTopMargin(0);
939 rightTop->setRightMargin(0);
941 ImageView* rightBottomSprite = ImageView::create(
"cocosui/CloseSelected.png");
942 rightBottomSprite->ignoreContentAdaptWithSize(
false);
943 LayoutComponent* rightBottom = LayoutComponent::bindLayoutComponent(rightBottomSprite);
944 rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
945 rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
946 rightBottom->setStretchWidthEnabled(
true);
947 rightBottom->setStretchHeightEnabled(
true);
949 rightBottom->setSize(rightBottomSprite->getContentSize());
950 rightBottom->setBottomMargin(0);
951 rightBottom->setRightMargin(0);
#define ADD_TEST_CASE(__className__)
virtual bool init() override
virtual bool init() override
cocos2d::LayerColor * _baseLayer
virtual bool init() override
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
UILayoutTest_BackGroundImage_Scale9()
virtual bool init() override
~UILayoutTest_BackGroundImage_Scale9()
cocos2d::ui::Layout * _layout
virtual bool init() override
~UILayoutTest_BackGroundImage()
UILayoutTest_BackGroundImage()
void printWidgetResources(cocos2d::Ref *sender)
virtual bool init() override
virtual bool init() override
~UILayoutTest_Layout_Linear_Horizontal()
UILayoutTest_Layout_Linear_Horizontal()
virtual bool init() override
UILayoutTest_Layout_Linear_Vertical()
~UILayoutTest_Layout_Linear_Vertical()
virtual bool init() override
UILayoutTest_Layout_Relative_Align_Parent()
~UILayoutTest_Layout_Relative_Align_Parent()
virtual bool init() override
~UILayoutTest_Layout_Relative_Location()
virtual bool init() override
UILayoutTest_Layout_Relative_Location()
virtual bool init() override
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget
static cocos2d::Vec2 bottom()
static cocos2d::Vec2 left()