BsGUILayout.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisites.h"
  5. #include "BsGUIElementBase.h"
  6. #include "BsVector2I.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Implementation
  10. * @{
  11. */
  12. /**
  13. * Base class for layout GUI element. Layout element positions and sizes any child elements according to element styles
  14. * and layout options.
  15. */
  16. class BS_EXPORT GUILayout : public GUIElementBase
  17. {
  18. public:
  19. GUILayout(const GUIDimensions& dimensions);
  20. GUILayout();
  21. virtual ~GUILayout();
  22. /** Creates a new element and adds it to the layout after all existing elements. */
  23. template<class Type, class... Args>
  24. Type* addNewElement(Args &&...args)
  25. {
  26. Type* elem = Type::create(std::forward<Args>(args)...);
  27. addElement(elem);
  28. return elem;
  29. }
  30. /** Creates a new element and inserts it before the element at the specified index. */
  31. template<class Type, class... Args>
  32. Type* insertNewElement(UINT32 idx, Args &&...args)
  33. {
  34. Type* elem = Type::create(std::forward<Args>(args)...);
  35. insertElement(idx, elem);
  36. return elem;
  37. }
  38. /** Adds a new element to the layout after all existing elements. */
  39. void addElement(GUIElementBase* element);
  40. /** Removes the specified element from the layout. */
  41. void removeElement(GUIElementBase* element);
  42. /** Removes a child element at the specified index. */
  43. void removeElementAt(UINT32 idx);
  44. /** Inserts a GUI element before the element at the specified index. */
  45. void insertElement(UINT32 idx, GUIElementBase* element);
  46. /** Returns number of child elements in the layout. */
  47. UINT32 getNumChildren() const { return (UINT32)mChildren.size(); }
  48. /** Destroy the layout. Removes it from parent and widget, and deletes it. */
  49. static void destroy(GUILayout* layout);
  50. public: // ***** INTERNAL ******
  51. /** @name Internal
  52. * @{
  53. */
  54. /** @copydoc GUIElementBase::_getLayoutSizeRange */
  55. LayoutSizeRange _getLayoutSizeRange() const override { return _getCachedSizeRange(); }
  56. /** Returns a size range that was cached during the last GUIElementBase::_updateOptimalLayoutSizes call. */
  57. LayoutSizeRange _getCachedSizeRange() const { return mSizeRange; }
  58. /**
  59. * Returns a size ranges for all children that was cached during the last GUIElementBase::_updateOptimalLayoutSizes
  60. * call.
  61. */
  62. const Vector<LayoutSizeRange>& _getCachedChildSizeRanges() const { return mChildSizeRanges; }
  63. /** @copydoc GUIElementBase::_getOptimalSize */
  64. Vector2I _getOptimalSize() const override { return mSizeRange.optimal; }
  65. /** @copydoc GUIElementBase::_getPadding */
  66. const RectOffset& _getPadding() const override;
  67. /** @copydoc GUIElementBase::_getType */
  68. virtual Type _getType() const override { return GUIElementBase::Type::Layout; }
  69. /** @} */
  70. protected:
  71. Vector<LayoutSizeRange> mChildSizeRanges;
  72. LayoutSizeRange mSizeRange;
  73. };
  74. /** @} */
  75. }