UILayoutManager.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /****************************************************************************
  2. Copyright (c) 2013-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __cocos2d_libs__CCLayoutManager__
  22. #define __cocos2d_libs__CCLayoutManager__
  23. #include "base/CCRef.h"
  24. #include "base/CCVector.h"
  25. #include "ui/GUIExport.h"
  26. /**
  27. * @addtogroup ui
  28. * @{
  29. */
  30. NS_CC_BEGIN
  31. namespace ui {
  32. class LayoutProtocol;
  33. class Widget;
  34. class RelativeLayoutParameter;
  35. /**
  36. *@brief Base class for managing layout.
  37. * All the concrete layout manager should inherit from this class.
  38. */
  39. class CC_GUI_DLL LayoutManager : public Ref
  40. {
  41. public:
  42. virtual ~LayoutManager(){};
  43. LayoutManager(){};
  44. /**
  45. * The interface does the actual layouting work.
  46. */
  47. virtual void doLayout(LayoutProtocol *layout) = 0;
  48. friend class Layout;
  49. };
  50. /**
  51. *@brief Linear vertical layouting class.
  52. * Note: This class is used only by @see `Layout` class.
  53. * @lua NA
  54. * @js NA
  55. */
  56. class CC_GUI_DLL LinearVerticalLayoutManager : public LayoutManager
  57. {
  58. private:
  59. LinearVerticalLayoutManager(){};
  60. virtual ~LinearVerticalLayoutManager(){};
  61. static LinearVerticalLayoutManager* create();
  62. virtual void doLayout(LayoutProtocol *layout) override;
  63. friend class Layout;
  64. };
  65. /**
  66. *@brief Linear horizontal layouting class.
  67. *Note: This class is used only by @see `Layout` class.
  68. * @lua NA
  69. * @js NA
  70. */
  71. class CC_GUI_DLL LinearHorizontalLayoutManager : public LayoutManager
  72. {
  73. private:
  74. LinearHorizontalLayoutManager(){};
  75. virtual ~LinearHorizontalLayoutManager(){};
  76. static LinearHorizontalLayoutManager* create();
  77. virtual void doLayout(LayoutProtocol *layout) override;
  78. friend class Layout;
  79. };
  80. /**
  81. *@brief Relative layouting class.
  82. *Note: This class is used only by `Layout` class.
  83. * @lua NA
  84. * @js NA
  85. */
  86. class CC_GUI_DLL RelativeLayoutManager : public LayoutManager
  87. {
  88. private:
  89. RelativeLayoutManager()
  90. :_unlayoutChildCount(0),
  91. _widget(nullptr),
  92. _finalPositionX(0.0f),
  93. _finalPositionY(0.0f),
  94. _relativeWidgetLP(nullptr)
  95. {}
  96. virtual ~RelativeLayoutManager(){};
  97. static RelativeLayoutManager* create();
  98. virtual void doLayout(LayoutProtocol *layout) override;
  99. Vector<Widget*> getAllWidgets(LayoutProtocol *layout);
  100. Widget* getRelativeWidget(Widget* widget);
  101. bool calculateFinalPositionWithRelativeWidget(LayoutProtocol *layout);
  102. void calculateFinalPositionWithRelativeAlign();
  103. /** @deprecated Use method calculateFinalPositionWithRelativeWidget() instead */
  104. CC_DEPRECATED_ATTRIBUTE bool caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout);
  105. /** @deprecated Use method calculateFinalPositionWithRelativeAlign() instead */
  106. CC_DEPRECATED_ATTRIBUTE void caculateFinalPositionWithRelativeAlign();
  107. ssize_t _unlayoutChildCount;
  108. Vector<Widget*> _widgetChildren;
  109. Widget* _widget;
  110. float _finalPositionX;
  111. float _finalPositionY;
  112. RelativeLayoutParameter* _relativeWidgetLP;
  113. friend class Layout;
  114. };
  115. }
  116. NS_CC_END
  117. // end of ui group
  118. /// @}
  119. #endif /* defined(__cocos2d_libs__CCLayoutManager__) */