| 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 "2D/BsTextSprite.h" |
| 7 | #include "GUI/BsGUIContent.h" |
| 8 | |
| 9 | namespace bs |
| 10 | { |
| 11 | /** @addtogroup GUI-Internal |
| 12 | * @{ |
| 13 | */ |
| 14 | |
| 15 | /** Contains various helper methods used by GUI. */ |
| 16 | class BS_EXPORT GUIHelper |
| 17 | { |
| 18 | public: |
| 19 | /** |
| 20 | * Calculates optimal content size by returning the nearest valid size to the provided value. |
| 21 | * |
| 22 | * @param[in] contentSize Wanted content size. This will be limited by minimal constraints of the style and |
| 23 | * layout options. |
| 24 | * @param[in] style Style to use for determining size constraints. |
| 25 | * @param[in] dimensions Dimension constraints of a GUI element. |
| 26 | */ |
| 27 | static Vector2I calcOptimalContentsSize(const Vector2I& contentSize, const GUIElementStyle& style, |
| 28 | const GUIDimensions& dimensions); |
| 29 | |
| 30 | /** |
| 31 | * Calculates optimal content size for the provided content using the provided style and layout options for |
| 32 | * constraints. |
| 33 | * |
| 34 | * @param[in] content Content to calculate size for. |
| 35 | * @param[in] style Style to use for determining size constraints. |
| 36 | * @param[in] dimensions Dimension constraints of a GUI element. |
| 37 | * @param[in] state State of the GUI element in case the content changes according to state. |
| 38 | */ |
| 39 | static Vector2I calcOptimalContentsSize(const GUIContent& content, const GUIElementStyle& style, |
| 40 | const GUIDimensions& dimensions, GUIElementState state = GUIElementState::Normal); |
| 41 | |
| 42 | /** |
| 43 | * Calculates optimal content size for the provided text using the provided style and layout options for |
| 44 | * constraints. |
| 45 | * |
| 46 | * @param[in] text Text to calculate size for. |
| 47 | * @param[in] style Style to use for determining size constraints. |
| 48 | * @param[in] dimensions Dimension constraints of a GUI element. |
| 49 | */ |
| 50 | static Vector2I calcOptimalContentsSize(const String& text, const GUIElementStyle& style, |
| 51 | const GUIDimensions& dimensions); |
| 52 | |
| 53 | /** |
| 54 | * Calculates optimal content size for the provided text using the provided font and size. Size is calculated |
| 55 | * without word wrap. |
| 56 | * |
| 57 | * @param[in] text Text to calculate the size for. |
| 58 | * @param[in] font Font to use for rendering the text. |
| 59 | * @param[in] fontSize Size of individual characters in the font, in points. |
| 60 | * @return Width/height required to display the text, in pixels. |
| 61 | */ |
| 62 | static Vector2I calcTextSize(const String& text, const HFont& font, UINT32 fontSize); |
| 63 | }; |
| 64 | |
| 65 | /** @} */ |
| 66 | } |