diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 0d4be2801f..f33591a81c 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -152,6 +152,16 @@ bool Layout::init() } return false; } + +void Layout::addChild(Node* child) +{ + Layout::addChild(child, child->getLocalZOrder(), child->getTag()); +} + +void Layout::addChild(Node * child, int localZOrder) +{ + Layout::addChild(child, localZOrder, child->getTag()); +} void Layout::addChild(Node *child, int zOrder, int tag) { diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index c19af1c617..2278e64564 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -232,7 +232,6 @@ public: virtual Type getLayoutType() const; - using Node::addChild; /** * Adds a child to the container with z order and tag * @@ -242,6 +241,8 @@ public: * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ + virtual void addChild(Node* child)override; + virtual void addChild(Node * child, int localZOrder)override; virtual void addChild(Node* child, int zOrder, int tag) override; virtual void addChild(Node* child, int zOrder, const std::string &name) override; diff --git a/cocos/ui/UIListView.cpp b/cocos/ui/UIListView.cpp index a795a41d9d..da6f993446 100644 --- a/cocos/ui/UIListView.cpp +++ b/cocos/ui/UIListView.cpp @@ -272,6 +272,7 @@ void ListView::insertDefaultItem(ssize_t index) _refreshViewDirty = true; } + void ListView::pushBackCustomItem(Widget* item) { remedyLayoutParameter(item); @@ -289,6 +290,16 @@ void ListView::addChild(cocos2d::Node *child, int zOrder, int tag) _items.pushBack(widget); } } + +void ListView::addChild(cocos2d::Node *child) +{ + ListView::addChild(child, child->getLocalZOrder(), child->getName()); +} + +void ListView::addChild(cocos2d::Node *child, int zOrder) +{ + ListView::addChild(child, zOrder, child->getName()); +} void ListView::addChild(Node* child, int zOrder, const std::string &name) { diff --git a/cocos/ui/UIListView.h b/cocos/ui/UIListView.h index 4635e2182e..42a4d5050d 100644 --- a/cocos/ui/UIListView.h +++ b/cocos/ui/UIListView.h @@ -163,7 +163,8 @@ public: virtual void doLayout() override; - using ScrollView::addChild; + virtual void addChild(Node* child)override; + virtual void addChild(Node * child, int localZOrder)override; virtual void addChild(Node* child, int zOrder, int tag) override; virtual void addChild(Node* child, int zOrder, const std::string &name) override; virtual void removeAllChildren() override; diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 4dd4149af2..ef1993621d 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -229,6 +229,16 @@ const Size& ScrollView::getInnerContainerSize() const { return _innerContainer->getContentSize(); } + +void ScrollView::addChild(Node* child) +{ + ScrollView::addChild(child, child->getLocalZOrder(), child->getTag()); +} + +void ScrollView::addChild(Node * child, int localZOrder) +{ + ScrollView::addChild(child, localZOrder, child->getTag()); +} void ScrollView::addChild(Node *child, int zOrder, int tag) { diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index fbd0d684f0..39ec4dc8bd 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -254,12 +254,15 @@ public: virtual void addEventListener(const ccScrollViewCallback& callback); //all of these functions are related to innerContainer. - using Layout::addChild; + virtual void addChild(Node* child)override; + virtual void addChild(Node * child, int localZOrder)override; virtual void addChild(Node* child, int zOrder, int tag) override; virtual void addChild(Node* child, int zOrder, const std::string &name) override; + virtual void removeAllChildren() override; virtual void removeAllChildrenWithCleanup(bool cleanup) override; virtual void removeChild(Node* child, bool cleaup = true) override; + virtual Vector& getChildren() override; virtual const Vector& getChildren() const override; virtual ssize_t getChildrenCount() const override; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 7c39e5bc00..f10366869d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -8,14 +8,12 @@ const char* font_UIListViewTest = "fonts/Marker Felt.ttf"; UIListViewTest_Vertical::UIListViewTest_Vertical() : _displayValueLabel(nullptr) -, _array(nullptr) { } UIListViewTest_Vertical::~UIListViewTest_Vertical() { - CC_SAFE_RELEASE(_array); } bool UIListViewTest_Vertical::init() @@ -44,12 +42,11 @@ bool UIListViewTest_Vertical::init() // create list view ex data - _array = Array::create(); - CC_SAFE_RETAIN(_array); + for (int i = 0; i < 20; ++i) { - __String* ccstr = __String::createWithFormat("listview_item_%d", i); - _array->addObject(ccstr); + std::string ccstr = StringUtils::format("listview_item_%d", i); + _array.push_back(ccstr); } @@ -86,7 +83,7 @@ bool UIListViewTest_Vertical::init() listView->setItemModel(default_item); // add default item - ssize_t count = _array->count(); + ssize_t count = _array.size(); for (int i = 0; i < count / 4; ++i) { listView->pushBackDefaultItem(); @@ -144,7 +141,7 @@ bool UIListViewTest_Vertical::init() Widget* item = listView->getItem(i); Button* button = static_cast(item->getChildByName("Title Button")); ssize_t index = listView->getIndex(item); - button->setTitleText(static_cast<__String*>(_array->getObjectAtIndex(index))->getCString()); + button->setTitleText(_array[index]); } // remove last item @@ -208,13 +205,11 @@ void UIListViewTest_Vertical::selectedItemEventScrollView(Ref* pSender, ui::Scro UIListViewTest_Horizontal::UIListViewTest_Horizontal() : _displayValueLabel(nullptr) -, _array(nullptr) { } UIListViewTest_Horizontal::~UIListViewTest_Horizontal() { - CC_SAFE_RELEASE(_array); } bool UIListViewTest_Horizontal::init() @@ -244,12 +239,11 @@ bool UIListViewTest_Horizontal::init() // create list view ex data - _array = Array::create(); - CC_SAFE_RETAIN(_array); + for (int i = 0; i < 20; ++i) { - __String* ccstr = __String::createWithFormat("listview_item_%d", i); - _array->addObject(ccstr); + std::string ccstr = StringUtils::format("listview_item_%d", i); + _array.push_back(ccstr); } @@ -284,7 +278,7 @@ bool UIListViewTest_Horizontal::init() listView->setItemModel(default_item); // add default item - ssize_t count = _array->count(); + ssize_t count = _array.size(); for (int i = 0; i < count / 4; ++i) { listView->pushBackDefaultItem(); @@ -335,7 +329,7 @@ bool UIListViewTest_Horizontal::init() Widget *item = listView->getItem(i); Button *button = static_cast(item->getChildByName("Title Button")); ssize_t index = listView->getIndex(item); - button->setTitleText(static_cast<__String*>(_array->getObjectAtIndex(index))->getCString()); + button->setTitleText(_array[index]); } // remove last item listView->removeLastItem(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h index dfaab5f559..72e7382f5c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h @@ -41,7 +41,7 @@ protected: UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical) Text* _displayValueLabel; - __Array* _array; + std::vector _array; }; class UIListViewTest_Horizontal : public UIScene @@ -57,7 +57,7 @@ protected: UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal) Text* _displayValueLabel; - __Array* _array; + std::vector _array; }; #endif /* defined(__TestCpp__UIListViewTest__) */