diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp index 7765f3e2ad..e2774b2021 100644 --- a/cocos/ui/UIPageView.cpp +++ b/cocos/ui/UIPageView.cpp @@ -173,9 +173,12 @@ void PageView::insertPage(Layout* page, int idx) else { _protectedChildren.insert(idx, page); + page->setParent(this); + page->setPosition(Vec2(getPositionXByIndex(idx), 0)); Size pSize = page->getSize(); Size pvSize = getSize(); + if (!pSize.equals(pvSize)) { CCLOG("page size does not match pageview size, it will be force sized!"); @@ -248,8 +251,11 @@ void PageView::updateChildrenSize() Size selfSize = getSize(); for (auto& page : _protectedChildren) { + //FIXME: should call node->setContentSize Layout* layout = dynamic_cast(page); - layout->setSize(selfSize); + if (layout) { + layout->setSize(selfSize); + } } } @@ -269,7 +275,9 @@ void PageView::updateChildrenPosition() for (int i=0; i(_protectedChildren.at(i)); - page->setPosition(Vec2((i-_curPageIdx)*pageWidth, 0)); + if (page) { + page->setPosition(Vec2((i-_curPageIdx)*pageWidth, 0)); + } } } diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 09d0275ab8..6ced67ce97 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -258,12 +258,12 @@ const Size& ScrollView::getInnerContainerSize() const void ScrollView::addChild(Node *child) { - Layout::addChild(child); + ScrollView::addChild(child, child->getZOrder(), child->getTag()); } void ScrollView::addChild(Node * child, int zOrder) { - Layout::addChild(child, zOrder); + ScrollView::addChild(child, zOrder, child->getTag()); } void ScrollView::addChild(Node *child, int zOrder, int tag) diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 754e006290..448f906c9d 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -260,46 +260,21 @@ public: */ CC_DEPRECATED_ATTRIBUTE void addEventListenerScrollView(Ref* target, SEL_ScrollViewEvent selector); void addEventListener(const ccScrollViewCallback& callback); - + + //all of these functions are related to innerContainer. virtual void addChild(Node * child) override; - /** - * Adds a child to the container with a z-order - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) - */ virtual void addChild(Node * child, int zOrder) override; - /** - * Adds a child to the container with z order and tag - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @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, int zOrder, int tag) override; - - //override "removeAllChildrenAndCleanUp" method of widget. virtual void removeAllChildren() override; - virtual void removeAllChildrenWithCleanup(bool cleanup) override; - - //override "removeChild" method of widget. virtual void removeChild(Node* child, bool cleaup = true) override; - - //override "getChildren" method of widget. virtual Vector& getChildren() override; virtual const Vector& getChildren() const override; - virtual ssize_t getChildrenCount() const override; - virtual Node * getChildByTag(int tag) const override; - virtual Widget* getChildByName(const std::string& name) override; + //handle touch event virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index 55364c7fbb..66a1e79989 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -47,7 +47,10 @@ bool UIPageViewTest::init() (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - pageView->getSize().height) / 2.0f)); - for (int i = 0; i < 3; ++i) + pageView->removeAllPages(); + + int pageCount = 4; + for (int i = 0; i < pageCount; ++i) { Layout* layout = Layout::create(); layout->setSize(Size(240.0f, 130.0f)); @@ -63,8 +66,12 @@ bool UIPageViewTest::init() label->setPosition(Vec2(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(label); - pageView->addPage(layout); + pageView->insertPage(layout,i); } + + pageView->removePageAtIndex(0); + pageView->scrollToPage(pageCount-2); + pageView->addEventListener(CC_CALLBACK_2(UIPageViewTest::pageViewEvent, this)); _uiLayer->addChild(pageView);