diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index f7ff08967f..751ec40741 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -929,12 +929,12 @@ void Layout::requestDoLayout() _doLayoutDirty = true; } -const Size Layout::getLayoutSize() +const Size Layout::getLayoutContentSize() { return this->getSize(); } -const Vector& Layout::getLayoutChildren() +const Vector& Layout::getLayoutElements() { return this->getChildren(); } @@ -1031,7 +1031,7 @@ bool Layout::isPassFocusToChild() return _passFocusToChild; } -Size Layout::getLayoutContentSize()const +Size Layout::getLayoutAccumulatedSize()const { const auto& children = this->getChildren(); Size layoutSize = Size::ZERO; @@ -1041,7 +1041,7 @@ Size Layout::getLayoutContentSize()const Layout *layout = dynamic_cast(widget); if (nullptr != layout) { - layoutSize = layoutSize + layout->getLayoutContentSize(); + layoutSize = layoutSize + layout->getLayoutAccumulatedSize(); } else { @@ -1072,7 +1072,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget) { Layout *layout = dynamic_cast(widget); //FIXEDME: we don't need to calculate the content size of layout anymore - Size widgetSize = layout ? layout->getLayoutContentSize() : widget->getSize(); + Size widgetSize = layout ? layout->getLayoutAccumulatedSize() : widget->getSize(); // CCLOG("contnet size : width = %f, height = %f", widgetSize.width, widgetSize.height); return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2)); } diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index 497a33b229..cb4c0f37e3 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -40,8 +40,8 @@ public: virtual ~LayoutProtocol(){} virtual LayoutExecutant* createLayoutExecutant() = 0; - virtual const Size getLayoutSize() = 0; - virtual const Vector& getLayoutChildren() = 0; + virtual const Size getLayoutContentSize() = 0; + virtual const Vector& getLayoutElements() = 0; virtual void doLayout() = 0; }; @@ -329,8 +329,8 @@ protected: virtual void doLayout()override; virtual LayoutExecutant* createLayoutExecutant()override; - virtual const Size getLayoutSize()override; - virtual const Vector& getLayoutChildren() override; + virtual const Size getLayoutContentSize()override; + virtual const Vector& getLayoutElements() override; //clipping void onBeforeVisitStencil(); @@ -346,7 +346,7 @@ protected: /** *get the content size of the layout, it will accumulate all its children's content size */ - Size getLayoutContentSize() const; + Size getLayoutAccumulatedSize() const; /** * When the layout get focused, it the layout pass the focus to its child, it will use this method to determine which child diff --git a/cocos/ui/UILayoutExecutant.cpp b/cocos/ui/UILayoutExecutant.cpp index 5bd30dc4b6..30ac2f2e0b 100644 --- a/cocos/ui/UILayoutExecutant.cpp +++ b/cocos/ui/UILayoutExecutant.cpp @@ -67,8 +67,8 @@ RelativeLayoutExecutant* RelativeLayoutExecutant::create() void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout) { - Size layoutSize = layout->getLayoutSize(); - Vector container = layout->getLayoutChildren(); + Size layoutSize = layout->getLayoutContentSize(); + Vector container = layout->getLayoutElements(); float topBoundary = layoutSize.height; for (auto& subWidget : container) @@ -111,8 +111,8 @@ void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout) void LinearHorizontalLayoutExecutant::doLayout(LayoutProtocol* layout) { - Size layoutSize = layout->getLayoutSize(); - Vector container = layout->getLayoutChildren(); + Size layoutSize = layout->getLayoutContentSize(); + Vector container = layout->getLayoutElements(); float leftBoundary = 0.0f; for (auto& subWidget : container) { @@ -153,8 +153,8 @@ void LinearHorizontalLayoutExecutant::doLayout(LayoutProtocol* layout) void RelativeLayoutExecutant::doLayout(LayoutProtocol *layout) { - Size layoutSize = layout->getLayoutSize(); - Vector container = layout->getLayoutChildren(); + Size layoutSize = layout->getLayoutContentSize(); + Vector container = layout->getLayoutElements(); ssize_t unlayoutChildCount = 0; Vector widgetChildren; for (auto& subWidget : container) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 07d1c976b1..601dca158f 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -50,6 +50,18 @@ ScrollInnerContainer* ScrollInnerContainer::create() return nullptr; } +const Size& ScrollInnerContainer::getLayoutSize() +{ + Widget* parent = getWidgetParent(); + if (parent) + { + return parent->getSize(); + } + else + { + return _size; + } +} static const float AUTOSCROLLMAXSPEED = 1000.0f; diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 8009c6d071..57c94326f9 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -38,6 +38,7 @@ public: ScrollInnerContainer(); virtual ~ScrollInnerContainer(); static ScrollInnerContainer* create(); + virtual const Size& getLayoutSize() override; }; CC_DEPRECATED_ATTRIBUTE typedef enum diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 718336168f..e333a3da59 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -441,7 +441,7 @@ public: const Size& getCustomSize() const; - //virtual const Size& getLayoutSize() {return _size;}; + virtual const Size& getLayoutSize() {return _size;}; /** * Returns size percent of widget