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