diff --git a/cocos/gui/UIHelper.cpp b/cocos/gui/UIHelper.cpp index 814a4bdf53..2d9264cb4a 100644 --- a/cocos/gui/UIHelper.cpp +++ b/cocos/gui/UIHelper.cpp @@ -38,7 +38,7 @@ Widget* UIHelper::seekWidgetByTag(Widget* root, int tag) { return root; } - Vector arrayRootChildren = root->getChildren(); + const auto& arrayRootChildren = root->getChildren(); int length = arrayRootChildren.size(); for (int i=0;i arrayRootChildren = root->getChildren(); - int length = arrayRootChildren.size(); - for (int i=0;igetChildren(); + for (auto& subWidget : arrayRootChildren) { - Widget* child = static_cast(arrayRootChildren.at(i)); + Widget* child = static_cast(subWidget); Widget* res = seekWidgetByName(child,name); if (res != nullptr) { @@ -82,11 +81,10 @@ Widget* UIHelper::seekWidgetByRelativeName(Widget *root, const char *name) { return nullptr; } - Vector arrayRootChildren = root->getChildren(); - int length = arrayRootChildren.size(); - for (int i=0;igetChildren(); + for (auto& subWidget : arrayRootChildren) { - Widget* child = static_cast(arrayRootChildren.at(i)); + Widget* child = static_cast(subWidget); RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); if (layoutParameter && strcmp(layoutParameter->getRelativeName(), name) == 0) { @@ -107,11 +105,10 @@ Widget* UIHelper::seekActionWidgetByActionTag(Widget* root, int tag) { return root; } - Vector arrayRootChildren = root->getChildren(); - int length = arrayRootChildren.size(); - for (int i=0;igetChildren(); + for (auto& subWidget : arrayRootChildren) { - Widget* child = static_cast(arrayRootChildren.at(i)); + Widget* child = static_cast(subWidget); Widget* res = seekActionWidgetByActionTag(child,tag); if (res != nullptr) { diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 29031e2a29..f63ddb2c0d 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -727,12 +727,12 @@ void Layout::doLayout() break; case LAYOUT_LINEAR_VERTICAL: { - int length = _widgetChildren.size(); Size layoutSize = getSize(); float topBoundary = layoutSize.height; - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); if (layoutParameter) @@ -767,12 +767,11 @@ void Layout::doLayout() } case LAYOUT_LINEAR_HORIZONTAL: { - int length = _widgetChildren.size(); Size layoutSize = getSize(); float leftBoundary = 0.0f; - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); if (layoutParameter) @@ -807,22 +806,19 @@ void Layout::doLayout() } case LAYOUT_RELATIVE: { - int length = _widgetChildren.size(); - int unlayoutChildCount = length; + int unlayoutChildCount = _widgetChildren.size(); Size layoutSize = getSize(); - - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); layoutParameter->_put = false; } - while (unlayoutChildCount > 0) { - for (int i=0; i(_widgetChildren.at(i)); + Widget* child = static_cast(subWidget); RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); if (layoutParameter) diff --git a/cocos/gui/UIListView.cpp b/cocos/gui/UIListView.cpp index a6cedbb287..5d608ac6dc 100644 --- a/cocos/gui/UIListView.cpp +++ b/cocos/gui/UIListView.cpp @@ -90,9 +90,8 @@ void ListView::updateInnerContainerSize() { int length = _items.size(); float totalHeight = (length - 1) * _itemsMargin; - for (int i=0; igetSize().height; } float finalWidth = _size.width; @@ -104,9 +103,8 @@ void ListView::updateInnerContainerSize() { int length = _items.size(); float totalWidth = (length - 1) * _itemsMargin; - for (int i=0; igetSize().width; } float finalWidth = totalWidth; @@ -446,12 +444,9 @@ Widget* ListView::createCloneInstance() void ListView::copyClonedWidgetChildren(Widget* model) { - Vector arrayItems = getItems(); - - int length = arrayItems.size(); - for (int i=0; iclone()); } } diff --git a/cocos/gui/UIPageView.cpp b/cocos/gui/UIPageView.cpp index 784fc31b8f..dcc0dbf593 100644 --- a/cocos/gui/UIPageView.cpp +++ b/cocos/gui/UIPageView.cpp @@ -181,7 +181,7 @@ void PageView::insertPage(Layout* page, int idx) page->setSize(pvSize); } int length = _pages.size(); - for (int i=(idx+1); igetPosition(); behindPage->setPosition(Point(formerPos.x+getSize().width, 0)); @@ -268,10 +268,8 @@ void PageView::onSizeChanged() void PageView::updateChildrenSize() { Size selfSize = getSize(); - int length = _pages.size(); - for (long i=0; isetSize(selfSize); } } @@ -410,13 +408,11 @@ void PageView::onTouchCancelled(Touch *touch, Event *unusedEvent) void PageView::movePages(float offset) { - int length = _pages.size(); - for (int i = 0; i < length; i++) + for (auto& page : _pages) { - Widget* child = _pages.at(i); - _movePagePoint.x = child->getPosition().x + offset; - _movePagePoint.y = child->getPosition().y; - child->setPosition(_movePagePoint); + _movePagePoint.x = page->getPosition().x + offset; + _movePagePoint.y = page->getPosition().y; + page->setPosition(_movePagePoint); } } @@ -606,11 +602,9 @@ Widget* PageView::createCloneInstance() void PageView::copyClonedWidgetChildren(Widget* model) { - Vector modelPages = dynamic_cast(model)->getPages(); - int length = modelPages.size(); - for (int i=0; i(model)->getPages(); + for (auto& page : modelPages) { - Layout* page = modelPages.at(i); addPage(dynamic_cast(page->clone())); } } diff --git a/cocos/gui/UIWidget.cpp b/cocos/gui/UIWidget.cpp index 58b3284119..495821cd99 100644 --- a/cocos/gui/UIWidget.cpp +++ b/cocos/gui/UIWidget.cpp @@ -977,10 +977,11 @@ Widget* Widget::createCloneInstance() void Widget::copyClonedWidgetChildren(Widget* model) { - int length = model->getChildren().size(); - for (int i=0; igetChildren(); + + for (auto& subWidget : modelChildren) { - Widget* child = static_cast(model->getChildren().at(i)); + Widget* child = static_cast(subWidget); addChild(child->clone()); } }