TGUI  1.6.1
Loading...
Searching...
No Matches
Label.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_LABEL_HPP
26#define TGUI_LABEL_HPP
27
28#include <TGUI/Widgets/ClickableWidget.hpp>
29#include <TGUI/Renderers/LabelRenderer.hpp>
30#include <TGUI/Widgets/Scrollbar.hpp>
31#include <TGUI/Text.hpp>
32
34
35TGUI_MODULE_EXPORT namespace tgui
36{
40 class TGUI_API Label : public ClickableWidget, public ScrollbarChildInterface
41 {
42 public:
43
44 using Ptr = std::shared_ptr<Label>;
45 using ConstPtr = std::shared_ptr<const Label>;
46
47 static constexpr const char StaticWidgetType[] = "Label";
48
52 using HorizontalAlignment TGUI_DEPRECATED("Use tgui::HorizontalAlignment instead") = tgui::HorizontalAlignment;
53
57 using VerticalAlignment TGUI_DEPRECATED("Use tgui::VerticalAlignment instead") = tgui::VerticalAlignment;
58
66 Label(const char* typeName = StaticWidgetType, bool initRenderer = true);
67
75 TGUI_NODISCARD static Label::Ptr create(const String& text = "");
76
84 TGUI_NODISCARD static Label::Ptr copy(const Label::ConstPtr& label);
85
90 TGUI_NODISCARD LabelRenderer* getSharedRenderer() override;
91 TGUI_NODISCARD const LabelRenderer* getSharedRenderer() const override;
92
98 TGUI_NODISCARD LabelRenderer* getRenderer() override;
99
114 void setSize(const Layout2d& size) override;
115 using Widget::setSize;
116
126 void setText(const String& text);
127
133 TGUI_NODISCARD const String& getText() const;
134
142 void setHorizontalAlignment(tgui::HorizontalAlignment alignment); // TGUI_NEXT: Remove "tgui::" prefix
143
149 TGUI_NODISCARD tgui::HorizontalAlignment getHorizontalAlignment() const; // TGUI_NEXT: Remove "tgui::" prefix
150
158 void setVerticalAlignment(tgui::VerticalAlignment alignment); // TGUI_NEXT: Remove "tgui::" prefix
159
165 TGUI_NODISCARD tgui::VerticalAlignment getVerticalAlignment() const; // TGUI_NEXT: Remove "tgui::" prefix
166
171 TGUI_DEPRECATED("Use getScrollbar()->setPolicy(policy) instead") void setScrollbarPolicy(Scrollbar::Policy policy);
172
177 TGUI_DEPRECATED("Use getScrollbar()->getPolicy() instead") TGUI_NODISCARD Scrollbar::Policy getScrollbarPolicy() const;
178
184 TGUI_DEPRECATED("Use getScrollbar()->setValue(value) instead") void setScrollbarValue(unsigned int value);
185
191 TGUI_DEPRECATED("Use getScrollbar()->getValue() instead") TGUI_NODISCARD unsigned int getScrollbarValue() const;
192
200 TGUI_DEPRECATED("Use getScrollbar()->getMaxValue() instead") TGUI_NODISCARD unsigned int getScrollbarMaxValue() const;
201
212 void setAutoSize(bool autoSize);
213
219 TGUI_NODISCARD bool getAutoSize() const;
220
232 void setMaximumTextWidth(float maximumWidth);
233
242 TGUI_NODISCARD float getMaximumTextWidth() const;
243
251 TGUI_DEPRECATED("Use setIgnoreMouseEvents instead") void ignoreMouseEvents(bool ignore = true);
252
258 TGUI_DEPRECATED("Use getIgnoreMouseEvents instead") TGUI_NODISCARD bool isIgnoringMouseEvents() const;
259
265 void setParent(Container* parent) override;
266
273 TGUI_NODISCARD bool canGainFocus() const override;
274
279 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
280
282 bool leftMousePressed(Vector2f pos) override;
283
285 void leftMouseReleased(Vector2f pos) override;
286
288 void mouseMoved(Vector2f pos) override;
289
291 bool scrolled(float delta, Vector2f pos, bool touch) override;
292
294 void mouseNoLongerOnWidget() override;
295
297 void leftMouseButtonNoLongerDown() override;
298
305 void draw(BackendRenderTarget& target, RenderStates states) const override;
306
308 protected:
309
319 TGUI_NODISCARD Signal& getSignal(String signalName) override;
320
326 void rendererChanged(const String& property) override;
327
331 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
332
336 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
337
341 void updateTextSize() override;
342
344 // This function is called every frame with the time passed since the last frame.
346 bool updateTime(Duration elapsedTime) override;
347
351 void scrollbarPolicyChanged() override;
352
356 virtual void rearrangeText();
357
359 // Called at the end of rearrangeText() to position the text pieces that were created during rearrangeText().
361 void updateTextPiecePositions(float maxWidth);
362
364 // Makes a copy of the widget
366 TGUI_NODISCARD Widget::Ptr clone() const override;
367
369 public:
370
371 SignalString onDoubleClick = {"DoubleClicked"};
372
374 protected:
375
376 String m_string;
377 std::vector<std::vector<Text>> m_lines;
378
379 // TGUI_NEXT: Remove "tgui::" prefixes
382
383 bool m_autoSize = true;
384
385 float m_maximumTextWidth = 0;
386
387 bool m_ignoringMouseEvents = false; // TGUI_NEXT: Remove this property
388
389 // Will be set to true after the first click, but gets reset to false when the second click does not occur soon after
390 bool m_possibleDoubleClick = false;
391
392 Sprite m_spriteBackground;
393
394 // Cached renderer properties
395 Borders m_bordersCached;
396 Padding m_paddingCached;
397 TextStyles m_textStyleCached;
398 Color m_textColorCached;
399 Color m_borderColorCached;
400 Color m_backgroundColorCached;
401 Color m_textOutlineColorCached = Color::Black;
402 float m_textOutlineThicknessCached = 0;
403
405 };
406
408}
409
411
412#endif // TGUI_LABEL_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Clickable widget.
Definition ClickableWidget.hpp:38
Wrapper for colors.
Definition Color.hpp:73
Container widget.
Definition Container.hpp:48
Wrapper for durations.
Definition Duration.hpp:55
Definition LabelRenderer.hpp:35
Label widget.
Definition Label.hpp:41
static Label::Ptr create(const String &text="")
Creates a new label widget.
std::shared_ptr< const Label > ConstPtr
Shared constant widget pointer.
Definition Label.hpp:45
static Label::Ptr copy(const Label::ConstPtr &label)
Makes a copy of another label.
LabelRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setText(const String &text)
Changes the text.
void setHorizontalAlignment(tgui::HorizontalAlignment alignment)
Changes the horizontal text alignment.
LabelRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
tgui::VerticalAlignment getVerticalAlignment() const
Gets the current vertical text alignment.
void setSize(const Layout2d &size) override
Changes the area of the text that will be drawn.
const String & getText() const
Returns the text.
void setVerticalAlignment(tgui::VerticalAlignment alignment)
Changes the vertical text alignment.
tgui::HorizontalAlignment getHorizontalAlignment() const
Gets the current horizontal text alignment.
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition Label.hpp:44
Class to store the position or size of a widget.
Definition Layout.hpp:323
Definition Outline.hpp:38
Base class for widgets with a single scrollbar.
Definition Scrollbar.hpp:586
Scrollbar widget.
Definition Scrollbar.hpp:44
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Definition Sprite.hpp:47
Wrapper class to store strings.
Definition String.hpp:96
Wrapper for text styles.
Definition TextStyle.hpp:55
The parent class for every widget.
Definition Widget.hpp:83
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:62
@ Left
Align to the left side.
VerticalAlignment
The vertical alignment.
Definition Layout.hpp:73
@ Top
Align to the top.
States used for drawing.
Definition RenderStates.hpp:38