TGUI  1.1
Loading...
Searching...
No Matches
RichTextLabel.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2023 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_RICH_TEXT_LABEL_HPP
27#define TGUI_RICH_TEXT_LABEL_HPP
28
29
30#include <TGUI/Widgets/Label.hpp>
31
33
34TGUI_MODULE_EXPORT namespace tgui
35{
50 class TGUI_API RichTextLabel : public Label
51 {
52 public:
53
54 using Ptr = std::shared_ptr<RichTextLabel>;
55 using ConstPtr = std::shared_ptr<const RichTextLabel>;
56
57 static constexpr const char StaticWidgetType[] = "RichTextLabel";
58
59
67 RichTextLabel(const char* typeName = StaticWidgetType, bool initRenderer = true);
68
69
78 TGUI_NODISCARD static RichTextLabel::Ptr create(const String& text = "");
79
80
89 TGUI_NODISCARD static RichTextLabel::Ptr copy(const RichTextLabel::ConstPtr& label);
90
91
98 void draw(BackendRenderTarget& target, RenderStates states) const override;
99
100
102 protected:
103
110 void rendererChanged(const String& property) override;
111
112
116 void rearrangeText() override;
117
118
120 // Helper function used by rearrangeText() to calculate the height of a single line
122 float calculateLineSpacing(const std::vector<Text::Blueprint>& line, float defaultLineSpacing);
123
124
126 // Helper function used by rearrangeText() to calculate the total height of all lines
128 float calculateTextHeight(const std::vector<std::vector<Text::Blueprint>>& textPiecesLines, float defaultLineSpacing);
129
130
132 // Helper function used by rearrangeText() to create the lines before word-wrapping is applied
134 void constructRichLineBlueprints(std::vector<std::vector<Text::Blueprint>>& textPiecesLines, std::vector<Texture>& images);
135
136
138 // Makes a copy of the widget
140 TGUI_NODISCARD Widget::Ptr clone() const override;
141
142
144 protected:
145
146 std::vector<Sprite> m_images;
147
148
150 };
151
153}
154
156
157#endif // TGUI_RICH_TEXT_LABEL_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Label widget.
Definition Label.hpp:44
RichTextLabel widget.
Definition RichTextLabel.hpp:51
static TGUI_NODISCARD RichTextLabel::Ptr create(const String &text="")
Creates a new label widget.
static TGUI_NODISCARD RichTextLabel::Ptr copy(const RichTextLabel::ConstPtr &label)
Makes a copy of another label.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
std::shared_ptr< const RichTextLabel > ConstPtr
Shared constant widget pointer.
Definition RichTextLabel.hpp:55
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void rearrangeText() override
Rearrange the text (recreates m_textPieces), making use of the given size of maximum text width.
std::shared_ptr< RichTextLabel > Ptr
Shared widget pointer.
Definition RichTextLabel.hpp:54
Wrapper class to store strings.
Definition String.hpp:101
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
States used for drawing.
Definition RenderStates.hpp:39