60 Size widgetSize =
_widget->getContentSize();
62 _displayValueLabel = Text::create(
"There are 50 items, but we only create 5 templates",
"fonts/Marker Felt.ttf", 20);
69 Text* alert = Text::create(
"ListView vertical",
"fonts/Marker Felt.ttf", 30);
70 alert->setColor(Color3B(159, 168, 176));
71 alert->setPosition(Vec2(widgetSize.width / 2.0f,
72 widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
75 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
77 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
78 Size backgroundSize = background->getContentSize();
85 std::string ccstr = StringUtils::format(
"listview_item_%d", i);
93 _listView->setDirection(ui::ScrollView::Direction::VERTICAL);
95 _listView->setBackGroundImage(
"cocosui/green_edit.png");
97 _listView->setBackGroundImageScale9Enabled(
true);
98 _listView->setContentSize(Size(240.0f, 130.0f));
102 _listView->setScrollBarPositionFromCorner(Vec2(7, 7));
107 Button* default_button = Button::create(
"cocosui/backtotoppressed.png",
"cocosui/backtotopnormal.png");
108 default_button->setName(
"Title Button");
110 Layout* default_item = Layout::create();
111 default_item->setTouchEnabled(
true);
112 default_item->setContentSize(default_button->getContentSize());
113 default_button->setPosition(Vec2(default_item->getContentSize() / 2.0f));
114 default_item->addChild(default_button);
116 auto clippingNode = ClippingNode::create();
117 auto sprite = Sprite::create(
"cocosui/clippingHead.jpg");
118 clippingNode->addChild(sprite);
119 auto stencil = Sprite::create(
"cocosui/clippingStencil.jpg");
120 clippingNode->setStencil(stencil);
121 auto custom_item_contentSize = default_item->getContentSize();
122 clippingNode->setPosition(sprite->getContentSize().width/2,
123 custom_item_contentSize.height/2);
124 clippingNode->setScale(0.5);
125 default_item->addChild(clippingNode);
131 _listView->setGravity(ListView::Gravity::CENTER_VERTICAL);
136 Widget* item = default_item->clone();
138 Button* btn = (Button*)item->getChildByName(
"Title Button");
139 btn->setTitleText(
_array.at(i));
151 this->scheduleUpdate();
155 _listView->setInnerContainerSize(Size(
_listView->getInnerContainerSize().width, totalHeight));
163 _indexLabels[0] = Text::create(
" ",
"fonts/Marker Felt.ttf", 12);
167 _indexLabels[1] = Text::create(
" ",
"fonts/Marker Felt.ttf", 12);
171 _indexLabels[2] = Text::create(
" ",
"fonts/Marker Felt.ttf", 12);
177 _listView->ScrollView::addEventListener([
this](Ref* ref, ScrollView::EventType eventType) {
178 ListView* listView =
dynamic_cast<ListView*
>(ref);
179 if(listView ==
nullptr || eventType != ScrollView::EventType::CONTAINER_MOVED)
183 auto bottom = listView->getBottommostItemInCurrentView();
184 auto center = listView->getCenterItemInCurrentView();
185 auto top = listView->getTopmostItemInCurrentView();
187 _indexLabels[0]->setString(StringUtils::format(
"Top index=%zd", listView->getIndex(top)));
188 _indexLabels[1]->setString(StringUtils::format(
"Center\nindex=%zd", listView->getIndex(center)));
189 _indexLabels[2]->setString(StringUtils::format(
"Bottom index=%zd", listView->getIndex(bottom)));
std::vector< std::string > _array
cocos2d::ui::Text * _displayValueLabel
void selectedItemEvent(cocos2d::Ref *sender, cocos2d::ui::ListView::EventType type)
float _itemTemplateHeight
cocos2d::ui::Text * _indexLabels[3]
void selectedItemEventScrollView(cocos2d::Ref *sender, cocos2d::ui::ScrollView::EventType type)
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget