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/BsGUIElement.h"
7#include "2D/BsTextSprite.h"
8#include "2D/BsImageSprite.h"
9#include "GUI/BsGUIContent.h"
10
11namespace bs
12{
13 /** @addtogroup GUI
14 * @{
15 */
16
17 /** GUI element that displays text and optionally a content image. */
18 class BS_EXPORT GUILabel : public GUIElement
19 {
20 public:
21 /** Returns type name of the GUI element used for finding GUI element styles. */
22 static const String& getGUITypeName();
23
24 /**
25 * Creates a new label with the specified text.
26 *
27 * @param[in] text Text to display.
28 * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
29 * GUIWidget the element is used on. If not specified default button style is used.
30 */
31 static GUILabel* create(const HString& text, const String& styleName = StringUtil::BLANK);
32
33 /**
34 * Creates a new label with the specified text.
35 *
36 * @param[in] text Text to display.
37 * @param[in] options Options that allow you to control how is the element positioned and sized.
38 * This will override any similar options set by style.
39 * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
40 * GUIWidget the element is used on. If not specified default button style is used.
41 */
42 static GUILabel* create(const HString& text, const GUIOptions& options, const String& styleName = StringUtil::BLANK);
43
44 /**
45 * Creates a new label with the specified content (text + optional image).
46 *
47 * @param[in] content Content to display.
48 * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
49 * GUIWidget the element is used on. If not specified default button style is used.
50 */
51 static GUILabel* create(const GUIContent& content, const String& styleName = StringUtil::BLANK);
52
53 /**
54 * Creates a new label with the specified content (text + optional image).
55 *
56 * @param[in] content Content to display.
57 * @param[in] options Options that allow you to control how is the element positioned and sized. This will
58 * override any similar options set by style.
59 * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
60 * GUIWidget the element is used on. If not specified default button style is used.
61 */
62 static GUILabel* create(const GUIContent& content, const GUIOptions& options, const String& styleName = StringUtil::BLANK);
63
64 /** Changes the active content of the label. */
65 void setContent(const GUIContent& content);
66
67 public: // ***** INTERNAL ******
68 /** @name Internal
69 * @{
70 */
71
72 /** @copydoc GUIElement::_getOptimalSize */
73 Vector2I _getOptimalSize() const override;
74
75 /** @copydoc GUIElement::_getElementType */
76 ElementType _getElementType() const override { return ElementType::Label; }
77
78 /** @} */
79 protected:
80 ~GUILabel();
81
82 /** @copydoc GUIElement::_getNumRenderElements */
83 UINT32 _getNumRenderElements() const override;
84
85 /** @copydoc GUIElement::_getMaterial */
86 const SpriteMaterialInfo& _getMaterial(UINT32 renderElementIdx, SpriteMaterial** material) const override;
87
88 /** @copydoc GUIElement::_getMeshInfo() */
89 void _getMeshInfo(UINT32 renderElementIdx, UINT32& numVertices, UINT32& numIndices, GUIMeshType& type) const override;
90
91 /** @copydoc GUIElement::_getRenderElementDepth */
92 UINT32 _getRenderElementDepth(UINT32 renderElementIdx) const override;
93
94 /** @copydoc GUIElement::_getRenderElementDepthRange */
95 UINT32 _getRenderElementDepthRange() const override;
96
97 /** @copydoc GUIElement::_fillBuffer */
98 void _fillBuffer(UINT8* vertices, UINT32* indices, UINT32 vertexOffset, UINT32 indexOffset,
99 UINT32 maxNumVerts, UINT32 maxNumIndices, UINT32 renderElementIdx) const override;
100
101 /** @copydoc GUIElement::updateRenderElementsInternal */
102 void updateRenderElementsInternal() override;
103
104 private:
105 GUILabel(const String& styleName, const GUIContent& content, const GUIDimensions& dimensions);
106
107 GUIContent mContent;
108
109 TextSprite* mTextSprite;
110 ImageSprite* mImageSprite;
111
112 TEXT_SPRITE_DESC mDesc;
113 IMAGE_SPRITE_DESC mImageDesc;
114 };
115
116 /** @} */
117}