本文整理汇总了C++中ListView::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ ListView::addChild方法的具体用法?C++ ListView::addChild怎么用?C++ ListView::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListView
的用法示例。
在下文中一共展示了ListView::addChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMainLayout
/**
* Creates and adds main layout to the screen.
*/
void SettingsScreen::createMainLayout() {
// Create and add the main layout to the screen.
VerticalLayout* mainLayout = new VerticalLayout();
Screen::setMainWidget(mainLayout);
ListView* listView = new ListView();
mainLayout->addChild(listView);
// Add set duration option row.
this->addSetDurationRow(listView);
// Add get duration option row.
this->addGetDurationRow(listView);
// Add options for setting and getting the video quality value.
this->addVideoQualityRows(listView);
if ( isIOS())
{
// Add options for setting and getting the flash mode value.
this->addFlashModeRows(listView);
// Add option for setting the camera roll flag.
this->addCameraRollFlagRow(listView);
// Add option for setting the camera controls flag.
this->addCameraControlsFlagRow(listView);
}
// Add take picture button.
mTakePictureBtn = new Button();
mTakePictureBtn->setText(TAKE_PICTURE_BTN_TEXT);
this->addButtonToListView(mTakePictureBtn, listView);
if (isAndroid())
{
mTakenPicturePath = new Label();
ListViewItem* listItem = new ListViewItem();
listItem->addChild(mTakenPicturePath);
listView->addChild(listItem);
}
// Add record video button.
mRecordVideoBtn = new Button();
mRecordVideoBtn->setText(RECORD_VIDEO_BTN_TEXT);
this->addButtonToListView(mRecordVideoBtn, listView);
// Add show image button.
mShowImageScreen = new Button();
mShowImageScreen->setText(SHOW_IMAGE_SCREEN_TEXT);
this->addButtonToListView(mShowImageScreen, listView);
// Add show video screen button.
mShowVideoScreen = new Button();
mShowVideoScreen->setText(SHOW_VIDEO_SCREEN_TEXT);
this->addButtonToListView(mShowVideoScreen, listView);
}
示例2: createMainLayout
/**
* Creates and adds main layout to the screen.
*/
void SettingsScreen::createMainLayout()
{
VerticalLayout* mainLayout = new VerticalLayout();
Screen::setMainWidget(mainLayout);
ListView* listView = new ListView();
listView->fillSpaceHorizontally();
listView->fillSpaceVertically();
mainLayout->addChild(listView);
ListViewItem* listItem;
// Add IP label and edit box
mIPEditBox = new EditBox();
mIPEditBox->setInputMode(EDIT_BOX_INPUT_MODE_NUMERIC);
listView->addChild(this->createListViewItem(IP_LABEL_TEXT, mIPEditBox));
// Add port label and edit box
mPortEditBox = new EditBox();
mPortEditBox->setInputMode(EDIT_BOX_INPUT_MODE_NUMERIC);
listView->addChild(this->createListViewItem(PORT_LABEL_TEXT, mPortEditBox));
if ( isAndroid() )
{
mShowOnlyIfInBackground = new CheckBox();
mShowOnlyIfInBackground->setState(true);
listView->addChild(createListViewItem(SHOW_ONLY_IF_NOT_RUNNING, mShowOnlyIfInBackground));
mTickerText = new EditBox();
mTickerText->setText(TICKER_DEFAULT);
listView->addChild(createListViewItem(TICKER_LABEL, mTickerText));
mContentTitle = new EditBox();
mContentTitle->setText(TITLE_DEFAULT);
listView->addChild(createListViewItem(TITLE_LABEL, mContentTitle));
}
// Android: If the registrationID was already saved from previous launches,
// do not connect again.
MAHandle myStore = maOpenStore("MyStore", 0);
if ( isAndroid() && myStore == STERR_NONEXISTENT
||
!isAndroid() )
{
// Add connection status label.
listItem = new ListViewItem;
listView->addChild(listItem);
mConnectionStatusLabel = new Label();
mConnectionStatusLabel->setText(CONNECTION_NOT_ESTABLISHED);
listItem->addChild(mConnectionStatusLabel);
listItem = new ListViewItem;
listView->addChild(listItem);
mConnectButton = new Button();
mConnectButton->setText(CONNECT_BUTTON_TEXT);
listItem->addChild(mConnectButton);
}
}
示例3: init
bool UIListViewTest_Vertical::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
Text* alert = Text::create("ListView vertical", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
Size backgroundSize = background->getContentSize();
// create list view ex data
for (int i = 0; i < 20; ++i)
{
std::string ccstr = StringUtils::format("listview_item_%d", i);
_array.push_back(ccstr);
}
// Create the list view ex
ListView* listView = ListView::create();
// set list view ex direction
listView->setDirection(ui::ScrollView::Direction::VERTICAL);
listView->setBounceEnabled(true);
listView->setBackGroundImage("cocosui/green_edit.png");
listView->setBackGroundImageScale9Enabled(true);
listView->setContentSize(Size(240, 130));
listView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
(backgroundSize.width - listView->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - listView->getContentSize().height) / 2.0f));
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
//.........这里部分代码省略.........
示例4: init
bool UIListViewTest_Vertical::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
Text* alert = Text::create("ListView vertical", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
Size backgroundSize = background->getContentSize();
// create list view ex data
for (int i = 0; i < 20; ++i)
{
std::string ccstr = StringUtils::format("listview_item_%d", i);
_array.push_back(ccstr);
}
// Create the list view ex
ListView* listView = ListView::create();
// set list view ex direction
listView->setDirection(ui::ScrollView::Direction::VERTICAL);
listView->setBounceEnabled(true);
listView->setBackGroundImage("cocosui/green_edit.png");
listView->setBackGroundImageScale9Enabled(true);
listView->setContentSize(Size(240, 130));
listView->setPosition(Vec2((widgetSize - listView->getContentSize()) / 2.0f));
listView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEvent, this));
listView->addEventListener((ui::ListView::ccScrollViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEventScrollView,this));
listView->setScrollBarPositionFromCorner(Vec2(7, 7));
_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() / 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)
{
//.........这里部分代码省略.........
示例5: ShowItemList
//.........这里部分代码省略.........
lview = layout_Center->getChildByName<ListView*>("LView_DropOut");
}
lview->removeAllChildren();
for (auto iter = itemVect->begin(); iter != itemVect->end(); iter++)
{
auto itemId = iter->first;
auto itemNum = iter->second;
auto layout_BtnItem = Layout_BtnItem->clone();
auto btn_Item = layout_BtnItem->getChildByName<Button*>("Btn_Item");
btn_Item->addClickEventListener([this, direction, itemId](Ref* sender)
{
if (direction)
{
// 不占据背包空间物品不能丢弃
if (CfgDataRow(itemId).GetValue(CfgField::NonSpace)->asInt() == 0) {
return;
}
auto iter = m_BagItem->begin();
while (iter != m_BagItem->end())
{
if(iter->first == itemId)
{
break;
}
iter++;
}
if (iter != m_BagItem->end())
{
iter->second -= 1;
if(iter->second == 0)
{
m_BagItem->erase(iter);
}
iter = m_DropItem->begin();
while (iter != m_DropItem->end())
{
if(iter->first == itemId)
{
break;
}
iter++;
}
if(iter == m_DropItem->end())
{
m_DropItem->push_back(pair<int, int>( itemId, 1));
}else
{
iter->second += 1;
}
}
}else
{
//判断是否金币
if (itemId == (int)CfgIdEnum::GoldId)
{
SaveGold();
}else
{
auto iter = m_DropItem->begin();
while (iter != m_DropItem->end())
{
if(iter->first == itemId)
{
break;
}
iter++;
}
if (iter != m_DropItem->end())
{
if (IsSaveBag(itemId))
{
iter->second -= 1;
if(iter->second == 0)
{
m_DropItem->erase(iter);
}
}
}
}
}
ShowItemList(m_BagItem, true);
ShowItemList(m_DropItem, false);
});
auto text_Name = layout_BtnItem->getChildByName<Text*>("Text_ItemName");
CfgDataRow dataRow(itemId);
auto langId = dataRow.GetValue(CfgField::Name)->asInt();
auto langText = MultiLanguage::getInstance()->GetText(langId);
text_Name->setString(langText);
auto text_Num = layout_BtnItem->getChildByName<Text*>("Text_ItemNum");
text_Num->setString(StringUtils::format("x%d", itemNum));
lview->addChild(layout_BtnItem);
UpdateBagItemNum();
}
}
示例6: createMainLayout
/**
* Creates and adds main layout to the screen.
*/
void CreateNotificationScreen::createMainLayout()
{
VerticalLayout* mainLayout = new VerticalLayout();
Screen::setMainWidget(mainLayout);
ListView* listView = new ListView();
listView->fillSpaceHorizontally();
listView->fillSpaceVertically();
mainLayout->addChild(listView);
ListViewItem* listItem;
HorizontalLayout* hLayout;
Widget* space;
// ================ Content body =====================
mContentBody = new EditBox();
listView->addChild(createListViewItem(CONTENT_BODY_LABEL_TEXT,(Widget*) mContentBody));
if ( isAndroid() )
{
// ================ Content title =====================
mContentTitle = new EditBox();
listView->addChild(createListViewItem(CONTENT_TITLE_LABEL_TEXT, mContentTitle));
// ================ Ticker text =====================
mTickerText = new EditBox();
listView->addChild(createListViewItem(TICKER_TEXT_LABEL_TEXT, mTickerText));
}
else
{
// ================ Badge number =====================
mBadgeNumber = new EditBox();
mBadgeNumber->setWidth(NUMERIC_EDIT_BOX_WIDTH);
mBadgeNumber->setInputMode(EDIT_BOX_INPUT_MODE_NUMERIC);
mBadgeNumber->addEditBoxListener(this);
listView->addChild(createListViewItem(BADGE_NUMBER_LABEL_TEXT, mBadgeNumber));
// ================ Alert action =====================
mAlertAction = new EditBox();
mAlertAction->addEditBoxListener(this);
listView->addChild(createListViewItem(ALERT_ACTION_LABEL_TEXT, mAlertAction));
}
// ================ Play sound =====================
mPlaySound = new CheckBox();
listView->addChild(createListViewItem(PLAY_SOUND_LABEL_TEXT, mPlaySound));
if ( isAndroid() )
{
// ================ Sound path=====================
mSoundPath = new EditBox();
listView->addChild(createListViewItem(SOUND_PATH_LABEL_TEXT, mSoundPath));
// ================ Vibrate =====================
mVibrate = new CheckBox();
listView->addChild(createListViewItem(VIBRATE_LABEL_TEXT, mVibrate));
mVibrateDuration = new EditBox();
mVibrateDuration->setInputMode(EDIT_BOX_INPUT_MODE_NUMERIC);
listView->addChild(createListViewItem(VIBRATE_DURATION_LABEL_TEXT, mVibrateDuration));
// ================ Flashing LED =====================
mFlash = new CheckBox();
listView->addChild(createListViewItem(FLASH_LABEL_TEXT, mFlash));
// The pattern
mFlashColor = new EditBox();
listView->addChild(createListViewItem(FLASH_COLOR_LABEL_TEXT, mFlashColor));
mFlashOnLength = new EditBox();
mFlashOnLength->setInputMode(EDIT_BOX_INPUT_MODE_NUMERIC);
listView->addChild(createListViewItem(FLASH_ON_LABEL_TEXT, mFlashOnLength));
mFlashOffLength = new EditBox();
mFlashOffLength->setInputMode(EDIT_BOX_INPUT_MODE_NUMERIC);
listView->addChild(createListViewItem(FLASH_OFF_LABEL_TEXT, mFlashOffLength));
}
// ================ Fire time =====================
mTime = new EditBox();
mTime->setWidth(NUMERIC_EDIT_BOX_WIDTH);
mTime->setInputMode(EDIT_BOX_INPUT_MODE_NUMERIC);
listView->addChild(createListViewItem(FIRE_TIME_LABEL_TEXT, mTime));
// ================= Send image button ================
hLayout = new HorizontalLayout();
hLayout->fillSpaceHorizontally();
listItem = new ListViewItem();
listItem->addChild(hLayout);
listView->addChild(listItem);
mCreateNotificationButton = new ImageButton();
mCreateNotificationButton->setImage(RES_IMAGE);
space = this->createSpacer();
hLayout->addChild(space);
hLayout->addChild(mCreateNotificationButton);
// Align the image button at the center of the layout.
// Only after adding the image button widget to layout the widget's width
//.........这里部分代码省略.........