mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6914 from andyque/refactorLayoutExecutant
refactor: rename UILayoutExecutant to UILayoutManager
This commit is contained in:
commit
3d3fb6ad7e
|
@ -973,10 +973,10 @@
|
||||||
2905FA8E18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
|
2905FA8E18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
|
||||||
2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
|
2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
|
||||||
2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; };
|
2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; };
|
||||||
29CB8F4C1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */; };
|
29CB8F4C1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */; };
|
||||||
29CB8F4D1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */; };
|
29CB8F4D1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */; };
|
||||||
29CB8F4E1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */; };
|
29CB8F4E1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; };
|
||||||
29CB8F4F1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */; };
|
29CB8F4F1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; };
|
||||||
29CB8F551929D7A900C841D6 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F541929D7A900C841D6 /* UIScrollInterface.h */; };
|
29CB8F551929D7A900C841D6 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F541929D7A900C841D6 /* UIScrollInterface.h */; };
|
||||||
29CB8F561929D7A900C841D6 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F541929D7A900C841D6 /* UIScrollInterface.h */; };
|
29CB8F561929D7A900C841D6 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F541929D7A900C841D6 /* UIScrollInterface.h */; };
|
||||||
2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; };
|
2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; };
|
||||||
|
@ -2256,8 +2256,8 @@
|
||||||
29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; };
|
29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; };
|
||||||
2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = "<group>"; };
|
2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = "<group>"; };
|
||||||
2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; };
|
2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; };
|
||||||
29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutExecutant.cpp; sourceTree = "<group>"; };
|
29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutManager.cpp; sourceTree = "<group>"; };
|
||||||
29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutExecutant.h; sourceTree = "<group>"; };
|
29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutManager.h; sourceTree = "<group>"; };
|
||||||
29CB8F541929D7A900C841D6 /* UIScrollInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollInterface.h; sourceTree = "<group>"; };
|
29CB8F541929D7A900C841D6 /* UIScrollInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollInterface.h; sourceTree = "<group>"; };
|
||||||
2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = "<group>"; };
|
2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = "<group>"; };
|
||||||
2AC795D418628672005EC8E1 /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundingBoxAttachment.h; sourceTree = "<group>"; };
|
2AC795D418628672005EC8E1 /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundingBoxAttachment.h; sourceTree = "<group>"; };
|
||||||
|
@ -3932,8 +3932,8 @@
|
||||||
2905F9F918CF08D000240AA3 /* UILayout.h */,
|
2905F9F918CF08D000240AA3 /* UILayout.h */,
|
||||||
2905F9FC18CF08D000240AA3 /* UILayoutParameter.cpp */,
|
2905F9FC18CF08D000240AA3 /* UILayoutParameter.cpp */,
|
||||||
2905F9FD18CF08D000240AA3 /* UILayoutParameter.h */,
|
2905F9FD18CF08D000240AA3 /* UILayoutParameter.h */,
|
||||||
29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */,
|
29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */,
|
||||||
29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */,
|
29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */,
|
||||||
);
|
);
|
||||||
name = layout;
|
name = layout;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -4846,7 +4846,7 @@
|
||||||
5034CA39191D591100CE6051 /* ccShader_PositionColorLengthTexture.frag in Headers */,
|
5034CA39191D591100CE6051 /* ccShader_PositionColorLengthTexture.frag in Headers */,
|
||||||
2AC795DF18628723005EC8E1 /* SkeletonBounds.h in Headers */,
|
2AC795DF18628723005EC8E1 /* SkeletonBounds.h in Headers */,
|
||||||
50ABBE891925AB6F00A911A9 /* CCMap.h in Headers */,
|
50ABBE891925AB6F00A911A9 /* CCMap.h in Headers */,
|
||||||
29CB8F4E1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */,
|
29CB8F4E1929D1BB00C841D6 /* UILayoutManager.h in Headers */,
|
||||||
2AC795E018628723005EC8E1 /* Event.h in Headers */,
|
2AC795E018628723005EC8E1 /* Event.h in Headers */,
|
||||||
2AC795E118628723005EC8E1 /* EventData.h in Headers */,
|
2AC795E118628723005EC8E1 /* EventData.h in Headers */,
|
||||||
50E6D33618E174130051CA34 /* UIHBox.h in Headers */,
|
50E6D33618E174130051CA34 /* UIHBox.h in Headers */,
|
||||||
|
@ -5661,7 +5661,7 @@
|
||||||
1A8C59E2180E930E00EF57C3 /* CCInputDelegate.h in Headers */,
|
1A8C59E2180E930E00EF57C3 /* CCInputDelegate.h in Headers */,
|
||||||
503DD8EA1926736A00CD74DD /* CCESRenderer.h in Headers */,
|
503DD8EA1926736A00CD74DD /* CCESRenderer.h in Headers */,
|
||||||
1A8C59E6180E930E00EF57C3 /* CCProcessBase.h in Headers */,
|
1A8C59E6180E930E00EF57C3 /* CCProcessBase.h in Headers */,
|
||||||
29CB8F4F1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */,
|
29CB8F4F1929D1BB00C841D6 /* UILayoutManager.h in Headers */,
|
||||||
50ABBE581925AB6F00A911A9 /* CCEventFocus.h in Headers */,
|
50ABBE581925AB6F00A911A9 /* CCEventFocus.h in Headers */,
|
||||||
50ABC00A1926664800A911A9 /* CCCommon.h in Headers */,
|
50ABC00A1926664800A911A9 /* CCCommon.h in Headers */,
|
||||||
2905FA5918CF08D100240AA3 /* UILayout.h in Headers */,
|
2905FA5918CF08D100240AA3 /* UILayout.h in Headers */,
|
||||||
|
@ -6242,7 +6242,7 @@
|
||||||
2905FA4018CF08D100240AA3 /* CocosGUI.cpp in Sources */,
|
2905FA4018CF08D100240AA3 /* CocosGUI.cpp in Sources */,
|
||||||
1AD71EC1180E26E600808F54 /* extension.cpp in Sources */,
|
1AD71EC1180E26E600808F54 /* extension.cpp in Sources */,
|
||||||
50ABBE511925AB6F00A911A9 /* CCEventDispatcher.cpp in Sources */,
|
50ABBE511925AB6F00A911A9 /* CCEventDispatcher.cpp in Sources */,
|
||||||
29CB8F4C1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */,
|
29CB8F4C1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */,
|
||||||
50ABC0051926664800A911A9 /* CCThread.mm in Sources */,
|
50ABC0051926664800A911A9 /* CCThread.mm in Sources */,
|
||||||
1AD71EC5180E26E600808F54 /* Json.cpp in Sources */,
|
1AD71EC5180E26E600808F54 /* Json.cpp in Sources */,
|
||||||
50E6D33C18E174130051CA34 /* UIVBox.cpp in Sources */,
|
50E6D33C18E174130051CA34 /* UIVBox.cpp in Sources */,
|
||||||
|
@ -6721,7 +6721,7 @@
|
||||||
50FCEBAC18C72017004AD434 /* PageViewReader.cpp in Sources */,
|
50FCEBAC18C72017004AD434 /* PageViewReader.cpp in Sources */,
|
||||||
1A8C598C180E930E00EF57C3 /* CCActionFrame.cpp in Sources */,
|
1A8C598C180E930E00EF57C3 /* CCActionFrame.cpp in Sources */,
|
||||||
1A8C5990180E930E00EF57C3 /* CCActionFrameEasing.cpp in Sources */,
|
1A8C5990180E930E00EF57C3 /* CCActionFrameEasing.cpp in Sources */,
|
||||||
29CB8F4D1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */,
|
29CB8F4D1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */,
|
||||||
50FCEBA418C72017004AD434 /* ListViewReader.cpp in Sources */,
|
50FCEBA418C72017004AD434 /* ListViewReader.cpp in Sources */,
|
||||||
1A8C5994180E930E00EF57C3 /* CCActionManagerEx.cpp in Sources */,
|
1A8C5994180E930E00EF57C3 /* CCActionManagerEx.cpp in Sources */,
|
||||||
50ABBEBC1925AB6F00A911A9 /* ccUtils.cpp in Sources */,
|
50ABBEBC1925AB6F00A911A9 /* ccUtils.cpp in Sources */,
|
||||||
|
|
|
@ -9,7 +9,7 @@ LOCAL_SRC_FILES := \
|
||||||
UIWidget.cpp \
|
UIWidget.cpp \
|
||||||
UILayout.cpp \
|
UILayout.cpp \
|
||||||
UILayoutParameter.cpp \
|
UILayoutParameter.cpp \
|
||||||
UILayoutExecutant.cpp \
|
UILayoutManager.cpp \
|
||||||
CocosGUI.cpp \
|
CocosGUI.cpp \
|
||||||
UIHelper.cpp \
|
UIHelper.cpp \
|
||||||
UIListView.cpp \
|
UIListView.cpp \
|
||||||
|
|
|
@ -8,7 +8,7 @@ set(COCOS_UI_SRC
|
||||||
ui/UIImageView.cpp
|
ui/UIImageView.cpp
|
||||||
ui/UILayout.cpp
|
ui/UILayout.cpp
|
||||||
ui/UILayoutParameter.cpp
|
ui/UILayoutParameter.cpp
|
||||||
ui/UILayoutExecutant.cpp
|
ui/UILayoutManager.cpp
|
||||||
ui/UIListView.cpp
|
ui/UIListView.cpp
|
||||||
ui/UILoadingBar.cpp
|
ui/UILoadingBar.cpp
|
||||||
ui/UIPageView.cpp
|
ui/UIPageView.cpp
|
||||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
||||||
#include "renderer/CCRenderer.h"
|
#include "renderer/CCRenderer.h"
|
||||||
#include "renderer/CCGroupCommand.h"
|
#include "renderer/CCGroupCommand.h"
|
||||||
#include "renderer/CCCustomCommand.h"
|
#include "renderer/CCCustomCommand.h"
|
||||||
#include "ui/UILayoutExecutant.h"
|
#include "ui/UILayoutManager.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -942,19 +942,19 @@ const Vector<Node*>& Layout::getLayoutElements()const
|
||||||
return this->getChildren();
|
return this->getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutExecutant* Layout::createLayoutExecutant()
|
LayoutManager* Layout::createLayoutManager()
|
||||||
{
|
{
|
||||||
LayoutExecutant* exe = nullptr;
|
LayoutManager* exe = nullptr;
|
||||||
switch (_layoutType)
|
switch (_layoutType)
|
||||||
{
|
{
|
||||||
case Type::VERTICAL:
|
case Type::VERTICAL:
|
||||||
exe = LinearVerticalLayoutExecutant::create();
|
exe = LinearVerticalLayoutManager::create();
|
||||||
break;
|
break;
|
||||||
case Type::HORIZONTAL:
|
case Type::HORIZONTAL:
|
||||||
exe = LinearHorizontalLayoutExecutant::create();
|
exe = LinearHorizontalLayoutManager::create();
|
||||||
break;
|
break;
|
||||||
case Type::RELATIVE:
|
case Type::RELATIVE:
|
||||||
exe = RelativeLayoutExecutant::create();
|
exe = RelativeLayoutManager::create();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -969,7 +969,7 @@ void Layout::doLayout()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LayoutExecutant* executant = this->createLayoutExecutant();
|
LayoutManager* executant = this->createLayoutManager();
|
||||||
|
|
||||||
if (executant)
|
if (executant)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,7 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
class LayoutExecutant;
|
class LayoutManager;
|
||||||
|
|
||||||
class LayoutProtocol
|
class LayoutProtocol
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ public:
|
||||||
LayoutProtocol(){}
|
LayoutProtocol(){}
|
||||||
virtual ~LayoutProtocol(){}
|
virtual ~LayoutProtocol(){}
|
||||||
|
|
||||||
virtual LayoutExecutant* createLayoutExecutant() = 0;
|
virtual LayoutManager* createLayoutManager() = 0;
|
||||||
virtual Size getLayoutContentSize()const = 0;
|
virtual Size getLayoutContentSize()const = 0;
|
||||||
virtual const Vector<Node*>& getLayoutElements()const = 0;
|
virtual const Vector<Node*>& getLayoutElements()const = 0;
|
||||||
virtual void doLayout() = 0;
|
virtual void doLayout() = 0;
|
||||||
|
@ -328,7 +328,7 @@ protected:
|
||||||
const Rect& getClippingRect();
|
const Rect& getClippingRect();
|
||||||
|
|
||||||
virtual void doLayout()override;
|
virtual void doLayout()override;
|
||||||
virtual LayoutExecutant* createLayoutExecutant()override;
|
virtual LayoutManager* createLayoutManager()override;
|
||||||
virtual Size getLayoutContentSize()const override;
|
virtual Size getLayoutContentSize()const override;
|
||||||
virtual const Vector<Node*>& getLayoutElements()const override;
|
virtual const Vector<Node*>& getLayoutElements()const override;
|
||||||
|
|
||||||
|
|
|
@ -22,16 +22,16 @@
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "UILayoutExecutant.h"
|
#include "UILayoutManager.h"
|
||||||
#include "UILayout.h"
|
#include "UILayout.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create()
|
LinearHorizontalLayoutManager* LinearHorizontalLayoutManager::create()
|
||||||
{
|
{
|
||||||
LinearVerticalLayoutExecutant* exe = new LinearVerticalLayoutExecutant();
|
LinearHorizontalLayoutManager* exe = new LinearHorizontalLayoutManager();
|
||||||
if (exe)
|
if (exe)
|
||||||
{
|
{
|
||||||
exe->autorelease();
|
exe->autorelease();
|
||||||
|
@ -41,9 +41,54 @@ LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create()
|
|
||||||
|
void LinearHorizontalLayoutManager::doLayout(LayoutProtocol* layout)
|
||||||
{
|
{
|
||||||
LinearHorizontalLayoutExecutant* exe = new LinearHorizontalLayoutExecutant();
|
Size layoutSize = layout->getLayoutContentSize();
|
||||||
|
Vector<Node*> container = layout->getLayoutElements();
|
||||||
|
float leftBoundary = 0.0f;
|
||||||
|
for (auto& subWidget : container)
|
||||||
|
{
|
||||||
|
Widget* child = dynamic_cast<Widget*>(subWidget);
|
||||||
|
if (child)
|
||||||
|
{
|
||||||
|
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
|
||||||
|
if (layoutParameter)
|
||||||
|
{
|
||||||
|
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
|
||||||
|
Vec2 ap = child->getAnchorPoint();
|
||||||
|
Size cs = child->getSize();
|
||||||
|
float finalPosX = leftBoundary + (ap.x * cs.width);
|
||||||
|
float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;
|
||||||
|
switch (childGravity)
|
||||||
|
{
|
||||||
|
case LinearLayoutParameter::LinearGravity::NONE:
|
||||||
|
case LinearLayoutParameter::LinearGravity::TOP:
|
||||||
|
break;
|
||||||
|
case LinearLayoutParameter::LinearGravity::BOTTOM:
|
||||||
|
finalPosY = ap.y * cs.height;
|
||||||
|
break;
|
||||||
|
case LinearLayoutParameter::LinearGravity::CENTER_VERTICAL:
|
||||||
|
finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Margin mg = layoutParameter->getMargin();
|
||||||
|
finalPosX += mg.left;
|
||||||
|
finalPosY -= mg.top;
|
||||||
|
child->setPosition(Vec2(finalPosX, finalPosY));
|
||||||
|
leftBoundary = child->getRightBoundary() + mg.right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//LinearVerticalLayoutManager
|
||||||
|
LinearVerticalLayoutManager* LinearVerticalLayoutManager::create()
|
||||||
|
{
|
||||||
|
LinearVerticalLayoutManager* exe = new LinearVerticalLayoutManager();
|
||||||
if (exe)
|
if (exe)
|
||||||
{
|
{
|
||||||
exe->autorelease();
|
exe->autorelease();
|
||||||
|
@ -53,19 +98,7 @@ LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RelativeLayoutExecutant* RelativeLayoutExecutant::create()
|
void LinearVerticalLayoutManager::doLayout(LayoutProtocol* layout)
|
||||||
{
|
|
||||||
RelativeLayoutExecutant* exe = new RelativeLayoutExecutant();
|
|
||||||
if (exe)
|
|
||||||
{
|
|
||||||
exe->autorelease();
|
|
||||||
return exe;
|
|
||||||
}
|
|
||||||
CC_SAFE_DELETE(exe);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
|
||||||
{
|
{
|
||||||
Size layoutSize = layout->getLayoutContentSize();
|
Size layoutSize = layout->getLayoutContentSize();
|
||||||
Vector<Node*> container = layout->getLayoutElements();
|
Vector<Node*> container = layout->getLayoutElements();
|
||||||
|
@ -109,49 +142,24 @@ void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinearHorizontalLayoutExecutant::doLayout(LayoutProtocol* layout)
|
//RelativeLayoutManager
|
||||||
|
|
||||||
|
RelativeLayoutManager* RelativeLayoutManager::create()
|
||||||
{
|
{
|
||||||
Size layoutSize = layout->getLayoutContentSize();
|
RelativeLayoutManager* exe = new RelativeLayoutManager();
|
||||||
Vector<Node*> container = layout->getLayoutElements();
|
if (exe)
|
||||||
float leftBoundary = 0.0f;
|
|
||||||
for (auto& subWidget : container)
|
|
||||||
{
|
{
|
||||||
Widget* child = dynamic_cast<Widget*>(subWidget);
|
exe->autorelease();
|
||||||
if (child)
|
return exe;
|
||||||
{
|
|
||||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
|
|
||||||
if (layoutParameter)
|
|
||||||
{
|
|
||||||
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
|
|
||||||
Vec2 ap = child->getAnchorPoint();
|
|
||||||
Size cs = child->getSize();
|
|
||||||
float finalPosX = leftBoundary + (ap.x * cs.width);
|
|
||||||
float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;
|
|
||||||
switch (childGravity)
|
|
||||||
{
|
|
||||||
case LinearLayoutParameter::LinearGravity::NONE:
|
|
||||||
case LinearLayoutParameter::LinearGravity::TOP:
|
|
||||||
break;
|
|
||||||
case LinearLayoutParameter::LinearGravity::BOTTOM:
|
|
||||||
finalPosY = ap.y * cs.height;
|
|
||||||
break;
|
|
||||||
case LinearLayoutParameter::LinearGravity::CENTER_VERTICAL:
|
|
||||||
finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Margin mg = layoutParameter->getMargin();
|
|
||||||
finalPosX += mg.left;
|
|
||||||
finalPosY -= mg.top;
|
|
||||||
child->setPosition(Vec2(finalPosX, finalPosY));
|
|
||||||
leftBoundary = child->getRightBoundary() + mg.right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
CC_SAFE_DELETE(exe);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Widget*> RelativeLayoutExecutant::getAllWidgets(cocos2d::ui::LayoutProtocol *layout)
|
|
||||||
|
|
||||||
|
|
||||||
|
Vector<Widget*> RelativeLayoutManager::getAllWidgets(cocos2d::ui::LayoutProtocol *layout)
|
||||||
{
|
{
|
||||||
Vector<Node*> container = layout->getLayoutElements();
|
Vector<Node*> container = layout->getLayoutElements();
|
||||||
Vector<Widget*> widgetChildren;
|
Vector<Widget*> widgetChildren;
|
||||||
|
@ -170,7 +178,7 @@ Vector<Widget*> RelativeLayoutExecutant::getAllWidgets(cocos2d::ui::LayoutProtoc
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget* RelativeLayoutExecutant::getRelativeWidget(Widget* widget)
|
Widget* RelativeLayoutManager::getRelativeWidget(Widget* widget)
|
||||||
{
|
{
|
||||||
Widget* relativeWidget = nullptr;
|
Widget* relativeWidget = nullptr;
|
||||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(widget->getLayoutParameter());
|
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(widget->getLayoutParameter());
|
||||||
|
@ -195,7 +203,7 @@ Widget* RelativeLayoutExecutant::getRelativeWidget(Widget* widget)
|
||||||
return relativeWidget;
|
return relativeWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RelativeLayoutExecutant::caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout)
|
bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout)
|
||||||
{
|
{
|
||||||
Vec2 ap = _widget->getAnchorPoint();
|
Vec2 ap = _widget->getAnchorPoint();
|
||||||
Size cs = _widget->getSize();
|
Size cs = _widget->getSize();
|
||||||
|
@ -418,7 +426,7 @@ bool RelativeLayoutExecutant::caculateFinalPositionWithRelativeWidget(LayoutProt
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RelativeLayoutExecutant::caculateFinalPositionWithRelativeAlign()
|
void RelativeLayoutManager::caculateFinalPositionWithRelativeAlign()
|
||||||
{
|
{
|
||||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(_widget->getLayoutParameter());
|
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(_widget->getLayoutParameter());
|
||||||
|
|
||||||
|
@ -514,7 +522,7 @@ void RelativeLayoutExecutant::caculateFinalPositionWithRelativeAlign()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RelativeLayoutExecutant::doLayout(LayoutProtocol *layout)
|
void RelativeLayoutManager::doLayout(LayoutProtocol *layout)
|
||||||
{
|
{
|
||||||
|
|
||||||
_widgetChildren = this->getAllWidgets(layout);
|
_widgetChildren = this->getAllWidgets(layout);
|
|
@ -22,8 +22,8 @@
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __cocos2d_libs__CCLayoutExecutant__
|
#ifndef __cocos2d_libs__CCLayoutManager__
|
||||||
#define __cocos2d_libs__CCLayoutExecutant__
|
#define __cocos2d_libs__CCLayoutManager__
|
||||||
|
|
||||||
#include "base/CCRef.h"
|
#include "base/CCRef.h"
|
||||||
#include "base/CCVector.h"
|
#include "base/CCVector.h"
|
||||||
|
@ -36,48 +36,53 @@ class LayoutProtocol;
|
||||||
class Widget;
|
class Widget;
|
||||||
class RelativeLayoutParameter;
|
class RelativeLayoutParameter;
|
||||||
|
|
||||||
class LayoutExecutant : public Ref
|
class LayoutManager : public Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LayoutExecutant(){};
|
virtual ~LayoutManager(){};
|
||||||
virtual ~LayoutExecutant(){};
|
LayoutManager(){};
|
||||||
|
|
||||||
virtual void doLayout(LayoutProtocol *layout) = 0;
|
virtual void doLayout(LayoutProtocol *layout) = 0;
|
||||||
|
|
||||||
|
friend class Layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LinearVerticalLayoutExecutant : public LayoutExecutant
|
class LinearVerticalLayoutManager : public LayoutManager
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
LinearVerticalLayoutExecutant(){};
|
LinearVerticalLayoutManager(){};
|
||||||
virtual ~LinearVerticalLayoutExecutant(){};
|
virtual ~LinearVerticalLayoutManager(){};
|
||||||
static LinearVerticalLayoutExecutant* create();
|
static LinearVerticalLayoutManager* create();
|
||||||
virtual void doLayout(LayoutProtocol *layout) override;
|
virtual void doLayout(LayoutProtocol *layout) override;
|
||||||
|
|
||||||
|
friend class Layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LinearHorizontalLayoutExecutant : public LayoutExecutant
|
class LinearHorizontalLayoutManager : public LayoutManager
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
LinearHorizontalLayoutExecutant(){};
|
LinearHorizontalLayoutManager(){};
|
||||||
virtual ~LinearHorizontalLayoutExecutant(){};
|
virtual ~LinearHorizontalLayoutManager(){};
|
||||||
static LinearHorizontalLayoutExecutant* create();
|
static LinearHorizontalLayoutManager* create();
|
||||||
virtual void doLayout(LayoutProtocol *layout) override;
|
virtual void doLayout(LayoutProtocol *layout) override;
|
||||||
|
|
||||||
|
friend class Layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RelativeLayoutExecutant : public LayoutExecutant
|
class RelativeLayoutManager : public LayoutManager
|
||||||
{
|
{
|
||||||
public:
|
private:
|
||||||
RelativeLayoutExecutant()
|
RelativeLayoutManager()
|
||||||
:_unlayoutChildCount(0),
|
:_unlayoutChildCount(0),
|
||||||
_widget(nullptr),
|
_widget(nullptr),
|
||||||
_finalPositionX(0.0f),
|
_finalPositionX(0.0f),
|
||||||
_finalPositionY(0.0f),
|
_finalPositionY(0.0f),
|
||||||
_relativeWidgetLP(nullptr)
|
_relativeWidgetLP(nullptr)
|
||||||
{}
|
{}
|
||||||
virtual ~RelativeLayoutExecutant(){};
|
virtual ~RelativeLayoutManager(){};
|
||||||
static RelativeLayoutExecutant* create();
|
static RelativeLayoutManager* create();
|
||||||
virtual void doLayout(LayoutProtocol *layout) override;
|
virtual void doLayout(LayoutProtocol *layout) override;
|
||||||
|
|
||||||
protected:
|
|
||||||
Vector<Widget*> getAllWidgets(LayoutProtocol *layout);
|
Vector<Widget*> getAllWidgets(LayoutProtocol *layout);
|
||||||
Widget* getRelativeWidget(Widget* widget);
|
Widget* getRelativeWidget(Widget* widget);
|
||||||
bool caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout);
|
bool caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout);
|
||||||
|
@ -90,9 +95,11 @@ protected:
|
||||||
float _finalPositionY;
|
float _finalPositionY;
|
||||||
|
|
||||||
RelativeLayoutParameter* _relativeWidgetLP;
|
RelativeLayoutParameter* _relativeWidgetLP;
|
||||||
|
|
||||||
|
friend class Layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
#endif /* defined(__cocos2d_libs__CCLayoutExecutant__) */
|
#endif /* defined(__cocos2d_libs__CCLayoutManager__) */
|
|
@ -314,7 +314,7 @@ protected:
|
||||||
std::string _relativeWidgetName;
|
std::string _relativeWidgetName;
|
||||||
std::string _relativeLayoutName;
|
std::string _relativeLayoutName;
|
||||||
bool _put;
|
bool _put;
|
||||||
friend class RelativeLayoutExecutant;
|
friend class RelativeLayoutManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<ClInclude Include="..\UIHelper.h" />
|
<ClInclude Include="..\UIHelper.h" />
|
||||||
<ClInclude Include="..\UIImageView.h" />
|
<ClInclude Include="..\UIImageView.h" />
|
||||||
<ClInclude Include="..\UILayout.h" />
|
<ClInclude Include="..\UILayout.h" />
|
||||||
<ClInclude Include="..\UILayoutExecutant.h" />
|
<ClInclude Include="..\UILayoutManager.h" />
|
||||||
<ClInclude Include="..\UILayoutParameter.h" />
|
<ClInclude Include="..\UILayoutParameter.h" />
|
||||||
<ClInclude Include="..\UIListView.h" />
|
<ClInclude Include="..\UIListView.h" />
|
||||||
<ClInclude Include="..\UILoadingBar.h" />
|
<ClInclude Include="..\UILoadingBar.h" />
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
<ClCompile Include="..\UIHelper.cpp" />
|
<ClCompile Include="..\UIHelper.cpp" />
|
||||||
<ClCompile Include="..\UIImageView.cpp" />
|
<ClCompile Include="..\UIImageView.cpp" />
|
||||||
<ClCompile Include="..\UILayout.cpp" />
|
<ClCompile Include="..\UILayout.cpp" />
|
||||||
<ClCompile Include="..\UILayoutExecutant.cpp" />
|
<ClCompile Include="..\UILayoutManager.cpp" />
|
||||||
<ClCompile Include="..\UILayoutParameter.cpp" />
|
<ClCompile Include="..\UILayoutParameter.cpp" />
|
||||||
<ClCompile Include="..\UIListView.cpp" />
|
<ClCompile Include="..\UIListView.cpp" />
|
||||||
<ClCompile Include="..\UILoadingBar.cpp" />
|
<ClCompile Include="..\UILoadingBar.cpp" />
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
<ClInclude Include="..\UIVBox.h">
|
<ClInclude Include="..\UIVBox.h">
|
||||||
<Filter>Layouts</Filter>
|
<Filter>Layouts</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\UILayoutExecutant.h">
|
<ClInclude Include="..\UILayoutManager.h">
|
||||||
<Filter>Layouts</Filter>
|
<Filter>Layouts</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -158,7 +158,7 @@
|
||||||
<ClCompile Include="..\UIVBox.cpp">
|
<ClCompile Include="..\UIVBox.cpp">
|
||||||
<Filter>Layouts</Filter>
|
<Filter>Layouts</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\UILayoutExecutant.cpp">
|
<ClCompile Include="..\UILayoutManager.cpp">
|
||||||
<Filter>Layouts</Filter>
|
<Filter>Layouts</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -940,8 +940,8 @@
|
||||||
"cocos/ui/UIImageView.h",
|
"cocos/ui/UIImageView.h",
|
||||||
"cocos/ui/UILayout.cpp",
|
"cocos/ui/UILayout.cpp",
|
||||||
"cocos/ui/UILayout.h",
|
"cocos/ui/UILayout.h",
|
||||||
"cocos/ui/UILayoutExecutant.cpp",
|
"cocos/ui/UILayoutManager.cpp",
|
||||||
"cocos/ui/UILayoutExecutant.h",
|
"cocos/ui/UILayoutManager.h",
|
||||||
"cocos/ui/UILayoutParameter.cpp",
|
"cocos/ui/UILayoutParameter.cpp",
|
||||||
"cocos/ui/UILayoutParameter.h",
|
"cocos/ui/UILayoutParameter.h",
|
||||||
"cocos/ui/UIListView.cpp",
|
"cocos/ui/UIListView.cpp",
|
||||||
|
|
Loading…
Reference in New Issue