TGUI  1.1
Loading...
Searching...
No Matches
Widget.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_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
365 void setScale(Vector2f scaleFactors);
366
380 void setScale(Vector2f scaleFactors, Vector2f origin);
381
395 void setScale(float scaleFactor)
396 {
397 setScale({scaleFactor, scaleFactor});
398 }
399
413 void setScale(float scaleFactor, Vector2f origin)
414 {
415 setScale({scaleFactor, scaleFactor}, origin);
416 }
417
423 TGUI_NODISCARD Vector2f getScale() const
424 {
425 return m_scaleFactors;
426 }
427
433 TGUI_NODISCARD Vector2f getScaleOrigin() const;
434
445 void setRotation(float angle);
446
457 void setRotation(float angle, Vector2f origin);
458
464 TGUI_NODISCARD float getRotation() const
465 {
466 return m_rotationDeg;
467 }
468
474 TGUI_NODISCARD Vector2f getRotationOrigin() const;
475
495
515
522 void moveWithAnimation(Layout2d position, Duration duration);
523
531
539 virtual void setVisible(bool visible);
540
549 TGUI_NODISCARD bool isVisible() const
550 {
551 return m_visible;
552 }
553
561 virtual void setEnabled(bool enabled);
562
571 TGUI_NODISCARD bool isEnabled() const
572 {
573 return m_enabled;
574 }
575
584 virtual void setFocused(bool focused);
585
591 TGUI_NODISCARD bool isFocused() const
592 {
593 return m_focused;
594 }
595
601 TGUI_NODISCARD const String& getWidgetType() const;
602
608 TGUI_NODISCARD Container* getParent() const
609 {
610 return m_parent;
611 }
612
618 TGUI_NODISCARD BackendGui* getParentGui() const
619 {
620 return m_parentGui;
621 }
622
628 TGUI_NODISCARD bool isAnimationPlaying() const;
629
636
643
654 void setUserData(Any userData)
655 {
656 m_userData = std::move(userData);
657 }
658
664 template <typename DataType>
665 TGUI_NODISCARD DataType getUserData() const
666 {
667 return AnyCast<DataType>(m_userData);
668 }
669
674 TGUI_NODISCARD bool hasUserData() const
675 {
676 return m_userData.has_value();
677 }
678
687 void setInheritedFont(const Font& font);
688
694 TGUI_NODISCARD const Font& getInheritedFont() const;
695
704 void setInheritedOpacity(float opacity);
705
711 TGUI_NODISCARD float getInheritedOpacity() const;
712
720 void setTextSize(unsigned int size);
721
730 TGUI_NODISCARD unsigned int getTextSize() const;
731
737 void setToolTip(Widget::Ptr toolTip);
738
744 TGUI_NODISCARD Widget::Ptr getToolTip() const;
745
758 void setWidgetName(const String& name);
759
765 TGUI_NODISCARD String getWidgetName() const;
766
775
781 TGUI_NODISCARD Cursor::Type getMouseCursor() const;
782
790 void setFocusable(bool focusable);
791
799 TGUI_NODISCARD bool isFocusable() const;
800
810 void setNavigationUp(const Widget::Ptr& widgetAbove);
811
819 TGUI_NODISCARD Widget::Ptr getNavigationUp() const;
820
830 void setNavigationDown(const Widget::Ptr& widgetBelow);
831
839 TGUI_NODISCARD Widget::Ptr getNavigationDown() const;
840
850 void setNavigationLeft(const Widget::Ptr& widgetLeft);
851
859 TGUI_NODISCARD Widget::Ptr getNavigationLeft() const;
860
870 void setNavigationRight(const Widget::Ptr& widgetRight);
871
879 TGUI_NODISCARD Widget::Ptr getNavigationRight() const;
880
885
892 TGUI_NODISCARD virtual bool canGainFocus() const;
893
898 TGUI_NODISCARD bool isContainer() const;
899
904 TGUI_NODISCARD bool isDraggableWidget() const;
905
910 TGUI_NODISCARD bool isMouseDown() const;
911
921 TGUI_NODISCARD virtual Signal& getSignal(String signalName);
922
928 virtual void setParent(Container* parent);
929
934 virtual bool updateTime(Duration elapsedTime);
935
940 void setAutoLayoutUpdateEnabled(bool enabled);
941
946 TGUI_NODISCARD virtual bool isMouseOnWidget(Vector2f pos) const = 0;
947
955 virtual bool leftMousePressed(Vector2f pos);
956
960 virtual void leftMouseReleased(Vector2f pos);
961
965 virtual void rightMousePressed(Vector2f pos);
966
970 virtual void rightMouseReleased(Vector2f pos);
971
975 virtual void mouseReleased(Event::MouseButton button, Vector2f pos);
976
980 virtual void mouseMoved(Vector2f pos);
981
985 virtual void keyPressed(const Event::KeyEvent& event);
986
996 virtual bool canHandleKeyPress(const Event::KeyEvent& event);
997
1001 virtual void textEntered(char32_t key);
1002
1012 virtual bool scrolled(float delta, Vector2f pos, bool touch);
1013
1017 virtual void mouseNoLongerOnWidget();
1018
1022 virtual void leftMouseButtonNoLongerDown();
1023
1027 virtual void rightMouseButtonNoLongerDown();
1028
1031 // Show the tool tip when the widget is located below the mouse.
1032 // Returns its tool tip or the tool tip from a child widget if the mouse is on top of the widget.
1033 // A nullptr is returned when the mouse is not on top of the widget or when the tool tip is empty.
1035 TGUI_NODISCARD virtual Widget::Ptr askToolTip(Vector2f mousePos);
1036
1041 TGUI_NODISCARD const Layout2d& getPositionLayout() const
1042 {
1043 return m_position;
1044 }
1045
1050 TGUI_NODISCARD const Layout2d& getSizeLayout() const
1051 {
1052 return m_size;
1053 }
1054
1059 void bindPositionLayout(Layout* layout);
1060
1065 void unbindPositionLayout(Layout* layout);
1066
1071 void bindSizeLayout(Layout* layout);
1072
1077 void unbindSizeLayout(Layout* layout);
1078
1087 virtual void draw(BackendRenderTarget& target, RenderStates states) const = 0;
1088
1092 template <typename WidgetType>
1093 TGUI_NODISCARD std::shared_ptr<const WidgetType> cast() const
1094 {
1095 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1096 }
1097
1101 template <typename WidgetType>
1102 TGUI_NODISCARD std::shared_ptr<WidgetType> cast()
1103 {
1104 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1105 }
1106
1115 TGUI_NODISCARD virtual Widget::Ptr clone() const = 0;
1116
1121 void rendererChangedCallback(const String& property);
1122
1127 virtual void updateTextSize();
1128
1130 protected:
1131
1132 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>, String>>;
1133 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1134
1140 virtual void rendererChanged(const String& property);
1141
1145 TGUI_NODISCARD virtual std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const;
1146
1150 virtual void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers);
1151
1155 virtual void mouseEnteredWidget();
1156
1160 virtual void mouseLeftWidget();
1161
1166
1171
1173 public:
1174
1175 SignalVector2f onPositionChange = {"PositionChanged"};
1176 SignalVector2f onSizeChange = {"SizeChanged"};
1177 Signal onFocus = {"Focused"};
1178 Signal onUnfocus = {"Unfocused"};
1179 Signal onMouseEnter = {"MouseEntered"};
1180 Signal onMouseLeave = {"MouseLeft"};
1181 SignalShowEffect onShowEffectFinish = {"ShowEffectFinished"};
1182
1189 SignalAnimationType onAnimationFinish = {"AnimationFinished"};
1190
1192 protected:
1193
1194 String m_type;
1195 String m_name;
1196
1201
1206 unsigned int m_textSize = 0; // This may be overwritten by the renderer, m_textSizeCached contains the actual text size
1207
1208 Vector2f m_origin;
1209 Optional<Vector2f> m_rotationOrigin;
1210 Optional<Vector2f> m_scaleOrigin;
1211 Vector2f m_scaleFactors = {1, 1};
1212 float m_rotationDeg = 0;
1213
1214 // The previous position and size have to be stored because when setPosition/setSize is called, the layout may already be
1215 // changed and there would be no way for the widget to detect whether the values changed or not.
1216 Vector2f m_prevPosition;
1217 Vector2f m_prevSize;
1218
1219 // Layouts that need to recalculate their value when the position or size of this widget changes
1220 std::unordered_set<Layout*> m_boundPositionLayouts;
1221 std::unordered_set<Layout*> m_boundSizeLayouts;
1222
1228 bool m_enabled = true;
1229
1235 bool m_visible = true;
1236
1237 // This will point to our parent widget. If there is no parent then this will be nullptr.
1238 Container* m_parent = nullptr;
1239 BackendGui* m_parentGui = nullptr;
1240
1241 // Is the mouse on top of the widget? Did the mouse go down on the widget?
1242 bool m_mouseHover = false;
1243 bool m_mouseDown = false;
1244
1245 // Is the widget focused?
1246 bool m_focused = false;
1247
1248 // Can the widget be focused?
1249 bool m_focusable = true;
1250
1251 // Widgets that can be navigated to from this widgets with the arrow keys
1252 std::weak_ptr<Widget> m_navWidgetUp;
1253 std::weak_ptr<Widget> m_navWidgetDown;
1254 std::weak_ptr<Widget> m_navWidgetRight;
1255 std::weak_ptr<Widget> m_navWidgetLeft;
1256
1257 // Keep track of the elapsed time.
1258 Duration m_animationTimeElapsed;
1259
1260 // This is set to true for widgets that store other widgets inside them
1261 bool m_containerWidget = false;
1262
1263 // The tool tip connected to the widget
1264 Widget::Ptr m_toolTip = nullptr;
1265
1266 // Renderer of the widget
1267 aurora::CopiedPtr<WidgetRenderer> m_renderer = nullptr;
1268
1269 // Show animations
1270 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1271
1272 // Renderer properties that can be passed from containers to their children
1273 Font m_inheritedFont;
1274 float m_inheritedOpacity = 1;
1275
1276 Any m_userData;
1277 Cursor::Type m_mouseCursor = Cursor::Type::Arrow;
1278 AutoLayout m_autoLayout = AutoLayout::Manual;
1279 bool m_autoLayoutUpdateEnabled = true;
1280
1281 // Cached renderer properties
1282 Font m_fontCached = Font::getGlobalFont();
1283 float m_opacityCached = 1;
1284 bool m_transparentTextureCached = false;
1285 unsigned int m_textSizeCached = 0;
1286
1288
1289 friend class Container; // Container accesses save and load functions
1290 };
1291
1293}
1294
1296
1297#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:1205
TGUI_NODISCARD bool isFocused() const
Returns true when the widget is focused and false otherwise.
Definition Widget.hpp:591
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:1200
TGUI_NODISCARD Widget::Ptr getNavigationUp() const
Returns which widget would become focused when navigating upwards from this widget.
TGUI_NODISCARD bool isDraggableWidget() const
Returns whether the widget has something to drag (e.g. slider or scrollbar thumbs)
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:413
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:549
TGUI_NODISCARD std::shared_ptr< const WidgetType > cast() const
Downcast const widget.
Definition Widget.hpp:1093
TGUI_NODISCARD DataType getUserData() const
Returns data stored in the widget.
Definition Widget.hpp:665
TGUI_NODISCARD bool isEnabled() const
Returns true when the widget is enabled.
Definition Widget.hpp:571
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)
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:618
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:674
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:464
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:395
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
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:608
TGUI_NODISCARD std::shared_ptr< WidgetType > cast()
Downcast widget.
Definition Widget.hpp:1102
void setUserData(Any userData)
Stores some data into the widget.
Definition Widget.hpp:654
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:423
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