TGUI  1.3-dev
Loading...
Searching...
No Matches
Widget.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
26#ifndef TGUI_WIDGET_HPP
27#define TGUI_WIDGET_HPP
28
30
31#include <TGUI/Signal.hpp>
32#include <TGUI/Font.hpp>
33#include <TGUI/Sprite.hpp>
34#include <TGUI/Layout.hpp>
35#include <TGUI/String.hpp>
36#include <TGUI/Vector2.hpp>
37#include <TGUI/Duration.hpp>
38#include <TGUI/Cursor.hpp>
39#include <TGUI/Event.hpp>
40#include <TGUI/Any.hpp>
41#include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
42#include <TGUI/Loading/Theme.hpp>
43#include <TGUI/Loading/DataIO.hpp>
44#include <TGUI/Loading/Serializer.hpp>
45#include <TGUI/Loading/Deserializer.hpp>
46#include <TGUI/Renderers/WidgetRenderer.hpp>
47
48#if TGUI_USE_SYSTEM_AURORA
49 #include <Aurora/SmartPtr/CopiedPtr.hpp>
50 #include <Aurora/Tools/Downcast.hpp>
51#else
52 #include <TGUI/extlibs/Aurora/SmartPtr/CopiedPtr.hpp>
53 #include <TGUI/extlibs/Aurora/Tools/Downcast.hpp>
54#endif
55
56#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
57 #include <unordered_set>
58#endif
59
61
62TGUI_MODULE_EXPORT namespace tgui
63{
64 class BackendGui;
65 class Container;
66
67 enum class ShowEffectType;
68}
69
70namespace tgui
71{
72 namespace priv
73 {
74 class Animation;
75 }
76}
77
78TGUI_MODULE_EXPORT namespace tgui
79{
83 class TGUI_API Widget : public std::enable_shared_from_this<Widget>
84 {
85 public:
86
87 using Ptr = std::shared_ptr<Widget>;
88 using ConstPtr = std::shared_ptr<const Widget>;
89
97 Widget(const char* typeName, bool initRenderer);
98
102 Widget(const Widget&);
103
107 Widget(Widget&&) noexcept;
108
112 virtual ~Widget();
113
117 Widget& operator=(const Widget&);
118
122 Widget& operator=(Widget&&) noexcept;
123
131 void setRenderer(std::shared_ptr<RendererData> rendererData);
132
137 TGUI_NODISCARD virtual WidgetRenderer* getSharedRenderer();
138 TGUI_NODISCARD virtual const WidgetRenderer* getSharedRenderer() const;
139
145 TGUI_NODISCARD virtual WidgetRenderer* getRenderer();
146
172 virtual void setPosition(const Layout2d& position);
173
188 void setPosition(Layout x, Layout y)
189 {
190 setPosition({std::move(x), std::move(y)});
191 }
192
198 TGUI_NODISCARD Vector2f getPosition() const
199 {
200 return m_position.getValue();
201 }
202
220 virtual void setSize(const Layout2d& size);
221
230 void setSize(Layout width, Layout height)
231 {
232 setSize({std::move(width), std::move(height)});
233 }
234
243 void setWidth(Layout width)
244 {
245 setSize({std::move(width), m_size.y});
246 }
247
256 void setHeight(Layout height)
257 {
258 setSize({m_size.x, std::move(height)});
259 }
260
266 TGUI_NODISCARD Vector2f getSize() const
267 {
268 return m_size.getValue();
269 }
270
279 TGUI_NODISCARD virtual Vector2f getFullSize() const;
280
288 TGUI_NODISCARD virtual Vector2f getAbsolutePosition(Vector2f offset = {}) const;
289
297 TGUI_NODISCARD virtual Vector2f getWidgetOffset() const;
298
307
315 TGUI_NODISCARD AutoLayout getAutoLayout() const;
316
327 void setOrigin(float x, float y)
328 {
329 setOrigin({x, y});
330 }
331
341 void setOrigin(Vector2f origin);
342
347 TGUI_NODISCARD Vector2f getOrigin() const
348 {
349 return m_origin;
350 }
351
363 void setScale(Vector2f scaleFactors);
364
376 void setScale(Vector2f scaleFactors, Vector2f origin);
377
389 void setScale(float scaleFactor)
390 {
391 setScale({scaleFactor, scaleFactor});
392 }
393
405 void setScale(float scaleFactor, Vector2f origin)
406 {
407 setScale({scaleFactor, scaleFactor}, origin);
408 }
409
415 TGUI_NODISCARD Vector2f getScale() const
416 {
417 return m_scaleFactors;
418 }
419
425 TGUI_NODISCARD Vector2f getScaleOrigin() const;
426
437 void setRotation(float angle);
438
449 void setRotation(float angle, Vector2f origin);
450
456 TGUI_NODISCARD float getRotation() const
457 {
458 return m_rotationDeg;
459 }
460
466 TGUI_NODISCARD Vector2f getRotationOrigin() const;
467
487
507
514 void moveWithAnimation(Layout2d position, Duration duration);
515
523
531 virtual void setVisible(bool visible);
532
541 TGUI_NODISCARD bool isVisible() const
542 {
543 return m_visible;
544 }
545
553 virtual void setEnabled(bool enabled);
554
563 TGUI_NODISCARD bool isEnabled() const
564 {
565 return m_enabled;
566 }
567
576 virtual void setFocused(bool focused);
577
583 TGUI_NODISCARD bool isFocused() const
584 {
585 return m_focused;
586 }
587
593 TGUI_NODISCARD const String& getWidgetType() const;
594
600 TGUI_NODISCARD Container* getParent() const
601 {
602 return m_parent;
603 }
604
610 TGUI_NODISCARD BackendGui* getParentGui() const
611 {
612 return m_parentGui;
613 }
614
620 TGUI_NODISCARD bool isAnimationPlaying() const;
621
628
635
646 void setUserData(Any userData)
647 {
648 m_userData = std::move(userData);
649 }
650
656 template <typename DataType>
657 TGUI_NODISCARD DataType getUserData() const
658 {
659 return AnyCast<DataType>(m_userData);
660 }
661
666 TGUI_NODISCARD bool hasUserData() const
667 {
668 return m_userData.has_value();
669 }
670
679 void setInheritedFont(const Font& font);
680
686 TGUI_NODISCARD const Font& getInheritedFont() const;
687
696 void setInheritedOpacity(float opacity);
697
703 TGUI_NODISCARD float getInheritedOpacity() const;
704
712 void setTextSize(unsigned int size);
713
722 TGUI_NODISCARD unsigned int getTextSize() const;
723
729 void setToolTip(Widget::Ptr toolTip);
730
736 TGUI_NODISCARD Widget::Ptr getToolTip() const;
737
750 void setWidgetName(const String& name);
751
757 TGUI_NODISCARD String getWidgetName() const;
758
767
773 TGUI_NODISCARD Cursor::Type getMouseCursor() const;
774
782 void setFocusable(bool focusable);
783
791 TGUI_NODISCARD bool isFocusable() const;
792
802 void setNavigationUp(const Widget::Ptr& widgetAbove);
803
811 TGUI_NODISCARD Widget::Ptr getNavigationUp() const;
812
822 void setNavigationDown(const Widget::Ptr& widgetBelow);
823
831 TGUI_NODISCARD Widget::Ptr getNavigationDown() const;
832
842 void setNavigationLeft(const Widget::Ptr& widgetLeft);
843
851 TGUI_NODISCARD Widget::Ptr getNavigationLeft() const;
852
862 void setNavigationRight(const Widget::Ptr& widgetRight);
863
871 TGUI_NODISCARD Widget::Ptr getNavigationRight() const;
872
877
884 TGUI_NODISCARD virtual bool canGainFocus() const;
885
890 TGUI_NODISCARD bool isContainer() const;
891
896 TGUI_NODISCARD bool isMouseDown() const;
897
907 TGUI_NODISCARD virtual Signal& getSignal(String signalName);
908
914 virtual void setParent(Container* parent);
915
920 virtual bool updateTime(Duration elapsedTime);
921
926 void setAutoLayoutUpdateEnabled(bool enabled);
927
932 TGUI_NODISCARD virtual bool isMouseOnWidget(Vector2f pos) const = 0;
933
941 virtual bool leftMousePressed(Vector2f pos);
942
946 virtual void leftMouseReleased(Vector2f pos);
947
951 virtual void rightMousePressed(Vector2f pos);
952
956 virtual void rightMouseReleased(Vector2f pos);
957
961 virtual void mouseReleased(Event::MouseButton button, Vector2f pos);
962
966 virtual void mouseMoved(Vector2f pos);
967
971 virtual void keyPressed(const Event::KeyEvent& event);
972
982 virtual bool canHandleKeyPress(const Event::KeyEvent& event);
983
987 virtual void textEntered(char32_t key);
988
998 virtual bool scrolled(float delta, Vector2f pos, bool touch);
999
1003 virtual void mouseNoLongerOnWidget();
1004
1008 virtual void leftMouseButtonNoLongerDown();
1009
1013 virtual void rightMouseButtonNoLongerDown();
1014
1017 // Show the tool tip when the widget is located below the mouse.
1018 // Returns its tool tip or the tool tip from a child widget if the mouse is on top of the widget.
1019 // A nullptr is returned when the mouse is not on top of the widget or when the tool tip is empty.
1021 TGUI_NODISCARD virtual Widget::Ptr askToolTip(Vector2f mousePos);
1022
1027 TGUI_NODISCARD const Layout2d& getPositionLayout() const
1028 {
1029 return m_position;
1030 }
1031
1036 TGUI_NODISCARD const Layout2d& getSizeLayout() const
1037 {
1038 return m_size;
1039 }
1040
1045 void bindPositionLayout(Layout* layout);
1046
1051 void unbindPositionLayout(Layout* layout);
1052
1057 void bindSizeLayout(Layout* layout);
1058
1063 void unbindSizeLayout(Layout* layout);
1064
1073 virtual void draw(BackendRenderTarget& target, RenderStates states) const = 0;
1074
1078 template <typename WidgetType>
1079 TGUI_NODISCARD std::shared_ptr<const WidgetType> cast() const
1080 {
1081 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1082 }
1083
1087 template <typename WidgetType>
1088 TGUI_NODISCARD std::shared_ptr<WidgetType> cast()
1089 {
1090 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1091 }
1092
1101 TGUI_NODISCARD virtual Widget::Ptr clone() const = 0;
1102
1107 void rendererChangedCallback(const String& property);
1108
1113 virtual void updateTextSize();
1114
1116 protected:
1117
1118 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>, String>>;
1119 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1120
1126 virtual void rendererChanged(const String& property);
1127
1131 TGUI_NODISCARD virtual std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const;
1132
1136 virtual void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers);
1137
1141 virtual void mouseEnteredWidget();
1142
1146 virtual void mouseLeftWidget();
1147
1152
1157
1159 public:
1160
1161 SignalVector2f onPositionChange = {"PositionChanged"};
1162 SignalVector2f onSizeChange = {"SizeChanged"};
1163 Signal onFocus = {"Focused"};
1164 Signal onUnfocus = {"Unfocused"};
1165 Signal onMouseEnter = {"MouseEntered"};
1166 Signal onMouseLeave = {"MouseLeft"};
1167 SignalShowEffect onShowEffectFinish = {"ShowEffectFinished"};
1168
1175 SignalAnimationType onAnimationFinish = {"AnimationFinished"};
1176
1178 protected:
1179
1180 String m_type;
1181 String m_name;
1182
1187
1192 unsigned int m_textSize = 0; // This may be overwritten by the renderer, m_textSizeCached contains the actual text size
1193
1194 Vector2f m_origin;
1195 Optional<Vector2f> m_rotationOrigin;
1196 Optional<Vector2f> m_scaleOrigin;
1197 Vector2f m_scaleFactors = {1, 1};
1198 float m_rotationDeg = 0;
1199
1200 // The previous position and size have to be stored because when setPosition/setSize is called, the layout may already be
1201 // changed and there would be no way for the widget to detect whether the values changed or not.
1202 Vector2f m_prevPosition;
1203 Vector2f m_prevSize;
1204
1205 // Layouts that need to recalculate their value when the position or size of this widget changes
1206 std::unordered_set<Layout*> m_boundPositionLayouts;
1207 std::unordered_set<Layout*> m_boundSizeLayouts;
1208
1214 bool m_enabled = true;
1215
1221 bool m_visible = true;
1222
1223 // This will point to our parent widget. If there is no parent then this will be nullptr.
1224 Container* m_parent = nullptr;
1225 BackendGui* m_parentGui = nullptr;
1226
1227 // Is the mouse on top of the widget? Did the mouse go down on the widget?
1228 bool m_mouseHover = false;
1229 bool m_mouseDown = false;
1230
1231 // Is the widget focused?
1232 bool m_focused = false;
1233
1234 // Can the widget be focused?
1235 bool m_focusable = true;
1236
1237 // Widgets that can be navigated to from this widgets with the arrow keys
1238 std::weak_ptr<Widget> m_navWidgetUp;
1239 std::weak_ptr<Widget> m_navWidgetDown;
1240 std::weak_ptr<Widget> m_navWidgetRight;
1241 std::weak_ptr<Widget> m_navWidgetLeft;
1242
1243 // Keep track of the elapsed time.
1244 Duration m_animationTimeElapsed;
1245
1246 // This is set to true for widgets that store other widgets inside them
1247 bool m_containerWidget = false;
1248
1249 // The tool tip connected to the widget
1250 Widget::Ptr m_toolTip = nullptr;
1251
1252 // Renderer of the widget
1253 aurora::CopiedPtr<WidgetRenderer> m_renderer = nullptr;
1254
1255 // Show animations
1256 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1257
1258 // Renderer properties that can be passed from containers to their children
1259 Font m_inheritedFont;
1260 float m_inheritedOpacity = 1;
1261
1262 Any m_userData;
1263 Cursor::Type m_mouseCursor = Cursor::Type::Arrow;
1264 AutoLayout m_autoLayout = AutoLayout::Manual;
1265 bool m_autoLayoutUpdateEnabled = true;
1266
1267 // Cached renderer properties
1268 Font m_fontCached = Font::getGlobalFont();
1269 float m_opacityCached = 1;
1270 bool m_transparentTextureCached = false;
1271 unsigned int m_textSizeCached = 0;
1272
1274
1275 friend class Container; // Container accesses save and load functions
1276 };
1277
1279}
1280
1282
1283#endif // TGUI_WIDGET_HPP
Base class for the Gui.
Definition BackendGui.hpp:48
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Container widget.
Definition Container.hpp:49
Type
List of available cursors.
Definition Cursor.hpp:51
Wrapper for durations.
Definition Duration.hpp:56
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:61
Class to store the position or size of a widget.
Definition Layout.hpp:305
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:70
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:1051
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:941
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
Base class for all renderer classes.
Definition WidgetRenderer.hpp:72
The parent class for every widget.
Definition Widget.hpp:84
virtual TGUI_NODISCARD Vector2f getFullSize() const
Returns the entire size that the widget is using.
void showWithEffect(ShowEffectType type, Duration duration)
Shows the widget by introducing it with an animation.
void setSize(Layout width, Layout height)
Changes the size of the widget.
Definition Widget.hpp:230
void moveToFront()
Places the widget before all other widgets.
void setTextSize(unsigned int size)
Changes the character size of text in this widget if it uses text.
Layout2d m_size
Stores the size of this widget.
Definition Widget.hpp:1191
TGUI_NODISCARD bool isFocused() const
Returns true when the widget is focused and false otherwise.
Definition Widget.hpp:583
void setHeight(Layout height)
Changes the height of the widget.
Definition Widget.hpp:256
virtual TGUI_NODISCARD Widget::Ptr clone() const =0
Makes a copy of the widget if you don't know its exact type.
Layout2d m_position
Stores the position of this widget.
Definition Widget.hpp:1186
TGUI_NODISCARD Widget::Ptr getNavigationUp() const
Returns which widget would become focused when navigating upwards from this widget.
TGUI_NODISCARD Widget::Ptr getNavigationDown() const
Returns which widget would become focused when navigating downwards from this widget.
void recalculateBoundPositionLayouts()
Calls recalculateValue() on each layout in m_boundPositionLayouts.
void resizeWithAnimation(Layout2d size, Duration duration)
Resizes the widget from its current size to the given size, over a given duration.
virtual TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const =0
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
void setScale(float scaleFactor, Vector2f origin)
Sets the scaling to be applied to the widget.
Definition Widget.hpp:405
TGUI_NODISCARD Cursor::Type getMouseCursor() const
Returns which mouse cursor is shown when hovering over the widget.
void setScale(Vector2f scaleFactors, Vector2f origin)
Sets the scaling to be applied to the widget.
void setScale(Vector2f scaleFactors)
Sets the scaling to be applied to the widget.
TGUI_NODISCARD Vector2f getPosition() const
Gets the position of the widget.
Definition Widget.hpp:198
void setFocusable(bool focusable)
Changes whether a widget could be focused.
TGUI_NODISCARD bool isFocusable() const
Returns whether a widget could be focused.
void setNavigationRight(const Widget::Ptr &widgetRight)
Changes which widget should become focused when navigating to the right from this widget.
void setOrigin(float x, float y)
Sets the origin point on which the position, scale and rotation is based.
Definition Widget.hpp:327
virtual void draw(BackendRenderTarget &target, RenderStates states) const =0
Draw the widget to a render target.
TGUI_NODISCARD Vector2f getScaleOrigin() const
Returns the origin used for scaling.
TGUI_NODISCARD String getWidgetName() const
Returns the name of a widget.
virtual TGUI_NODISCARD bool canGainFocus() const
Returns whether the widget can currently gain focus.
TGUI_NODISCARD unsigned int getTextSize() const
Returns the character size of text in this widget.
void setNavigationUp(const Widget::Ptr &widgetAbove)
Changes which widget should become focused when navigating upwards from this widget.
void setRotation(float angle, Vector2f origin)
Sets the rotation to be applied to the widget.
TGUI_NODISCARD bool isVisible() const
Returns true when the widget is visible.
Definition Widget.hpp:541
TGUI_NODISCARD std::shared_ptr< const WidgetType > cast() const
Downcast const widget.
Definition Widget.hpp:1079
TGUI_NODISCARD DataType getUserData() const
Returns data stored in the widget.
Definition Widget.hpp:657
TGUI_NODISCARD bool isEnabled() const
Returns true when the widget is enabled.
Definition Widget.hpp:563
virtual void mouseEnteredWidget()
This function is called when the mouse enters the widget.
TGUI_NODISCARD bool isContainer() const
Returns whether the widget is a container widget or not.
void setAutoLayout(AutoLayout layout)
Sets how the position is determined compared to the other widgets in the parent.
TGUI_NODISCARD const Font & getInheritedFont() const
Returns the font of the widget that is used when no font is set in the renderer.
void setWidth(Layout width)
Changes the width of the widget.
Definition Widget.hpp:243
virtual void mouseLeftWidget()
This function is called when the mouse leaves the widget.
virtual void rendererChanged(const String &property)
Function called when one of the properties of the renderer is changed.
void moveToBack()
Places the widget behind all other widgets.
virtual TGUI_NODISCARD std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const
Saves the widget as a tree node in order to save it to a file.
TGUI_NODISCARD Widget::Ptr getNavigationLeft() const
Returns which widget would become focused when navigating to the left from this widget.
TGUI_NODISCARD bool isMouseDown() const
Returns whether the left mouse button has been pressed on top of the widget.
Widget(Widget &&) noexcept
Move constructor.
virtual TGUI_NODISCARD Vector2f getWidgetOffset() const
Returns the distance between the position where the widget is drawn and where the widget is placed.
Widget(const Widget &)
Copy constructor.
virtual void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers)
Loads the widget from a tree of nodes.
std::shared_ptr< const Widget > ConstPtr
Shared constant widget pointer.
Definition Widget.hpp:88
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
virtual bool scrolled(float delta, Vector2f pos, bool touch)
Called by the parent on scroll event (either from mouse wheel of from two finger scrolling on a touch...
TGUI_NODISCARD Vector2f getSize() const
Returns the size of the widget.
Definition Widget.hpp:266
void setWidgetName(const String &name)
Changes the name of a widget.
TGUI_NODISCARD Vector2f getOrigin() const
Returns the relative origin point on which the position, scale and rotation is based.
Definition Widget.hpp:347
TGUI_NODISCARD Vector2f getRotationOrigin() const
Returns the origin used for rotations.
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual bool canHandleKeyPress(const Event::KeyEvent &event)
Called by the parent of the widget to check if keyPressed would process the event.
void finishAllAnimations()
Makes all animations of the widget finish immediately.
TGUI_NODISCARD BackendGui * getParentGui() const
Returns a pointer to the gui to which this widget belongs.
Definition Widget.hpp:610
TGUI_NODISCARD Widget::Ptr getNavigationRight() const
Returns which widget would become focused when navigating to the right from this widget.
TGUI_NODISCARD Widget::Ptr getToolTip() const
Returns the tool tip that is displayed when hovering over the widget.
TGUI_NODISCARD const String & getWidgetType() const
Returns the type of the widget.
void setMouseCursor(Cursor::Type cursor)
Changes which mouse cursor is shown when hovering over the widget.
virtual bool leftMousePressed(Vector2f pos)
Called by the parent when the left mouse button goes down on top of the widget.
TGUI_NODISCARD bool hasUserData() const
Returns whether data stored in the widget.
Definition Widget.hpp:666
virtual void setFocused(bool focused)
Focus or unfocus the widget.
TGUI_NODISCARD float getRotation() const
Returns the rotation to be applied to the widget.
Definition Widget.hpp:456
virtual void setVisible(bool visible)
Shows or hides a widget.
void setScale(float scaleFactor)
Sets the scaling to be applied to the widget.
Definition Widget.hpp:389
void setInheritedOpacity(float opacity)
Sets the opacity of the widget that will be multiplied with the opacity set in the renderer.
TGUI_NODISCARD float getInheritedOpacity() const
Returns the opacity of the widget that is multiplied with the opacity set in the renderer.
void setRotation(float angle)
Sets the rotation to be applied to the widget.
TGUI_NODISCARD AutoLayout getAutoLayout() const
Returns how the position is determined compared to the other widgets in the parent.
void setNavigationLeft(const Widget::Ptr &widgetLeft)
Changes which widget should become focused when navigating to the left from this widget.
TGUI_NODISCARD Container * getParent() const
Returns a pointer to the parent widget.
Definition Widget.hpp:600
TGUI_NODISCARD std::shared_ptr< WidgetType > cast()
Downcast widget.
Definition Widget.hpp:1088
void setUserData(Any userData)
Stores some data into the widget.
Definition Widget.hpp:646
void setToolTip(Widget::Ptr toolTip)
Sets the tool tip that should be displayed when hovering over the widget.
void setInheritedFont(const Font &font)
Sets the font of the widget that is used when no font is set in the renderer.
void moveWithAnimation(Layout2d position, Duration duration)
Moves the widget from its current position to the given position, over a given duration.
TGUI_NODISCARD Vector2f getScale() const
Returns the scaling to be applied to the widget.
Definition Widget.hpp:415
virtual TGUI_NODISCARD Signal & getSignal(String signalName)
Retrieves a signal based on its name.
void setNavigationDown(const Widget::Ptr &widgetBelow)
Changes which widget should become focused when navigating downwards from this widget.
void setOrigin(Vector2f origin)
Sets the origin point on which the position, scale and rotation is based.
virtual void setEnabled(bool enabled)
Enables or disables the widget.
virtual TGUI_NODISCARD Vector2f getAbsolutePosition(Vector2f offset={}) const
Get the absolute position of the widget instead of the relative position to its parent.
void recalculateBoundSizeLayouts()
Calls recalculateValue() on each layout in m_boundSizeLayouts.
void hideWithEffect(ShowEffectType type, Duration duration)
Hides the widget by making it leave with an animation.
TGUI_NODISCARD bool isAnimationPlaying() const
Returns whether there is an active animation (started with showWithEffect or hideWithEffect)
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
ShowEffectType
Type of effect to show/hide widget.
Definition Animation.hpp:47
AutoLayout
Alignments for how to position a widget in its parent.
Definition Layout.hpp:53
KeyPressed event parameters.
Definition Event.hpp:169
MouseButton
Mouse buttons.
Definition Event.hpp:150
States used for drawing.
Definition RenderStates.hpp:39
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:50