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 "Reflection/BsIReflectable.h"
7#include "Utility/BsRectOffset.h"
8#include "2D/BsTextSprite.h"
9#include "Image/BsColor.h"
10#include "Math/BsVector2I.h"
11
12namespace bs
13{
14 /** @addtogroup GUI
15 * @{
16 */
17
18 /** Possible positions used for positioning content image within a GUI element. */
19 enum class BS_SCRIPT_EXPORT(m:GUI) GUIImagePosition
20 {
21 Left, Right
22 };
23
24 /** Specific texture and text color used in a particular GUI element style. */
25 struct BS_EXPORT BS_SCRIPT_EXPORT(m:GUI,pl:true) GUIElementStateStyle
26 {
27 BS_NORREF HSpriteTexture texture;
28 Color textColor;
29 };
30
31 /**
32 * GUI element style that determines the look of a GUI element, as well as the element's default layout options.
33 * Different looks can be provided for different element states.
34 */
35 struct BS_EXPORT BS_SCRIPT_EXPORT(m:GUI) GUIElementStyle : public IReflectable
36 {
37 BS_SCRIPT_EXPORT()
38 GUIElementStyle() = default;
39
40 BS_SCRIPT_EXPORT()
41 BS_NORREF HFont font; /**< Font to use for all text within the GUI element. */
42
43 BS_SCRIPT_EXPORT()
44 UINT32 fontSize = 8; /**< Font size to use for all text within the GUI element. */
45
46 BS_SCRIPT_EXPORT()
47 TextHorzAlign textHorzAlign = THA_Left; /**< Horizontal alignment of text within the GUI element. */
48
49 BS_SCRIPT_EXPORT()
50 TextVertAlign textVertAlign = TVA_Top; /**< Vertical alignment of text within the GUI element. */
51
52 BS_SCRIPT_EXPORT()
53 GUIImagePosition imagePosition = GUIImagePosition::Left; /**< Position of content image relative to text. */
54
55 BS_SCRIPT_EXPORT()
56 bool wordWrap = false; /**< Should the text word wrap if it doesn't fit. */
57
58 /**
59 * Style used when the element doesn't have focus nor is the user interacting with the element. Used when the
60 * element is in the 'off' state.
61 */
62 BS_SCRIPT_EXPORT()
63 GUIElementStateStyle normal;
64
65 /**
66 * Style used when the user is hovering the pointer over the element, while the element doesn't have focus. Used
67 * when the element is in the 'off' state.
68 */
69 BS_SCRIPT_EXPORT()
70 GUIElementStateStyle hover;
71
72 /**
73 * Style used when the user is actively interacting with the element. Used when the element is in the 'off' state.
74 */
75 BS_SCRIPT_EXPORT()
76 GUIElementStateStyle active;
77
78 /**
79 * Style used when the element has focus but the pointer is not hovering over the element. Used when the element is
80 * in the 'off' state.
81 */
82 BS_SCRIPT_EXPORT()
83 GUIElementStateStyle focused;
84
85 /**
86 * Style used when the element has focus and the pointer is hovering over the element. Used when the element is
87 * in the 'off' state.
88 */
89 BS_SCRIPT_EXPORT()
90 GUIElementStateStyle focusedHover;
91
92 /** Same as GUIElementStyle::normal, except it's used when element is in the 'on' state. */
93 BS_SCRIPT_EXPORT()
94 GUIElementStateStyle normalOn;
95
96 /** Same as GUIElementStyle::hover, except it's used when element is in the 'on' state. */
97 BS_SCRIPT_EXPORT()
98 GUIElementStateStyle hoverOn;
99
100 /** Same as GUIElementStyle::active, except it's used when element is in the 'on' state. */
101 BS_SCRIPT_EXPORT()
102 GUIElementStateStyle activeOn;
103
104 /** Same as GUIElementStyle::focused, except it's used when element is in the 'on' state. */
105 BS_SCRIPT_EXPORT()
106 GUIElementStateStyle focusedOn;
107
108 /** Same as GUIElementStyle::focusedHover, except it's used when element is in the 'on' state. */
109 BS_SCRIPT_EXPORT()
110 GUIElementStateStyle focusedHoverOn;
111
112 BS_SCRIPT_EXPORT()
113 RectOffset border; /**< Determines how the element is scaled (using the typical Scale9Grid approach). */
114
115 BS_SCRIPT_EXPORT()
116 RectOffset margins; /**< Determines offset from the background graphics to the content. Input uses bounds offset by this value. */
117
118 BS_SCRIPT_EXPORT()
119 RectOffset contentOffset; /**< Additional offset to the content, that doesn't effect the bounds. Applied on top of the margins offsets. */
120
121 BS_SCRIPT_EXPORT()
122 RectOffset padding; /**< Determines extra distance between this and other elements in a layout. */
123
124 BS_SCRIPT_EXPORT()
125 UINT32 width = 0; /**< Wanted width of the GUI element in pixels. Only used if fixedWidth is enabled. */
126
127 BS_SCRIPT_EXPORT()
128 UINT32 height = 0; /**< Wanted height of the GUI element in pixels. Only used if fixedHeight is enabled. */
129
130 BS_SCRIPT_EXPORT()
131 UINT32 minWidth = 0; /**< Minimum width allowed for the GUI element. Used by the layout only when exact width is not specified. */
132
133 BS_SCRIPT_EXPORT()
134 UINT32 maxWidth = 0; /**< Maximum width allowed for the GUI element. Used by the layout only when exact width is not specified. */
135
136 BS_SCRIPT_EXPORT()
137 UINT32 minHeight = 0; /**< Minimum height allowed for the GUI element. Used by the layout only when exact height is not specified. */
138
139 BS_SCRIPT_EXPORT()
140 UINT32 maxHeight = 0; /**< Maximum height allowed for the GUI element. Used by the layout only when exact height is not specified. */
141
142 BS_SCRIPT_EXPORT()
143 bool fixedWidth = false; /**< Determines should the layout resize the element depending on available size. If true no resizing will be done. */
144
145 BS_SCRIPT_EXPORT()
146 bool fixedHeight = false; /**< Determines should the layout resize the element depending on available size. If true no resizing will be done. */
147
148 /**
149 * Registers a new sub-style that is used by complex GUI elements that contain one or multiple sub-elements.
150 * @param[in] guiType Name of the sub-element this style is to be used for. This depends on GUI element the
151 * style is applied to.
152 * @param[in] styleName Name of the style in GUI skin to use for the sub-element.
153 */
154 BS_SCRIPT_EXPORT()
155 void addSubStyle(const String& guiType, const String& styleName)
156 {
157 subStyles[guiType] = styleName;
158 }
159
160 Map<String, String> subStyles; /**< Sub-styles used by certain more complex elements. */
161
162 /************************************************************************/
163 /* SERIALIZATION */
164 /************************************************************************/
165 public:
166 friend class GUIElementStyleRTTI;
167 static RTTITypeBase* getRTTIStatic();
168 RTTITypeBase* getRTTI() const override;
169 };
170
171 /** @} */
172}