BsGUISpace.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsGUIElementBase.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief GUI element that may be inserted into layouts in order to make
  8. * a space of a fixed size.
  9. */
  10. class BS_EXPORT GUIFixedSpace : public GUIElementBase
  11. {
  12. public:
  13. GUIFixedSpace(UINT32 size)
  14. :mSize(size)
  15. { }
  16. ~GUIFixedSpace();
  17. /**
  18. * @brief Returns the size of the space in pixels.
  19. */
  20. UINT32 getSize() const { return mSize; }
  21. /**
  22. * @brief Changes the size of the space to the specified value, in pixels.
  23. */
  24. void setSize(UINT32 size) { mSize = size; _markContentAsDirty(); }
  25. /**
  26. * @copydoc GUIElementBase::_getType
  27. */
  28. Type _getType() const { return GUIElementBase::Type::FixedSpace; }
  29. /**
  30. * @copydoc GUIElementBase::_getOptimalSize
  31. */
  32. virtual Vector2I _getOptimalSize() const override { return Vector2I(getSize(), getSize()); }
  33. /**
  34. * @copydoc GUIElementBase::_calculateLayoutSizeRange
  35. */
  36. virtual LayoutSizeRange _calculateLayoutSizeRange() const override;
  37. /**
  38. * @copydoc GUIElementBase::_getPadding
  39. */
  40. virtual const RectOffset& _getPadding() const override
  41. {
  42. static RectOffset padding;
  43. return padding;
  44. }
  45. /**
  46. * @brief Creates a new fixed space GUI element.
  47. */
  48. static GUIFixedSpace* create(UINT32 size);
  49. /**
  50. * @brief Destroys the space and removes it from its parent.
  51. */
  52. static void destroy(GUIFixedSpace* space);
  53. protected:
  54. UINT32 mSize;
  55. };
  56. /**
  57. * @brief GUI element that may be inserted into layouts to make a space of
  58. * a flexible size. The space will expand only if there is room and
  59. * other elements are not squished because of it. If multiple flexible
  60. * spaces are in a layout, their sizes will be shared equally.
  61. *
  62. * @note e.g. If you had a horizontal layout with a button, and you wanted to
  63. * align that button to the right of the layout, you would insert a flexible
  64. * space before the button in the layout.
  65. */
  66. class BS_EXPORT GUIFlexibleSpace : public GUIElementBase
  67. {
  68. public:
  69. GUIFlexibleSpace() {}
  70. ~GUIFlexibleSpace();
  71. /**
  72. * @copydoc GUIElementBase::_getType
  73. */
  74. Type _getType() const override { return GUIElementBase::Type::FlexibleSpace; }
  75. /**
  76. * @copydoc GUIElementBase::_getOptimalSize
  77. */
  78. virtual Vector2I _getOptimalSize() const override { return Vector2I(0, 0); }
  79. /**
  80. * @copydoc GUIElementBase::_calculateLayoutSizeRange
  81. */
  82. virtual LayoutSizeRange _calculateLayoutSizeRange() const override;
  83. /**
  84. * @copydoc GUIElementBase::_getPadding
  85. */
  86. virtual const RectOffset& _getPadding() const override
  87. {
  88. static RectOffset padding;
  89. return padding;
  90. }
  91. /**
  92. * @brief Creates a new flexible space GUI element.
  93. */
  94. static GUIFlexibleSpace* create();
  95. /**
  96. * @brief Destroys the space and removes it from its parent.
  97. */
  98. static void destroy(GUIFlexibleSpace* space);
  99. };
  100. }