本文整理汇总了C++中ListView::removeChildByTag方法的典型用法代码示例。如果您正苦于以下问题:C++ ListView::removeChildByTag方法的具体用法?C++ ListView::removeChildByTag怎么用?C++ ListView::removeChildByTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListView
的用法示例。
在下文中一共展示了ListView::removeChildByTag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
//.........这里部分代码省略.........
listView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEvent, this));
listView->addEventListener((ui::ListView::ccScrollViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEventScrollView,this));
_uiLayer->addChild(listView);
// create model
Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
default_button->setName("Title Button");
Layout* default_item = Layout::create();
default_item->setTouchEnabled(true);
default_item->setContentSize(default_button->getContentSize());
default_button->setPosition(Vec2(default_item->getContentSize().width / 2.0f,
default_item->getContentSize().height / 2.0f));
default_item->addChild(default_button);
// set model
listView->setItemModel(default_item);
// add default item
ssize_t count = _array.size();
for (int i = 0; i < count / 4; ++i)
{
listView->pushBackDefaultItem();
}
// insert default item
for (int i = 0; i < count / 4; ++i)
{
listView->insertDefaultItem(0);
}
listView->removeAllChildren();
Sprite* testSprite = Sprite::create("cocosui/backtotoppressed.png");
testSprite->setPosition(Vec2(200,200));
listView->addChild(testSprite);
// add custom item
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setScale9Enabled(true);
custom_button->setContentSize(default_button->getContentSize());
Layout *custom_item = Layout::create();
custom_item->setContentSize(custom_button->getContentSize());
custom_button->setPosition(Vec2(custom_item->getContentSize().width / 2.0f, custom_item->getContentSize().height / 2.0f));
custom_item->addChild(custom_button);
listView->addChild(custom_item);
}
// insert custom item
Vector<Widget*>& items = listView->getItems();
ssize_t items_count = items.size();
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setScale9Enabled(true);
custom_button->setContentSize(default_button->getContentSize());
Layout *custom_item = Layout::create();
custom_item->setContentSize(custom_button->getContentSize());
custom_button->setPosition(Vec2(custom_item->getContentSize().width / 2.0f, custom_item->getContentSize().height / 2.0f));
custom_item->addChild(custom_button);
custom_item->setTag(1);
listView->insertCustomItem(custom_item, items_count);
}
// set item data
items_count = items.size();
for (int i = 0; i < items_count; ++i)
{
Widget* item = listView->getItem(i);
Button* button = static_cast<Button*>(item->getChildByName("Title Button"));
ssize_t index = listView->getIndex(item);
button->setTitleText(_array[index]);
}
// remove last item
listView->removeChildByTag(1);
// remove item by index
items_count = items.size();
listView->removeItem(items_count - 1);
// set all items layout gravity
listView->setGravity(ListView::Gravity::CENTER_VERTICAL);
// set items margin
listView->setItemsMargin(2.0f);
return true;
}
return false;
}
示例2: init
//.........这里部分代码省略.........
Sprite* testSprite = Sprite::create("cocosui/backtotoppressed.png");
testSprite->setPosition(Vec2(200,200));
listView->addChild(testSprite);
// add custom item
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setScale9Enabled(true);
custom_button->setContentSize(default_button->getContentSize());
Layout *custom_item = Layout::create();
custom_item->setContentSize(custom_button->getContentSize());
custom_button->setPosition(Vec2(custom_item->getContentSize().width / 2.0f, custom_item->getContentSize().height / 2.0f));
custom_item->addChild(custom_button);
listView->addChild(custom_item);
}
// insert custom item
Vector<Widget*>& items = listView->getItems();
ssize_t items_count = items.size();
for (int i = 0; i < count / 4; ++i)
{
Button* custom_button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
custom_button->setName("Title Button");
custom_button->setScale9Enabled(true);
custom_button->setContentSize(default_button->getContentSize());
Layout *custom_item = Layout::create();
custom_item->setContentSize(custom_button->getContentSize());
custom_button->setPosition(Vec2(custom_item->getContentSize().width / 2.0f, custom_item->getContentSize().height / 2.0f));
custom_item->addChild(custom_button);
custom_item->setTag(1);
listView->insertCustomItem(custom_item, items_count);
}
// set item data
items_count = items.size();
for (int i = 0; i < items_count; ++i)
{
Widget* item = listView->getItem(i);
Button* button = static_cast<Button*>(item->getChildByName("Title Button"));
ssize_t index = listView->getIndex(item);
button->setTitleText(_array[index]);
}
// remove last item
listView->removeChildByTag(1);
// remove item by index
items_count = items.size();
listView->removeItem(items_count - 1);
// set all items layout gravity
listView->setGravity(ListView::Gravity::CENTER_VERTICAL);
// set items margin
listView->setItemsMargin(2.0f);
// Show the indexes of items on each boundary.
{
float position = 75;
// Labels
_indexLabels[0] = Text::create(" ", "fonts/Marker Felt.ttf", 12);
_indexLabels[0]->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_indexLabels[0]->setPosition(_uiLayer->getContentSize() / 2 + Size(0, position));
_uiLayer->addChild(_indexLabels[0]);
_indexLabels[1] = Text::create(" ", "fonts/Marker Felt.ttf", 12);
_indexLabels[1]->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_indexLabels[1]->setPosition(_uiLayer->getContentSize() / 2 + Size(140, 0));
_uiLayer->addChild(_indexLabels[1]);
_indexLabels[2] = Text::create(" ", "fonts/Marker Felt.ttf", 12);
_indexLabels[2]->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_indexLabels[2]->setPosition(_uiLayer->getContentSize() / 2 + Size(0, -position));
_uiLayer->addChild(_indexLabels[2]);
// Callback
listView->ScrollView::addEventListener([this](Ref* ref, ScrollView::EventType eventType) {
ListView* listView = dynamic_cast<ListView*>(ref);
if(listView == nullptr || eventType != ScrollView::EventType::CONTAINER_MOVED)
{
return;
}
auto bottom = listView->getBottommostItemInCurrentView();
auto center = listView->getCenterItemInCurrentView();
auto top = listView->getTopmostItemInCurrentView();
_indexLabels[0]->setString(StringUtils::format("Top index=%zd", listView->getIndex(top)));
_indexLabels[1]->setString(StringUtils::format("Center\nindex=%zd", listView->getIndex(center)));
_indexLabels[2]->setString(StringUtils::format("Bottom index=%zd", listView->getIndex(bottom)));
});
}
return true;
}
return false;
}