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);
cocos2d::ui::Layout * _layout
void printWidgetResources(cocos2d::Ref *sender)
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget
static cocos2d::Vec2 bottom()
static cocos2d::Vec2 left()