138 Size widgetSize =
_widget->getContentSize();
141 _displayValueLabel = Text::create(
"Move by horizontal direction",
"fonts/Marker Felt.ttf",32);
146 Text* alert = Text::create(
"ScrollView horizontal",
"fonts/Marker Felt.ttf",30);
147 alert->setColor(Color3B(159, 168, 176));
148 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
151 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
153 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
156 ui::ScrollView* scrollView = ui::ScrollView::create();
157 scrollView->setBounceEnabled(
true);
158 scrollView->setDirection(ui::ScrollView::Direction::HORIZONTAL);
159 scrollView->setContentSize(Size(280.0f, 150.0f));
160 scrollView->setInnerContainerSize(scrollView->getContentSize());
161 scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
162 scrollView->setScrollBarColor(Color3B::YELLOW);
163 Size backgroundSize = background->getContentSize();
164 scrollView->setPosition((widgetSize - scrollView->getContentSize()) / 2.0f);
167 ImageView* imageView = ImageView::create(
"cocosui/ccicon.png");
169 float innerWidth = scrollView->getContentSize().width + imageView->getContentSize().width;
170 float innerHeight = scrollView->getContentSize().height;
172 scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
174 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
175 button->setPosition(Vec2(button->getContentSize().width / 2.0f,
176 scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
177 scrollView->addChild(button);
179 Button* titleButton = Button::create(
"cocosui/backtotopnormal.png",
"cocosui/backtotoppressed.png");
180 titleButton->setTitleText(
"Title Button");
181 titleButton->setPosition(Vec2(button->getRightBoundary() + button->getContentSize().width / 2.0f,
182 button->getBottomBoundary() - button->getContentSize().height / 2.0f));
183 scrollView->addChild(titleButton);
185 Button* button_scale9 = Button::create(
"cocosui/button.png",
"cocosui/buttonHighlighted.png");
186 button_scale9->setScale9Enabled(
true);
187 button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
188 button_scale9->setPosition(Vec2(titleButton->getRightBoundary() + titleButton->getContentSize().width / 2.0f,
189 titleButton->getBottomBoundary() - titleButton->getContentSize().height / 2.0f));
190 scrollView->addChild(button_scale9);
192 imageView->setPosition(Vec2(innerWidth - imageView->getContentSize().width / 2.0f,
193 button_scale9->getBottomBoundary() - button_scale9->getContentSize().height / 2.0f));
194 scrollView->addChild(imageView);
197 scrollView->jumpToRight();
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget