TGUI  1.6.1
Loading...
Searching...
No Matches
RichTextLabel.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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#ifndef TGUI_RICH_TEXT_LABEL_HPP
26#define TGUI_RICH_TEXT_LABEL_HPP
27
28#include <TGUI/Widgets/Label.hpp>
29
31
32TGUI_MODULE_EXPORT namespace tgui
33{
48 class TGUI_API RichTextLabel : public Label
49 {
50 public:
51
52 using Ptr = std::shared_ptr<RichTextLabel>;
53 using ConstPtr = std::shared_ptr<const RichTextLabel>;
54
55 static constexpr const char StaticWidgetType[] = "RichTextLabel";
56
64 RichTextLabel(const char* typeName = StaticWidgetType, bool initRenderer = true);
65
73 TGUI_NODISCARD static RichTextLabel::Ptr create(const String& text = "");
74
82 TGUI_NODISCARD static RichTextLabel::Ptr copy(const RichTextLabel::ConstPtr& label);
83
90 void draw(BackendRenderTarget& target, RenderStates states) const override;
91
93 protected:
94
105 virtual void constructRichLineBlueprints(std::vector<std::vector<Text::Blueprint>>& textPiecesLines, std::vector<Texture>& images);
106
112 void rendererChanged(const String& property) override;
113
117 void rearrangeText() override;
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
125 // Helper function used by rearrangeText() to calculate the total height of all lines
127 float calculateTextHeight(const std::vector<std::vector<Text::Blueprint>>& textPiecesLines, float defaultLineSpacing);
128
130 // Makes a copy of the widget
132 TGUI_NODISCARD Widget::Ptr clone() const override;
133
135 protected:
136
137 std::vector<Sprite> m_images;
138
140 };
141
143}
144
146
147#endif // TGUI_RICH_TEXT_LABEL_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Label widget.
Definition Label.hpp:41
RichTextLabel widget.
Definition RichTextLabel.hpp:49
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
static RichTextLabel::Ptr create(const String &text="")
Creates a new label widget.
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.
virtual void constructRichLineBlueprints(std::vector< std::vector< Text::Blueprint > > &textPiecesLines, std::vector< Texture > &images)
Helper function used by rearrangeText() to create the lines before word-wrapping is applied.
std::shared_ptr< const RichTextLabel > ConstPtr
Shared constant widget pointer.
Definition RichTextLabel.hpp:53
static RichTextLabel::Ptr copy(const RichTextLabel::ConstPtr &label)
Makes a copy of another label.
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:52
Wrapper class to store strings.
Definition String.hpp:96
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
States used for drawing.
Definition RenderStates.hpp:38