mirror of https://github.com/axmolengine/axmol.git
issue #5183, refactor
This commit is contained in:
parent
e0192e2a1b
commit
432f688a67
|
@ -929,12 +929,12 @@ void Layout::requestDoLayout()
|
||||||
_doLayoutDirty = true;
|
_doLayoutDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Size Layout::getLayoutSize()
|
const Size Layout::getLayoutContentSize()
|
||||||
{
|
{
|
||||||
return this->getSize();
|
return this->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<Node*>& Layout::getLayoutChildren()
|
const Vector<Node*>& Layout::getLayoutElements()
|
||||||
{
|
{
|
||||||
return this->getChildren();
|
return this->getChildren();
|
||||||
}
|
}
|
||||||
|
@ -1031,7 +1031,7 @@ bool Layout::isPassFocusToChild()
|
||||||
return _passFocusToChild;
|
return _passFocusToChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size Layout::getLayoutContentSize()const
|
Size Layout::getLayoutAccumulatedSize()const
|
||||||
{
|
{
|
||||||
const auto& children = this->getChildren();
|
const auto& children = this->getChildren();
|
||||||
Size layoutSize = Size::ZERO;
|
Size layoutSize = Size::ZERO;
|
||||||
|
@ -1041,7 +1041,7 @@ Size Layout::getLayoutContentSize()const
|
||||||
Layout *layout = dynamic_cast<Layout*>(widget);
|
Layout *layout = dynamic_cast<Layout*>(widget);
|
||||||
if (nullptr != layout)
|
if (nullptr != layout)
|
||||||
{
|
{
|
||||||
layoutSize = layoutSize + layout->getLayoutContentSize();
|
layoutSize = layoutSize + layout->getLayoutAccumulatedSize();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1072,7 +1072,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)
|
||||||
{
|
{
|
||||||
Layout *layout = dynamic_cast<Layout*>(widget);
|
Layout *layout = dynamic_cast<Layout*>(widget);
|
||||||
//FIXEDME: we don't need to calculate the content size of layout anymore
|
//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);
|
// CCLOG("contnet size : width = %f, height = %f", widgetSize.width, widgetSize.height);
|
||||||
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
|
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ public:
|
||||||
virtual ~LayoutProtocol(){}
|
virtual ~LayoutProtocol(){}
|
||||||
|
|
||||||
virtual LayoutExecutant* createLayoutExecutant() = 0;
|
virtual LayoutExecutant* createLayoutExecutant() = 0;
|
||||||
virtual const Size getLayoutSize() = 0;
|
virtual const Size getLayoutContentSize() = 0;
|
||||||
virtual const Vector<Node*>& getLayoutChildren() = 0;
|
virtual const Vector<Node*>& getLayoutElements() = 0;
|
||||||
virtual void doLayout() = 0;
|
virtual void doLayout() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -329,8 +329,8 @@ protected:
|
||||||
|
|
||||||
virtual void doLayout()override;
|
virtual void doLayout()override;
|
||||||
virtual LayoutExecutant* createLayoutExecutant()override;
|
virtual LayoutExecutant* createLayoutExecutant()override;
|
||||||
virtual const Size getLayoutSize()override;
|
virtual const Size getLayoutContentSize()override;
|
||||||
virtual const Vector<Node*>& getLayoutChildren() override;
|
virtual const Vector<Node*>& getLayoutElements() override;
|
||||||
|
|
||||||
//clipping
|
//clipping
|
||||||
void onBeforeVisitStencil();
|
void onBeforeVisitStencil();
|
||||||
|
@ -346,7 +346,7 @@ protected:
|
||||||
/**
|
/**
|
||||||
*get the content size of the layout, it will accumulate all its children's content size
|
*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
|
* When the layout get focused, it the layout pass the focus to its child, it will use this method to determine which child
|
||||||
|
|
|
@ -67,8 +67,8 @@ RelativeLayoutExecutant* RelativeLayoutExecutant::create()
|
||||||
|
|
||||||
void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
||||||
{
|
{
|
||||||
Size layoutSize = layout->getLayoutSize();
|
Size layoutSize = layout->getLayoutContentSize();
|
||||||
Vector<Node*> container = layout->getLayoutChildren();
|
Vector<Node*> container = layout->getLayoutElements();
|
||||||
float topBoundary = layoutSize.height;
|
float topBoundary = layoutSize.height;
|
||||||
|
|
||||||
for (auto& subWidget : container)
|
for (auto& subWidget : container)
|
||||||
|
@ -111,8 +111,8 @@ void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
||||||
|
|
||||||
void LinearHorizontalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
void LinearHorizontalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
||||||
{
|
{
|
||||||
Size layoutSize = layout->getLayoutSize();
|
Size layoutSize = layout->getLayoutContentSize();
|
||||||
Vector<Node*> container = layout->getLayoutChildren();
|
Vector<Node*> container = layout->getLayoutElements();
|
||||||
float leftBoundary = 0.0f;
|
float leftBoundary = 0.0f;
|
||||||
for (auto& subWidget : container)
|
for (auto& subWidget : container)
|
||||||
{
|
{
|
||||||
|
@ -153,8 +153,8 @@ void LinearHorizontalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
||||||
|
|
||||||
void RelativeLayoutExecutant::doLayout(LayoutProtocol *layout)
|
void RelativeLayoutExecutant::doLayout(LayoutProtocol *layout)
|
||||||
{
|
{
|
||||||
Size layoutSize = layout->getLayoutSize();
|
Size layoutSize = layout->getLayoutContentSize();
|
||||||
Vector<Node*> container = layout->getLayoutChildren();
|
Vector<Node*> container = layout->getLayoutElements();
|
||||||
ssize_t unlayoutChildCount = 0;
|
ssize_t unlayoutChildCount = 0;
|
||||||
Vector<Widget*> widgetChildren;
|
Vector<Widget*> widgetChildren;
|
||||||
for (auto& subWidget : container)
|
for (auto& subWidget : container)
|
||||||
|
|
|
@ -50,6 +50,18 @@ ScrollInnerContainer* ScrollInnerContainer::create()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Size& ScrollInnerContainer::getLayoutSize()
|
||||||
|
{
|
||||||
|
Widget* parent = getWidgetParent();
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
return parent->getSize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const float AUTOSCROLLMAXSPEED = 1000.0f;
|
static const float AUTOSCROLLMAXSPEED = 1000.0f;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
ScrollInnerContainer();
|
ScrollInnerContainer();
|
||||||
virtual ~ScrollInnerContainer();
|
virtual ~ScrollInnerContainer();
|
||||||
static ScrollInnerContainer* create();
|
static ScrollInnerContainer* create();
|
||||||
|
virtual const Size& getLayoutSize() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef enum
|
CC_DEPRECATED_ATTRIBUTE typedef enum
|
||||||
|
|
|
@ -441,7 +441,7 @@ public:
|
||||||
|
|
||||||
const Size& getCustomSize() const;
|
const Size& getCustomSize() const;
|
||||||
|
|
||||||
//virtual const Size& getLayoutSize() {return _size;};
|
virtual const Size& getLayoutSize() {return _size;};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns size percent of widget
|
* Returns size percent of widget
|
||||||
|
|
Loading…
Reference in New Issue