BsGUISpace.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. namespace BansheeEngine
  7. {
  8. /** @addtogroup GUI
  9. * @{
  10. */
  11. /** GUI element that may be inserted into layouts in order to make a space of a fixed size. */
  12. class BS_EXPORT GUIFixedSpace : public GUIElementBase
  13. {
  14. public:
  15. GUIFixedSpace(UINT32 size)
  16. :mSize(size)
  17. { }
  18. ~GUIFixedSpace();
  19. /** Returns the size of the space in pixels. */
  20. UINT32 getSize() const { return mSize; }
  21. /** Changes the size of the space to the specified value, in pixels. */
  22. void setSize(UINT32 size) { if (mSize != size) { mSize = size; _markLayoutAsDirty(); } }
  23. /** Creates a new fixed space GUI element. */
  24. static GUIFixedSpace* create(UINT32 size);
  25. /** Destroys the space and removes it from its parent. */
  26. static void destroy(GUIFixedSpace* space);
  27. public: // ***** INTERNAL ******
  28. /** @name Internal
  29. * @{
  30. */
  31. /** @copydoc GUIElementBase::_getType */
  32. Type _getType() const override { return GUIElementBase::Type::FixedSpace; }
  33. /** @copydoc GUIElementBase::_getOptimalSize */
  34. Vector2I _getOptimalSize() const override { return Vector2I(getSize(), getSize()); }
  35. /** @copydoc GUIElementBase::_calculateLayoutSizeRange */
  36. LayoutSizeRange _calculateLayoutSizeRange() const override;
  37. /** @copydoc GUIElementBase::_getPadding */
  38. const RectOffset& _getPadding() const override
  39. {
  40. static RectOffset padding;
  41. return padding;
  42. }
  43. /** @} */
  44. protected:
  45. UINT32 mSize;
  46. };
  47. /**
  48. * GUI element that may be inserted into layouts to make a space of a flexible size. The space will expand only if
  49. * there is room and other elements are not squished because of it. If multiple flexible spaces are in a layout, their
  50. * sizes will be shared equally.
  51. *
  52. * @note
  53. * For example if you had a horizontal layout with a button, and you wanted to align that button to the right of the
  54. * layout, you would insert a flexible space before the button in the layout.
  55. */
  56. class BS_EXPORT GUIFlexibleSpace : public GUIElementBase
  57. {
  58. public:
  59. GUIFlexibleSpace() {}
  60. ~GUIFlexibleSpace();
  61. /** Creates a new flexible space GUI element. */
  62. static GUIFlexibleSpace* create();
  63. /** Destroys the space and removes it from its parent. */
  64. static void destroy(GUIFlexibleSpace* space);
  65. public: // ***** INTERNAL ******
  66. /** @name Internal
  67. * @{
  68. */
  69. /** @copydoc GUIElementBase::_getType */
  70. Type _getType() const override { return GUIElementBase::Type::FlexibleSpace; }
  71. /** @copydoc GUIElementBase::_getOptimalSize */
  72. virtual Vector2I _getOptimalSize() const override { return Vector2I(0, 0); }
  73. /** @copydoc GUIElementBase::_calculateLayoutSizeRange */
  74. virtual LayoutSizeRange _calculateLayoutSizeRange() const override;
  75. /** @copydoc GUIElementBase::_getPadding */
  76. virtual const RectOffset& _getPadding() const override
  77. {
  78. static RectOffset padding;
  79. return padding;
  80. }
  81. /** @} */
  82. };
  83. /** @} */
  84. }