TGUI 1.11
Loading...
Searching...
No Matches
Widget.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 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_WIDGET_HPP
26#define TGUI_WIDGET_HPP
27
29
30#include <TGUI/Signal.hpp>
31#include <TGUI/Font.hpp>
32#include <TGUI/Sprite.hpp>
33#include <TGUI/Layout.hpp>
34#include <TGUI/String.hpp>
35#include <TGUI/Vector2.hpp>
36#include <TGUI/Duration.hpp>
37#include <TGUI/CopiedPtr.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#include <unordered_set>
49
51
52// We used to rely on Aurora (https://bromeon.ch/libraries/aurora/index.html) for some functionality.
53// For backwards compatibility the replacement functions are still placed in the aurora namespace.
54// TGUI_NEXT: Remove this namespace and the include files in the extlibs folder.
55namespace aurora
56{
57 using tgui::CopiedPtr;
58 using tgui::makeCopied;
59 using tgui::downcast;
60}
62namespace 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
78namespace 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
91 /// @internal
92 /// @brief Constructor
93 /// @param typeName Type of the widget
94 /// @param initRenderer Should the renderer be initialized? Should be true unless a derived class initializes it.
95 /// @see create
96 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
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
496
525
532 void moveWithAnimation(Layout2d position, Duration duration);
533
541
549 virtual void setVisible(bool visible);
550
559 TGUI_NODISCARD bool isVisible() const
560 {
561 return m_visible;
562 }
563
571 virtual void setEnabled(bool enabled);
572
581 TGUI_NODISCARD bool isEnabled() const
582 {
583 return m_enabled;
584 }
585
594 virtual void setFocused(bool focused);
595
601 TGUI_NODISCARD bool isFocused() const
602 {
603 return m_focused;
604 }
605
611 TGUI_NODISCARD const String& getWidgetType() const;
612
618 TGUI_NODISCARD Container* getParent() const
619 {
620 return m_parent;
621 }
622
628 TGUI_NODISCARD BackendGui* getParentGui() const
629 {
630 return m_parentGui;
631 }
632
638 TGUI_NODISCARD bool isAnimationPlaying() const;
639
646
653
664 void setUserData(Any userData)
665 {
666 m_userData = std::move(userData);
667 }
668
674 template <typename DataType>
675 TGUI_NODISCARD DataType getUserData() const
676 {
677 return AnyCast<DataType>(m_userData);
678 }
679
684 TGUI_NODISCARD bool hasUserData() const
685 {
686 return m_userData.has_value();
687 }
688
697 void setInheritedFont(const Font& font);
698
704 TGUI_NODISCARD const Font& getInheritedFont() const;
705
714 void setInheritedOpacity(float opacity);
715
721 TGUI_NODISCARD float getInheritedOpacity() const;
722
730 void setTextSize(unsigned int size);
731
740 TGUI_NODISCARD unsigned int getTextSize() const;
741
747 void setToolTip(Widget::Ptr toolTip);
748
754 TGUI_NODISCARD Widget::Ptr getToolTip() const;
755
768 void setWidgetName(const String& name);
769
775 TGUI_NODISCARD String getWidgetName() const;
776
785
791 TGUI_NODISCARD Cursor::Type getMouseCursor() const;
792
800 void setFocusable(bool focusable);
801
809 TGUI_NODISCARD bool isFocusable() const;
810
820 void setNavigationUp(const Widget::Ptr& widgetAbove);
821
829 TGUI_NODISCARD Widget::Ptr getNavigationUp() const;
830
840 void setNavigationDown(const Widget::Ptr& widgetBelow);
841
849 TGUI_NODISCARD Widget::Ptr getNavigationDown() const;
850
860 void setNavigationLeft(const Widget::Ptr& widgetLeft);
861
869 TGUI_NODISCARD Widget::Ptr getNavigationLeft() const;
870
880 void setNavigationRight(const Widget::Ptr& widgetRight);
881
889 TGUI_NODISCARD Widget::Ptr getNavigationRight() const;
890
903 void setIgnoreMouseEvents(bool ignore);
904
912 TGUI_NODISCARD bool getIgnoreMouseEvents() const;
913
918
925 TGUI_NODISCARD virtual bool canGainFocus() const;
926
931 TGUI_NODISCARD bool isContainer() const;
932
937 TGUI_NODISCARD bool isMouseDown() const;
938
948 TGUI_NODISCARD virtual Signal& getSignal(String signalName);
949
955 virtual void setParent(Container* parent);
956
961 virtual bool updateTime(Duration elapsedTime);
962
967 void setAutoLayoutUpdateEnabled(bool enabled);
968
973 TGUI_NODISCARD virtual bool isMouseOnWidget(Vector2f pos) const = 0;
974
982 virtual bool leftMousePressed(Vector2f pos);
983
987 virtual void leftMouseReleased(Vector2f pos);
988
992 virtual void rightMousePressed(Vector2f pos);
993
997 virtual void rightMouseReleased(Vector2f pos);
998
1002 virtual void mouseReleased(Event::MouseButton button, Vector2f pos);
1003
1007 virtual void mouseMoved(Vector2f pos);
1008
1012 virtual void keyPressed(const Event::KeyEvent& event);
1013
1023 virtual bool canHandleKeyPress(const Event::KeyEvent& event);
1024
1028 virtual void textEntered(char32_t key);
1029
1039 virtual bool scrolled(float delta, Vector2f pos, bool touch);
1040
1044 virtual void mouseNoLongerOnWidget();
1045
1049 virtual void leftMouseButtonNoLongerDown();
1050
1054 virtual void rightMouseButtonNoLongerDown();
1055
1058 // Show the tool tip when the widget is located below the mouse.
1059 // Returns its tool tip or the tool tip from a child widget if the mouse is on top of the widget.
1060 // A nullptr is returned when the mouse is not on top of the widget or when the tool tip is empty.
1062 TGUI_NODISCARD virtual Widget::Ptr askToolTip(Vector2f mousePos);
1063
1068 TGUI_NODISCARD const Layout2d& getPositionLayout() const
1069 {
1070 return m_position;
1071 }
1072
1077 TGUI_NODISCARD const Layout2d& getSizeLayout() const
1078 {
1079 return m_size;
1080 }
1081
1086 void bindPositionLayout(Layout* layout);
1087
1092 void unbindPositionLayout(Layout* layout);
1093
1098 void bindSizeLayout(Layout* layout);
1099
1104 void unbindSizeLayout(Layout* layout);
1105
1114 virtual void draw(BackendRenderTarget& target, RenderStates states) const = 0;
1115
1119 template <typename WidgetType>
1120 TGUI_NODISCARD std::shared_ptr<const WidgetType> cast() const
1121 {
1122 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1123 }
1124
1128 template <typename WidgetType>
1129 TGUI_NODISCARD std::shared_ptr<WidgetType> cast()
1130 {
1131 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1132 }
1133
1142 TGUI_NODISCARD virtual Widget::Ptr clone() const = 0;
1143
1148 void rendererChangedCallback(const String& property);
1149
1154 virtual void updateTextSize();
1155
1157 protected:
1158
1159 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>, String>>;
1160 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1161
1167 virtual void rendererChanged(const String& property);
1168
1172 TGUI_NODISCARD virtual std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const;
1173
1177 virtual void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers);
1178
1182 virtual void mouseEnteredWidget();
1183
1187 virtual void mouseLeftWidget();
1188
1193
1198
1200 public:
1201
1202 SignalVector2f onPositionChange = {"PositionChanged"};
1203 SignalVector2f onSizeChange = {"SizeChanged"};
1204 Signal onFocus = {"Focused"};
1205 Signal onUnfocus = {"Unfocused"};
1206 Signal onMouseEnter = {"MouseEntered"};
1207 Signal onMouseLeave = {"MouseLeft"};
1208 SignalShowEffect onShowEffectFinish = {"ShowEffectFinished"};
1209
1217
1219 protected:
1220
1221 String m_type;
1222 String m_name;
1223
1228
1233 unsigned int m_textSize = 0; // This may be overwritten by the renderer, m_textSizeCached contains the actual text size
1234
1235 Vector2f m_origin;
1236 Optional<Vector2f> m_rotationOrigin;
1237 Optional<Vector2f> m_scaleOrigin;
1238 Vector2f m_scaleFactors = {1, 1};
1239 float m_rotationDeg = 0;
1240
1241 // The previous position and size have to be stored because when setPosition/setSize is called, the layout may already be
1242 // changed and there would be no way for the widget to detect whether the values changed or not.
1243 Vector2f m_prevPosition;
1244 Vector2f m_prevSize;
1245
1246 // Layouts that need to recalculate their value when the position or size of this widget changes
1247 std::unordered_set<Layout*> m_boundPositionLayouts;
1248 std::unordered_set<Layout*> m_boundSizeLayouts;
1249
1255 bool m_enabled = true;
1256
1262 bool m_visible = true;
1263
1264 // This will point to our parent widget. If there is no parent then this will be nullptr.
1265 Container* m_parent = nullptr;
1266 BackendGui* m_parentGui = nullptr;
1267
1268 // Is the mouse on top of the widget? Did the mouse go down on the widget?
1269 bool m_mouseHover = false;
1270 bool m_mouseDown = false;
1271
1272 // Is the widget focused?
1273 bool m_focused = false;
1274
1275 // Can the widget be focused?
1276 bool m_focusable = true;
1277
1278 // Widgets that can be navigated to from this widgets with the arrow keys
1279 std::weak_ptr<Widget> m_navWidgetUp;
1280 std::weak_ptr<Widget> m_navWidgetDown;
1281 std::weak_ptr<Widget> m_navWidgetRight;
1282 std::weak_ptr<Widget> m_navWidgetLeft;
1283
1284 // Keep track of the elapsed time.
1285 Duration m_animationTimeElapsed;
1286
1287 // This is set to true for widgets that store other widgets inside them
1288 bool m_containerWidget = false;
1289
1290 // The tool tip connected to the widget
1291 Widget::Ptr m_toolTip = nullptr;
1292
1293 // Renderer of the widget
1294 CopiedPtr<WidgetRenderer> m_renderer = nullptr;
1295
1296 // Show animations
1297 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1298
1299 // Renderer properties that can be passed from containers to their children
1300 Font m_inheritedFont;
1301 float m_inheritedOpacity = 1;
1302
1303 Any m_userData;
1304 Cursor::Type m_mouseCursor = Cursor::Type::Arrow;
1305 AutoLayout m_autoLayout = AutoLayout::Manual;
1306 bool m_autoLayoutUpdateEnabled = true;
1307 bool m_ignoreMouseEvents = false;
1308
1309 // Cached renderer properties
1310 Font m_fontCached = Font::getGlobalFont();
1311 float m_opacityCached = 1;
1312 bool m_transparentTextureCached = false;
1313 unsigned int m_textSizeCached = 0;
1314
1316
1317 friend class Container; // Container accesses save and load functions
1318 };
1319
1321}
1322
1324
1325#endif // TGUI_WIDGET_HPP
Base class for the Gui.
Definition BackendGui.hpp:45
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Container widget.
Definition Container.hpp:46
Copyable smart pointer template.
Definition CopiedPtr.hpp:52
Type
List of available cursors.
Definition Cursor.hpp:48
@ Arrow
Arrow cursor (default)
Definition Cursor.hpp:49
Wrapper for durations.
Definition Duration.hpp:53
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:56
static Font getGlobalFont()
Returns the global font that is used for all new widgets.
Class to store the position or size of a widget.
Definition Layout.hpp:321
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:100
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:984
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:882
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Wrapper class to store strings.
Definition String.hpp:94
Base class for all renderer classes.
Definition WidgetRenderer.hpp:67
The parent class for every widget.
Definition Widget.hpp:84
void showWithEffect(ShowEffectType type, Duration duration)
Shows the widget by introducing it with an animation.
Widget::Ptr getNavigationUp() const
Returns which widget would become focused when navigating upwards from this widget.
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:1232
void setHeight(Layout height)
Changes the height of the widget.
Definition Widget.hpp:256
const String & getWidgetType() const
Returns the type of the widget.
virtual WidgetRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Layout2d m_position
Stores the position of this widget.
Definition Widget.hpp:1227
std::shared_ptr< WidgetType > cast()
Downcast widget.
Definition Widget.hpp:1129
virtual Widget::Ptr clone() const =0
Makes a copy of the widget if you don't know its exact type.
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 WidgetRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Signal onUnfocus
The widget was unfocused.
Definition Widget.hpp:1205
void setScale(float scaleFactor, Vector2f origin)
Sets the scaling to be applied to the widget.
Definition Widget.hpp:405
AutoLayout getAutoLayout() const
Returns how the position is determined compared to the other widgets in the parent.
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.
Vector2f getScale() const
Returns the scaling to be applied to the widget.
Definition Widget.hpp:415
void setFocusable(bool focusable)
Changes 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
Signal onMouseEnter
The mouse entered the widget.
Definition Widget.hpp:1206
virtual void draw(BackendRenderTarget &target, RenderStates states) const =0
Draw the widget to a render target.
unsigned int getTextSize() const
Returns the character size of text in this widget.
SignalVector2f onPositionChange
The position of the widget changed. Optional parameter: new position.
Definition Widget.hpp:1202
SignalAnimationType onAnimationFinish
An animation has finished.
Definition Widget.hpp:1216
DataType getUserData() const
Returns data stored in the widget.
Definition Widget.hpp:675
Signal onFocus
The widget was focused.
Definition Widget.hpp:1204
virtual bool canGainFocus() const
Returns whether the widget can currently gain focus.
String getWidgetName() const
Returns the name of a widget.
Container * getParent() const
Returns a pointer to the parent widget.
Definition Widget.hpp:618
Cursor::Type getMouseCursor() const
Returns which mouse cursor is shown when hovering over the widget.
void setNavigationUp(const Widget::Ptr &widgetAbove)
Changes which widget should become focused when navigating upwards from this widget.
bool isVisible() const
Returns true when the widget is visible.
Definition Widget.hpp:559
bool isFocusable() const
Returns whether a widget could be focused.
void setRotation(float angle, Vector2f origin)
Sets the rotation to be applied to the widget.
float getRotation() const
Returns the rotation to be applied to the widget.
Definition Widget.hpp:456
Vector2f getScaleOrigin() const
Returns the origin used for scaling.
bool isContainer() const
Returns whether the widget is a container widget or not.
virtual void mouseEnteredWidget()
This function is called when the mouse enters the widget.
void setAutoLayout(AutoLayout layout)
Sets how the position is determined compared to the other widgets in the parent.
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 std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const
Saves the widget as a tree node in order to save it to a file.
bool m_enabled
Stores the flag indicating whether this widget is enabled.
Definition Widget.hpp:1255
Widget(Widget &&) noexcept
Move constructor.
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
virtual Signal & getSignal(String signalName)
Retrieves a signal based on its name.
Widget::Ptr getNavigationDown() const
Returns which widget would become focused when navigating downwards from this widget.
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...
bool isMouseDown() const
Returns whether the left mouse button has been pressed on top of the widget.
void setWidgetName(const String &name)
Changes the name of a widget.
Widget::Ptr getNavigationRight() const
Returns which widget would become focused when navigating to the right from this widget.
bool isAnimationPlaying() const
Returns whether there is an active animation (started with showWithEffect or hideWithEffect)
bool isEnabled() const
Returns true when the widget is enabled.
Definition Widget.hpp:581
Vector2f getOrigin() const
Returns the relative origin point on which the position, scale and rotation is based.
Definition Widget.hpp:347
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Vector2f getSize() const
Returns the size of the widget.
Definition Widget.hpp:266
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.
virtual bool isMouseOnWidget(Vector2f pos) const =0
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
Widget::Ptr getToolTip() const
Returns the tool tip that is displayed when hovering over the widget.
BackendGui * getParentGui() const
Returns a pointer to the gui to which this widget belongs.
Definition Widget.hpp:628
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.
bool m_visible
Stores the flag indicating whether this widget is visible.
Definition Widget.hpp:1262
virtual void setFocused(bool focused)
Focus or unfocus the widget.
virtual Vector2f getFullSize() const
Returns the entire size that the widget is using.
void setIgnoreMouseEvents(bool ignore)
Sets whether the widget should completely ignore mouse events and let them pass to the widgets behind...
Signal onMouseLeave
The mouse left the widget.
Definition Widget.hpp:1207
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.
bool getIgnoreMouseEvents() const
Returns whether the widget is ignoring mouse events and letting them pass to the widgets behind it.
void setRotation(float angle)
Sets the rotation to be applied to the widget.
void setNavigationLeft(const Widget::Ptr &widgetLeft)
Changes which widget should become focused when navigating to the left from this widget.
bool hasUserData() const
Returns whether data stored in the widget.
Definition Widget.hpp:684
void setUserData(Any userData)
Stores some data into the widget.
Definition Widget.hpp:664
Widget::Ptr getNavigationLeft() const
Returns which widget would become focused when navigating to the left from this widget.
void setToolTip(Widget::Ptr toolTip)
Sets the tool tip that should be displayed when hovering over the widget.
virtual Vector2f getAbsolutePosition(Vector2f offset={}) const
Get the absolute position of the widget instead of the relative position to its parent.
void setRenderer(std::shared_ptr< RendererData > rendererData)
Sets a new renderer for the widget. The renderer determines how the widget looks.
void setInheritedFont(const Font &font)
Sets the font of the widget that is used when no font is set in the renderer.
virtual Vector2f getWidgetOffset() const
Returns the distance between the position where the widget is drawn and where the widget is placed.
void moveWithAnimation(Layout2d position, Duration duration)
Moves the widget from its current position to the given position, over a given duration.
SignalShowEffect onShowEffectFinish
A show or hide effect finished. Optional parameters: effect type, new widget visibility or both.
Definition Widget.hpp:1208
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.
std::shared_ptr< const WidgetType > cast() const
Downcast const widget.
Definition Widget.hpp:1120
virtual void setEnabled(bool enabled)
Enables or disables the widget.
void recalculateBoundSizeLayouts()
Calls recalculateValue() on each layout in m_boundSizeLayouts.
float getInheritedOpacity() const
Returns the opacity of the widget that is multiplied with the opacity set in the renderer.
Vector2f getPosition() const
Gets the position of the widget.
Definition Widget.hpp:198
void hideWithEffect(ShowEffectType type, Duration duration)
Hides the widget by making it leave with an animation.
virtual void setPosition(const Layout2d &position)
sets the position of the widget
Vector2f getRotationOrigin() const
Returns the origin used for rotations.
SignalVector2f onSizeChange
The size of the widget changed. Optional parameter: new size.
Definition Widget.hpp:1203
bool isFocused() const
Returns true when the widget is focused and false otherwise.
Definition Widget.hpp:601
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
ShowEffectType
Type of effect to show/hide widget.
Definition Animation.hpp:44
CopiedPtr< T > makeCopied(Args &&... args)
Creates a CopiedPtr object that contains a value.
Definition CopiedPtr.hpp:224
SignalTyped< Vector2f > SignalVector2f
Signal with one "Vector2f" as optional unbound parameter.
Definition Signal.hpp:427
AutoLayout
Alignments for how to position a widget in its parent.
Definition Layout.hpp:83
@ Manual
Position and size need to be manually set. This is the default.
Definition Layout.hpp:84
To downcast(From &base)
Cast from a reference of a base class to a reference of a derived class.
Definition Global.hpp:166
KeyPressed event parameters.
Definition Event.hpp:168
MouseButton
Mouse buttons.
Definition Event.hpp:149
States used for drawing.
Definition RenderStates.hpp:38
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:46