issue #5183, refactor

This commit is contained in:
andyque 2014-05-20 10:16:19 +08:00
parent e0192e2a1b
commit 432f688a67
6 changed files with 30 additions and 17 deletions

View File

@ -929,12 +929,12 @@ void Layout::requestDoLayout()
_doLayoutDirty = true;
}
const Size Layout::getLayoutSize()
const Size Layout::getLayoutContentSize()
{
return this->getSize();
}
const Vector<Node*>& Layout::getLayoutChildren()
const Vector<Node*>& 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<Layout*>(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<Layout*>(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));
}

View File

@ -40,8 +40,8 @@ public:
virtual ~LayoutProtocol(){}
virtual LayoutExecutant* createLayoutExecutant() = 0;
virtual const Size getLayoutSize() = 0;
virtual const Vector<Node*>& getLayoutChildren() = 0;
virtual const Size getLayoutContentSize() = 0;
virtual const Vector<Node*>& 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<Node*>& getLayoutChildren() override;
virtual const Size getLayoutContentSize()override;
virtual const Vector<Node*>& 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

View File

@ -67,8 +67,8 @@ RelativeLayoutExecutant* RelativeLayoutExecutant::create()
void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout)
{
Size layoutSize = layout->getLayoutSize();
Vector<Node*> container = layout->getLayoutChildren();
Size layoutSize = layout->getLayoutContentSize();
Vector<Node*> 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<Node*> container = layout->getLayoutChildren();
Size layoutSize = layout->getLayoutContentSize();
Vector<Node*> 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<Node*> container = layout->getLayoutChildren();
Size layoutSize = layout->getLayoutContentSize();
Vector<Node*> container = layout->getLayoutElements();
ssize_t unlayoutChildCount = 0;
Vector<Widget*> widgetChildren;
for (auto& subWidget : container)

View File

@ -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;

View File

@ -38,6 +38,7 @@ public:
ScrollInnerContainer();
virtual ~ScrollInnerContainer();
static ScrollInnerContainer* create();
virtual const Size& getLayoutSize() override;
};
CC_DEPRECATED_ATTRIBUTE typedef enum

View File

@ -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