28using namespace cocos2d::ui;
30UIButtonTests::UIButtonTests()
55: _displayValueLabel(nullptr)
68 Size widgetSize =
_widget->getContentSize();
73 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
77 Text* alert = Text::create(
"Button",
"fonts/Marker Felt.ttf",30);
78 alert->setColor(Color3B(159, 168, 176));
80 alert->setPosition(Vec2(widgetSize.width / 2.0f,
81 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
86 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
87 "cocosui/animationbuttonpressed.png");
88 CCLOG(
"content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
89 button->getContentSize().height);
90 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
92 button->setZoomScale(0.4f);
93 button->setPressedActionEnabled(
true);
95 button->setOpacity(100);
97 ImageView* imageView = ImageView::create();
99 imageView->setPosition(Vec2(widgetSize.width / 2.0f + 50+ button->getContentSize().width/2,
100 widgetSize.height / 2.0f));
101 imageView->setTag(12);
107 TTFConfig ttfConfig(
"fonts/arial.ttf", 15);
108 auto label1 = Label::createWithTTF(ttfConfig,
"Print Resources");
111 auto pMenu1 = Menu::create(item1,
nullptr);
112 pMenu1->setPosition(Vec2(0.0f, 0.0f));
113 this->addChild(pMenu1, 10);
124 case Widget::TouchEventType::BEGAN:
128 case Widget::TouchEventType::MOVED:
132 case Widget::TouchEventType::ENDED:
135 ImageView* imageView = (ImageView*)
_uiLayer->getChildByTag(12);
136 imageView->setVisible(
false);
137 imageView->loadTexture(
"cocosui/ccicon.png");
138 imageView->setOpacity(0);
139 imageView->setVisible(
true);
140 imageView->runAction(Sequence::create(FadeIn::create(0.5),DelayTime::create(1.0),FadeOut::create(0.5),
nullptr));
141 Button *btn = (Button*)pSender;
142 btn->loadTextureNormal(
"cocosui/animationbuttonnormal.png");
146 case Widget::TouchEventType::CANCELED:
157 cocos2d::ResourceData normalFileName =
_button->getNormalFile();
158 CCLOG(
"normalFileName Name : %s, Type: %d", normalFileName.file.c_str(), normalFileName.type);
159 cocos2d::ResourceData clickedFileName =
_button->getPressedFile();
160 CCLOG(
"clickedFileName Name : %s, Type: %d", clickedFileName.file.c_str(), clickedFileName.type);
161 cocos2d::ResourceData disabledFileName =
_button->getDisabledFile();
162 CCLOG(
"disabledFileName Name : %s, Type: %d", disabledFileName.file.c_str(), disabledFileName.type);
168: _displayValueLabel(nullptr)
182 Size widgetSize =
_widget->getContentSize();
187 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
191 Text* alert = Text::create(
"Button scale9 render",
"fonts/Marker Felt.ttf",30);
192 alert->setColor(Color3B(159, 168, 176));
193 alert->setPosition(Vec2(widgetSize.width / 2.0f,
194 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
198 Button* button = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
200 button->setScale9Enabled(
true);
201 button->setContentSize(Size(150.0f, 70.0f));
202 button->setPosition(Vec2(-button->getContentSize().width - 10, widgetSize.height / 2.0f));
203 auto moveBy = MoveBy::create(1.0f, Vec2(widgetSize.width/2, 0.0f));
204 auto moveByReverse = moveBy->reverse()->clone();
205 button->runAction(RepeatForever::create(
206 Sequence::create(moveBy,moveByReverse, NULL)));
207 button->setPressedActionEnabled(
true);
212 Button* button2 = Button::create();
213 button2->setPosition(Vec2(widgetSize.width / 2.0f + button->getContentSize().width + 20, widgetSize.height / 2.0f));
214 button2->setName(
"normal");
217 Sprite *sprite = Sprite::create(
"cocosui/animationbuttonnormal.png");
218 button2->addChild(sprite);
229 case Widget::TouchEventType::BEGAN:
233 case Widget::TouchEventType::MOVED:
237 case Widget::TouchEventType::ENDED:
240 Button *btn = (Button*)
_uiLayer->getChildByName(
"normal");
241 btn->loadTextureNormal(
"cocosui/animationbuttonnormal.png");
242 btn->loadTexturePressed(
"cocosui/animationbuttonpressed.png");
243 btn->runAction(Sequence::create(FadeIn::create(0.5),DelayTime::create(1.0),FadeOut::create(0.5),
nullptr));
247 case Widget::TouchEventType::CANCELED:
258 : _displayValueLabel(nullptr)
272 Size widgetSize =
_widget->getContentSize();
277 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
281 Text* alert = Text::create(
"Button scale9 render",
"fonts/Marker Felt.ttf", 30);
282 alert->setColor(Color3B(159, 168, 176));
283 alert->setPosition(Vec2(widgetSize.width / 2.0f,
284 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
288 Button* button = Button::create(
"cocosui/button.png");
290 button->ignoreContentAdaptWithSize(
false);
291 button->setScale9Enabled(
true);
292 button->setPosition(Vec2(widgetSize.width / 2.0f - 100, widgetSize.height / 2.0f));
293 button->setContentSize(Size(180.0f, 60.0f));
294 button->setTitleText(
"Hello Scale9");
295 button->setPressedActionEnabled(
false);
299 Button* button2 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
301 button2->ignoreContentAdaptWithSize(
false);
302 button2->setScale9Enabled(
true);
303 button2->setTitleText(
"Hello scale9");
304 button2->setPosition(Vec2(widgetSize.width / 2.0f + 100, widgetSize.height / 2.0f));
305 button2->setContentSize(Size(180.0f, 60.0f));
306 button2->setPressedActionEnabled(
true);
318 case Widget::TouchEventType::BEGAN:
322 case Widget::TouchEventType::MOVED:
326 case Widget::TouchEventType::ENDED:
329 Button *btn = (Button*)pSender;
330 if (btn->isScale9Enabled())
332 btn->setScale9Enabled(
false);
335 btn->setScale9Enabled(
true);
339 case Widget::TouchEventType::CANCELED:
350: _displayValueLabel(nullptr)
362 Size widgetSize =
_widget->getContentSize();
367 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
371 Text* alert = Text::create(
"Button Pressed Action",
"fonts/Marker Felt.ttf", 30);
372 alert->setColor(Color3B(159, 168, 176));
374 alert->setPosition(Vec2(widgetSize.width / 2.0f,
375 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
380 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
381 button->setPressedActionEnabled(
true);
382 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
383 button->setColor(Color3B::GREEN);
384 button->setOpacity(30);
386 button->setName(
"button");
389 Button* button2 = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
390 button2->setPosition(button->getPosition() + Vec2(100.0f,0.0f));
391 button2->setName(
"button2");
403 case Widget::TouchEventType::BEGAN:
407 case Widget::TouchEventType::MOVED:
411 case Widget::TouchEventType::ENDED:
414 Button* btn = (Button*)
_uiLayer->getChildByName(
"button");
415 btn->loadTextureNormal(
"cocosui/animationbuttonnormal.png");
417 Button* btn2 = (Button*)
_uiLayer->getChildByName(
"button2");
418 btn2->setAnchorPoint(Vec2(0,0.5));
422 case Widget::TouchEventType::CANCELED:
433: _displayValueLabel(nullptr)
446 Size widgetSize =
_widget->getContentSize();
451 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
455 Text* alert = Text::create(
"Button with title, title should be flipped!",
"fonts/Marker Felt.ttf", 30);
456 alert->setColor(Color3B(159, 168, 176));
457 alert->setPosition(Vec2(widgetSize.width / 2.0f,
458 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
463 Button* button = Button::create(
"cocosui/backtotoppressed.png",
"cocosui/backtotopnormal.png");
464 button->setTitleText(
"Title Button!");
465 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
466 button->setTitleColor(Color3B::YELLOW);
467 CCASSERT(button->getTitleColor() == Color3B::YELLOW,
"Button setTitleColor & getTitleColor not match!");
470 button->setFlippedX(
true);
471 auto label = button->getTitleRenderer();
472 label->setScale(4.0);
473 button->runAction(RepeatForever::create(Sequence::create(ScaleTo::create(1.0f, 1.2f),
474 ScaleTo::create(1.0f, 1.0f),
nullptr)));
477 TextBMFont *text = TextBMFont::create(
"BMFont",
"cocosui/bitmapFontTest2.fnt");
478 text->setPosition(button->getPosition() + Vec2(button->getContentSize().width/2 + 50,0.0f));
479 text->setColor(Color3B::YELLOW);
480 text->setOpacity(50);
481 text->setName(
"text");
483 auto button2 = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
484 button2->setTitleFontName(
"fonts/helvetica-32.fnt");
485 button2->setTitleText(
"BMFont");
487 button2->setTitleFontSize(30);
488 button2->setPosition(Vec2(button->getPosition() + Vec2(50.0f,-80.0f)));
489 this->addChild(button2);
503 case Widget::TouchEventType::BEGAN:
507 case Widget::TouchEventType::MOVED:
511 case Widget::TouchEventType::ENDED:
514 TextBMFont *text = (TextBMFont*)
_uiLayer->getChildByName(
"text");
515 text->setFntFile(
"cocosui/bitmapFontTest2.fnt");
516 if (text->getString() ==
"BMFont") {
517 text->setString(
"Hello");
520 text->setString(
"BMFont");
525 case Widget::TouchEventType::CANCELED:
537: _displayValueLabel(nullptr)
550 Size widgetSize =
_widget->getContentSize();
555 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
559 Text* alert = Text::create(
"Remove Self in the Button's Callback shouldn't cause crash!",
"fonts/Marker Felt.ttf",10);
560 alert->setColor(Color3B(159, 168, 176));
562 alert->setPosition(Vec2(widgetSize.width / 2.0f,
563 widgetSize.height / 2.0f - alert->getContentSize().height * 2.75f));
567 Layout *layout = Layout::create();
568 layout->setContentSize(widgetSize * 0.6f);
569 layout->setBackGroundColor(Color3B::GREEN);
570 layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
571 layout->setBackGroundColorOpacity(100);
572 layout->setPosition(Size(widgetSize.width/2, widgetSize.height/2));
573 layout->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
578 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
579 "cocosui/animationbuttonpressed.png");
580 button->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
583 layout->addChild(button);
596 case Widget::TouchEventType::BEGAN:
600 case Widget::TouchEventType::MOVED:
604 case Widget::TouchEventType::ENDED:
607 auto layout =
_uiLayer->getChildByTag(12);
608 layout->removeFromParentAndCleanup(
true);
612 case Widget::TouchEventType::CANCELED:
623: _displayValueLabel(nullptr)
636 Size widgetSize =
_widget->getContentSize();
641 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
646 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
647 "cocosui/animationbuttonpressed.png");
648 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
650 button->setTitleText(
"Button Title");
651 button->ignoreContentAdaptWithSize(
false);
666 case Widget::TouchEventType::BEGAN:
670 case Widget::TouchEventType::MOVED:
674 case Widget::TouchEventType::ENDED:
677 auto btn = ((Button*)pSender);
678 btn->setScale9Enabled(!btn->isScale9Enabled());
679 btn->setContentSize(Size(200.0f,100.0f));
683 case Widget::TouchEventType::CANCELED:
695: _displayValueLabel(nullptr)
708 Size widgetSize =
_widget->getContentSize();
713 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
718 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
719 "cocosui/animationbuttonpressed.png");
720 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
721 button->setPressedActionEnabled(
true);
722 button->addClickEventListener([=](Ref* sender){
723 CCLOG(
"Button clicked, position = (%f, %f)", button->getPosition().x,
724 button->getPosition().y);
727 button->setName(
"button");
729 button->setZoomScale(-0.5);
731 Slider* slider = Slider::create();
732 slider->loadBarTexture(
"cocosui/sliderTrack.png");
733 slider->loadSlidBallTextures(
"cocosui/sliderThumb.png",
"cocosui/sliderThumb.png",
"");
734 slider->loadProgressBarTexture(
"cocosui/sliderProgress.png");
735 slider->setPosition(Vec2(widgetSize.width / 2.0f , widgetSize.height / 2.0f - 20));
737 slider->setPercent(button->getZoomScale()*100);
746 if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
748 Slider* slider =
dynamic_cast<Slider*
>(pSender);
749 int percent = slider->getPercent();
750 Button* btn = (Button*)
_uiLayer->getChildByName(
"button");
751 float zoomScale = percent * 0.01;
752 btn->setZoomScale(zoomScale);
759: _displayValueLabel(nullptr)
772 Size widgetSize =
_widget->getContentSize();
777 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
782 auto button = Button::create();
783 button->setPositionNormalized(Vec2(0.5f, 0.5f));
785 button->setTitleText(
"PLAY GAME");
786 CCLOG(
"content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
787 button->getContentSize().height);
788 button->setZoomScale(0.3f);
789 button->setPressedActionEnabled(
true);
790 button->addClickEventListener([](Ref* sender) {
802: _displayValueLabel(nullptr)
815 Size widgetSize =
_widget->getContentSize();
818 _displayValueLabel = Text::create(
"Button IgnoreContent Size Test",
"fonts/Marker Felt.ttf",32);
820 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
825 auto button = Button::create(
"cocosui/animationbuttonnormal.png",
826 "cocosui/animationbuttonpressed.png");
827 button->ignoreContentAdaptWithSize(
false);
828 button->setContentSize(Size(200.0f,100.0f));
829 button->setPositionNormalized(Vec2(0.3f, 0.5f));
830 button->setTitleText(
"PLAY GAME");
831 button->setZoomScale(0.3f);
832 button->setPressedActionEnabled(
true);
833 button->addClickEventListener([=](Ref* sender) {
835 button->setScale(1.2f);
840 auto button2 = Button::create(
"cocosui/animationbuttonnormal.png",
841 "cocosui/animationbuttonpressed.png");
842 button2->ignoreContentAdaptWithSize(
false);
843 button2->setContentSize(Size(200.0f,100.0f));
844 button2->setPositionNormalized(Vec2(0.8f, 0.5f));
845 button2->setTitleText(
"PLAY GAME");
846 button2->setZoomScale(0.3f);
847 button2->setPressedActionEnabled(
true);
848 button2->addClickEventListener([=](Ref* sender) {
849 button2->runAction(ScaleTo::create(1.0f, 1.2f));
862: _displayValueLabel(nullptr)
875 Size widgetSize =
_widget->getContentSize();
880 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
885 auto button = Button::create(
"cocosui/animationbuttonnormal.png",
886 "cocosui/animationbuttonpressed.png");
887 button->setPositionNormalized(Vec2(0.3f, 0.5f));
888 button->setTitleText(
"PLAY GAME");
889 button->setTitleFontName(
"fonts/Marker Felt.ttf");
890 button->setZoomScale(0.3f);
891 button->setScale(2.0f);
892 button->setPressedActionEnabled(
true);
893 Label *
title = button->getTitleRenderer();
894 button->setTitleColor(Color3B::RED);
895 title->enableShadow(Color4B::BLACK,Size(2,-2));
901 auto button2 = Button::create(
"cocosui/animationbuttonnormal.png",
902 "cocosui/animationbuttonpressed.png");
903 button2->setPositionNormalized(Vec2(0.8f, 0.5f));
904 button2->setTitleText(
"PLAY GAME");
905 auto title2 = button2->getTitleRenderer();
906 title2->enableOutline(Color4B::GREEN, 3);
915: _displayValueLabel(nullptr)
928 Size widgetSize =
_widget->getContentSize();
937 auto button = Button::create(
"cocosui/animationbuttonnormal.png",
938 "cocosui/animationbuttonpressed.png");
939 button->setPositionNormalized(Vec2(0.3f, 0.5f));
940 button->setTitleText(
"PLAY GAME");
941 button->setTitleFontName(
"fonts/Marker Felt.ttf");
942 button->setZoomScale(0.3f);
943 button->setScale(2.0f);
944 button->setFlippedX(
true);
945 button->setPressedActionEnabled(
true);
951 auto button2 = Button::create(
"cocosui/animationbuttonnormal.png",
952 "cocosui/animationbuttonpressed.png");
953 button2->setPositionNormalized(Vec2(0.8f, 0.5f));
954 button2->setTitleText(
"PLAY GAME");
955 button2->setFlippedY(
true);
958 auto titleLabel = Text::create(
"Button Y flipped",
"Arial", 20);
959 titleLabel->setPositionNormalized(Vec2(0.8f, 0.7f));
960 this->addChild(titleLabel);
969: _displayValueLabel(nullptr)
982 Size widgetSize =
_widget->getContentSize();
987 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
991 Text* alert = Text::create(
"Button should scale when clicked",
"fonts/Marker Felt.ttf",20);
992 alert->setColor(Color3B(159, 168, 176));
994 alert->setPosition(Vec2(widgetSize.width / 2.0f,
995 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
1000 Button* button = Button::create(
"cocosui/animationbuttonnormal.png");
1001 button->setPosition(Vec2(widgetSize.width / 2.0f - 80, widgetSize.height / 2.0f + 40));
1002 button->setZoomScale(0.4f);
1003 button->setPressedActionEnabled(
true);
1007 Button* buttonScale9 = Button::create(
"cocosui/button.png");
1009 buttonScale9->setScale9Enabled(
true);
1010 buttonScale9->setPosition(Vec2(widgetSize.width / 2.0f + 50, widgetSize.height / 2.0f + 40));
1011 buttonScale9->setContentSize(Size(150.0f, 70.0f));
1012 buttonScale9->setPressedActionEnabled(
true);
1026: _displayValueLabel(nullptr)
1039 Size widgetSize =
_widget->getContentSize();
1044 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
1048 Text* alert = Text::create(
"Left button will turn normal when clicked",
"fonts/Marker Felt.ttf",20);
1049 alert->setColor(Color3B(159, 168, 176));
1051 alert->setPosition(Vec2(widgetSize.width / 2.0f,
1052 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
1057 Button* button = Button::create(
"cocosui/animationbuttonnormal.png");
1058 button->setPosition(Vec2(widgetSize.width / 2.0f - 80, widgetSize.height / 2.0f + 40));
1059 button->setZoomScale(0.4f);
1060 button->setPressedActionEnabled(
true);
1061 button->setBright(
false);
1062 button->setScale9Enabled(
true);
1063 button->setCapInsets(Rect(3,3,5,5));
1064 button->addClickEventListener([=](Ref*){
1065 button->setBright(
true);
1070 Button* buttonScale9 = Button::create(
"cocosui/button.png");
1072 buttonScale9->setScale9Enabled(
true);
1073 buttonScale9->setPosition(Vec2(widgetSize.width / 2.0f + 50, widgetSize.height / 2.0f + 40));
1074 buttonScale9->setContentSize(Size(150.0f, 70.0f));
1075 buttonScale9->setPressedActionEnabled(
true);
1076 buttonScale9->setEnabled(
false);
1077 buttonScale9->setBright(
false);
1090: _displayValueLabel(nullptr)
1103 Size widgetSize =
_widget->getContentSize();
1109 widgetSize.height / 2.0f));
1113 Text* alert = Text::create(
"This test case shouldn't trigger the Assertion!",
1114 "fonts/Marker Felt.ttf",20);
1115 alert->setColor(Color3B(159, 168, 176));
1117 alert->setPosition(Vec2(widgetSize.width / 2.0f,
1118 widgetSize.height / 2.0f
1119 - alert->getContentSize().height * 1.75f));
1124 Button* button = Button::create(
"cocosui/animationbuttonnormal.png");
1125 button->setPosition(Vec2(widgetSize.width / 2.0f - 80,
1126 widgetSize.height / 2.0f + 40));
1130 CCASSERT(button->getTitleRenderer() ==
nullptr,
1131 "Button title render must be nullptr ");
1133 auto buttonCopy = (Button*)button->clone();
1134 buttonCopy->setPosition(Vec2(widgetSize.width / 2.0f + 80,
1135 widgetSize.height / 2.0f + 40));
1136 this->addChild(buttonCopy);
1140 auto buttonScale9Copy = (Button*)button->clone();
1141 buttonScale9Copy->setPosition(button->getPosition() + Vec2(0.0f, -60.0f));
1142 buttonScale9Copy->setScale9Enabled(
true);
1143 buttonScale9Copy->setContentSize(button->getContentSize() * 1.5f);
1144 this->addChild(buttonScale9Copy);
1147 auto buttonScale9Copy2 = (Button*)buttonScale9Copy->clone();
1148 buttonScale9Copy2->setPosition(buttonCopy->getPosition() + Vec2(0.0f, -60.0f));
1149 buttonScale9Copy2->setScale9Enabled(
true);
1150 buttonScale9Copy2->setContentSize(buttonCopy->getContentSize() * 1.5f);
1151 this->addChild(buttonScale9Copy2);
1154 CCASSERT(button->getTitleRenderer() ==
nullptr,
1155 "Original Button title render must be nullptr ");
1157 CCASSERT(buttonCopy->getTitleRenderer() ==
nullptr,
1158 "Copied Button title render must be nullptr ");
1167: _displayValueLabel(nullptr)
1176 Size widgetSize =
_widget->getContentSize();
1182 widgetSize.height / 2.0f));
1186 Text* alert = Text::create(
"This test case two buttons should seem to be same!",
1187 "fonts/Marker Felt.ttf",20);
1188 alert->setColor(Color3B(159, 168, 176));
1190 alert->setPosition(Vec2(widgetSize.width / 2.0f,
1191 widgetSize.height / 2.0f
1192 - alert->getContentSize().height * 2.0f));
1197 Button* button =
nullptr, *button2 =
nullptr;
1198 float btnWidth = 100;
1199 button = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
1200 button->setScale9Enabled(
true);
1201 button->setContentSize(Size(btnWidth, button->getContentSize().height));
1202 button->setTitleText(
"Scale9 Button 1");
1203 button->setPosition(Vec2(widgetSize.width / 2.0f - btnWidth, widgetSize.height / 2.0f));
1207 button2 = Button::create();
1208 button2->setScale9Enabled(
true);
1209 button2->loadTextures(
"cocosui/button.png",
"cocosui/buttonHighlighted.png",
"");
1210 button2->setContentSize(Size(btnWidth, button2->getContentSize().height));
1211 button2->setTitleText(
"Scale9 Button 2");
1212 button2->setPosition(Vec2(widgetSize.width / 2.0f + btnWidth, widgetSize.height / 2.0f));
1229 auto visibleSize = Director::getInstance()->getVisibleSize();
1231 SpriteFrameCache::getInstance()->addSpriteFramesWithFile(
"Images/issue_17116.plist");
1232 auto button = ui::Button::create();
1233 button->loadTextureNormal(
"buttons/play-big", ui::Widget::TextureResType::PLIST);
1234 button->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
1235 button->setOpacity(100);
1250 auto visibleSize = Director::getInstance()->getVisibleSize();
1252 SpriteFrameCache::getInstance()->addSpriteFramesWithFile(
"Images/poly_test_textures.plist");
1253 auto button = ui::Button::create();
1254 button->loadTextureNormal(
"poly_test/wheel_disc_back.png", ui::Widget::TextureResType::PLIST);
1255 button->setPosition(Vec2(visibleSize.width/2 - 100, visibleSize.height/2));
1256 button->setScale(0.5);
1257 button->setScale9Enabled(
true);
1260 auto buttonCopy = button->clone();
1261 button->setPosition(Vec2(visibleSize.width/2 + 100, visibleSize.height/2));
1262 addChild(buttonCopy);
1277 ImageView* sprite = ImageView::create(
"Images/blocks.png");
1278 sprite->setScale9Enabled(
true);
1279 sprite->setCapInsets(Rect(32, 32, 32, 32));
1280 sprite->setContentSize(Size(96 * 1.5, 96));
1281 sprite->setNormalizedPosition(Vec2(0.2f, 0.5f));
1282 this->addChild(sprite);
1284 auto button = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
1285 button->setScale9Enabled(
true);
1286 button->setContentSize(Size(100.0f, 50.0f));
1287 button->setNormalizedPosition(Vec2(0.6f, 0.5f));
1288 button->setTitleText(
"Press me");
1291 button->addClickEventListener([sprite](Ref* button){
1292 sprite->loadTexture(
"Images/blocks9.png");
#define ADD_TEST_CASE(__className__)
virtual bool init() override
cocos2d::ui::Text * _displayValueLabel
virtual bool init() override
virtual std::string title() const
cocos2d::ui::Text * _displayValueLabel
UIButtonIgnoreContentSizeTest()
virtual bool init() override
~UIButtonIgnoreContentSizeTest()
virtual bool init() override
cocos2d::ui::Text * _displayValueLabel
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget
static cocos2d::Vec2 bottom()
static cocos2d::Vec2 left()