TGUI 1.13
Loading...
Searching...
No Matches
Widget.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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/Backend/Renderer/BackendRenderTarget.hpp>
31
32#include <TGUI/Any.hpp>
33#include <TGUI/CopiedPtr.hpp>
34#include <TGUI/Cursor.hpp>
35#include <TGUI/Duration.hpp>
36#include <TGUI/Event.hpp>
37#include <TGUI/Font.hpp>
38#include <TGUI/Layout.hpp>
39#include <TGUI/Loading/DataIO.hpp>
40#include <TGUI/Loading/Deserializer.hpp>
41#include <TGUI/Loading/Serializer.hpp>
42#include <TGUI/Loading/Theme.hpp>
43#include <TGUI/Renderers/WidgetRenderer.hpp>
44#include <TGUI/Signal.hpp>
45#include <TGUI/Sprite.hpp>
46#include <TGUI/String.hpp>
47#include <TGUI/Vector2.hpp>
48#include <TGUI/WidgetLoadResources.hpp>
49
50#include <unordered_set>
51
53
54// We used to rely on Aurora (https://bromeon.ch/libraries/aurora/index.html) for some functionality.
55// For backwards compatibility the replacement functions are still placed in the aurora namespace.
56// TGUI_NEXT: Remove this namespace and the include files in the extlibs folder.
57namespace aurora
58{
59 using tgui::CopiedPtr;
61 using tgui::makeCopied;
62} // namespace aurora
63
64namespace tgui
65{
66 class BackendGui;
67 class Container;
68
69 enum class ShowEffectType;
70} // namespace tgui
71
72namespace tgui::priv
73{
74 class Animation;
75} // namespace tgui::priv
76
77namespace tgui
78{
82 class TGUI_API Widget : public std::enable_shared_from_this<Widget>
83 {
84 public:
85 using Ptr = std::shared_ptr<Widget>;
86 using ConstPtr = std::shared_ptr<const Widget>;
87
89 /// @internal
90 /// @brief Constructor
91 /// @param typeName Type of the widget
92 /// @param initRenderer Should the renderer be initialized? Should be true unless a derived class initializes it.
93 /// @see create
94 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95 Widget(const char* typeName, bool initRenderer);
96
100 Widget(const Widget&);
101
105 Widget(Widget&&) noexcept;
106
110 virtual ~Widget();
111
115 Widget& operator=(const Widget&);
116
120 Widget& operator=(Widget&&) noexcept;
121
129 void setRenderer(std::shared_ptr<RendererData> rendererData);
130
135 [[nodiscard]] virtual WidgetRenderer* getSharedRenderer();
136 [[nodiscard]] virtual const WidgetRenderer* getSharedRenderer() const;
137
143 [[nodiscard]] virtual WidgetRenderer* getRenderer();
144
170 virtual void setPosition(const Layout2d& position);
171
187 {
188 setPosition({std::move(x), std::move(y)});
189 }
190
196 [[nodiscard]] Vector2f getPosition() const
197 {
198 return m_position.getValue();
199 }
200
218 virtual void setSize(const Layout2d& size);
219
228 void setSize(Layout width, Layout height)
229 {
230 setSize({std::move(width), std::move(height)});
231 }
232
241 void setWidth(Layout width)
242 {
243 setSize({std::move(width), m_size.y});
244 }
245
254 void setHeight(Layout height)
255 {
256 setSize({m_size.x, std::move(height)});
257 }
258
264 [[nodiscard]] Vector2f getSize() const
265 {
266 return m_size.getValue();
267 }
268
277 [[nodiscard]] virtual Vector2f getFullSize() const;
278
286 [[nodiscard]] virtual Vector2f getAbsolutePosition(Vector2f offset = {}) const;
287
295 [[nodiscard]] virtual Vector2f getWidgetOffset() const;
296
305
313 [[nodiscard]] AutoLayout getAutoLayout() const;
314
325 void setOrigin(float x, float y)
326 {
327 setOrigin({x, y});
328 }
329
339 void setOrigin(Vector2f origin);
340
345 [[nodiscard]] Vector2f getOrigin() const
346 {
347 return m_origin;
348 }
349
361 void setScale(Vector2f scaleFactors);
362
374 void setScale(Vector2f scaleFactors, Vector2f origin);
375
387 void setScale(float scaleFactor)
388 {
389 setScale({scaleFactor, scaleFactor});
390 }
391
403 void setScale(float scaleFactor, Vector2f origin)
404 {
405 setScale({scaleFactor, scaleFactor}, origin);
406 }
407
413 [[nodiscard]] Vector2f getScale() const
414 {
415 return m_scaleFactors;
416 }
417
423 [[nodiscard]] Vector2f getScaleOrigin() const;
424
435 void setRotation(float angle);
436
447 void setRotation(float angle, Vector2f origin);
448
454 [[nodiscard]] float getRotation() const
455 {
456 return m_rotationDeg;
457 }
458
464 [[nodiscard]] Vector2f getRotationOrigin() const;
465
494
523
530 void moveWithAnimation(Layout2d position, Duration duration);
531
539
547 virtual void setVisible(bool visible);
548
557 [[nodiscard]] bool isVisible() const
558 {
559 return m_visible;
560 }
561
569 virtual void setEnabled(bool enabled);
570
579 [[nodiscard]] bool isEnabled() const
580 {
581 return m_enabled;
582 }
583
592 virtual void setFocused(bool focused);
593
599 [[nodiscard]] bool isFocused() const
600 {
601 return m_focused;
602 }
603
609 [[nodiscard]] const String& getWidgetType() const;
610
616 [[nodiscard]] Container* getParent() const
617 {
618 return m_parent;
619 }
620
626 [[nodiscard]] BackendGui* getParentGui() const
627 {
628 return m_parentGui;
629 }
630
636 [[nodiscard]] bool isAnimationPlaying() const;
637
644
651
662 void setUserData(Any userData)
663 {
664 m_userData = std::move(userData);
665 }
666
672 template <typename DataType>
673 [[nodiscard]] DataType getUserData() const
674 {
675 return std::any_cast<DataType>(m_userData);
676 }
677
682 [[nodiscard]] bool hasUserData() const
683 {
684 return m_userData.has_value();
685 }
686
695 void setInheritedFont(const Font& font);
696
702 [[nodiscard]] const Font& getInheritedFont() const;
703
712 void setInheritedOpacity(float opacity);
713
719 [[nodiscard]] float getInheritedOpacity() const;
720
728 void setTextSize(unsigned int size);
729
738 [[nodiscard]] unsigned int getTextSize() const;
739
745 void setToolTip(Widget::Ptr toolTip);
746
752 [[nodiscard]] Widget::Ptr getToolTip() const;
753
766 void setWidgetName(const String& name);
767
773 [[nodiscard]] String getWidgetName() const;
774
783
789 [[nodiscard]] Cursor::Type getMouseCursor() const;
790
798 void setFocusable(bool focusable);
799
807 [[nodiscard]] bool isFocusable() const;
808
818 void setNavigationUp(const Widget::Ptr& widgetAbove);
819
827 [[nodiscard]] Widget::Ptr getNavigationUp() const;
828
838 void setNavigationDown(const Widget::Ptr& widgetBelow);
839
847 [[nodiscard]] Widget::Ptr getNavigationDown() const;
848
858 void setNavigationLeft(const Widget::Ptr& widgetLeft);
859
867 [[nodiscard]] Widget::Ptr getNavigationLeft() const;
868
878 void setNavigationRight(const Widget::Ptr& widgetRight);
879
887 [[nodiscard]] Widget::Ptr getNavigationRight() const;
888
901 void setIgnoreMouseEvents(bool ignore);
902
910 [[nodiscard]] bool getIgnoreMouseEvents() const;
911
916
923 [[nodiscard]] virtual bool canGainFocus() const;
924
929 [[nodiscard]] bool isContainer() const;
930
935 [[nodiscard]] bool isMouseDown() const;
936
946 [[nodiscard]] virtual Signal& getSignal(String signalName);
947
953 virtual void setParent(Container* parent);
954
959 virtual bool updateTime(Duration elapsedTime);
960
965 void setAutoLayoutUpdateEnabled(bool enabled);
966
971 [[nodiscard]] virtual bool isMouseOnWidget(Vector2f pos) const = 0;
972
980 virtual bool leftMousePressed(Vector2f pos);
981
985 virtual void leftMouseReleased(Vector2f pos);
986
990 virtual void rightMousePressed(Vector2f pos);
991
995 virtual void rightMouseReleased(Vector2f pos);
996
1000 virtual void mouseReleased(Event::MouseButton button, Vector2f pos);
1001
1005 virtual void mouseMoved(Vector2f pos);
1006
1010 virtual void keyPressed(const Event::KeyEvent& event);
1011
1021 virtual bool canHandleKeyPress(const Event::KeyEvent& event);
1022
1026 virtual void textEntered(char32_t key);
1027
1037 virtual bool scrolled(float delta, Vector2f pos, bool touch);
1038
1042 virtual void mouseNoLongerOnWidget();
1043
1047 virtual void leftMouseButtonNoLongerDown();
1048
1052 virtual void rightMouseButtonNoLongerDown();
1053
1056 // Show the tool tip when the widget is located below the mouse.
1057 // Returns its tool tip or the tool tip from a child widget if the mouse is on top of the widget.
1058 // A nullptr is returned when the mouse is not on top of the widget or when the tool tip is empty.
1060 [[nodiscard]] virtual Widget::Ptr askToolTip(Vector2f mousePos);
1061
1066 [[nodiscard]] const Layout2d& getPositionLayout() const
1067 {
1068 return m_position;
1069 }
1070
1075 [[nodiscard]] const Layout2d& getSizeLayout() const
1076 {
1077 return m_size;
1078 }
1079
1084 void bindPositionLayout(Layout* layout);
1085
1090 void unbindPositionLayout(Layout* layout);
1091
1096 void bindSizeLayout(Layout* layout);
1097
1102 void unbindSizeLayout(Layout* layout);
1103
1112 virtual void draw(BackendRenderTarget& target, RenderStates states) const = 0;
1113
1117 template <typename WidgetType>
1118 [[nodiscard]] std::shared_ptr<const WidgetType> cast() const
1119 {
1120 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1121 }
1122
1126 template <typename WidgetType>
1127 [[nodiscard]] std::shared_ptr<WidgetType> cast()
1128 {
1129 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1130 }
1131
1140 [[nodiscard]] virtual Widget::Ptr clone() const = 0;
1141
1146 void rendererChangedCallback(const String& property);
1147
1152 virtual void updateTextSize();
1153
1155
1156 protected:
1157 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>, String>>;
1158 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1159
1165 virtual void rendererChanged(const String& property);
1166
1170 [[nodiscard]] virtual std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const;
1171
1175 virtual void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers);
1176
1180 void load(const std::unique_ptr<DataIO::Node>& node, const WidgetLoadResources& resources);
1181
1185 virtual void mouseEnteredWidget();
1186
1190 virtual void mouseLeftWidget();
1191
1196
1201
1203
1204 public:
1205 SignalVector2f onPositionChange = {"PositionChanged"};
1206 SignalVector2f onSizeChange = {"SizeChanged"};
1207 Signal onFocus = {"Focused"};
1208 Signal onUnfocus = {"Unfocused"};
1209 Signal onMouseEnter = {"MouseEntered"};
1210 Signal onMouseLeave = {"MouseLeft"};
1212 "ShowEffectFinished"};
1213
1221
1223
1224 protected:
1225 String m_type;
1226 String m_name;
1227
1232
1237 unsigned int m_textSize = 0; // This may be overwritten by the renderer, m_textSizeCached contains the actual text size
1238
1239 Vector2f m_origin;
1240 Optional<Vector2f> m_rotationOrigin;
1241 Optional<Vector2f> m_scaleOrigin;
1242 Vector2f m_scaleFactors = {1, 1};
1243 float m_rotationDeg = 0;
1244
1245 // The previous position and size have to be stored because when setPosition/setSize is called, the layout may already be
1246 // changed and there would be no way for the widget to detect whether the values changed or not.
1247 Vector2f m_prevPosition;
1248 Vector2f m_prevSize;
1249
1250 // Layouts that need to recalculate their value when the position or size of this widget changes
1251 std::unordered_set<Layout*> m_boundPositionLayouts;
1252 std::unordered_set<Layout*> m_boundSizeLayouts;
1253
1259 bool m_enabled = true;
1260
1266 bool m_visible = true;
1267
1268 // This will point to our parent widget. If there is no parent then this will be nullptr.
1269 Container* m_parent = nullptr;
1270 BackendGui* m_parentGui = nullptr;
1271
1272 // Is the mouse on top of the widget? Did the mouse go down on the widget?
1273 bool m_mouseHover = false;
1274 bool m_mouseDown = false;
1275
1276 // Is the widget focused?
1277 bool m_focused = false;
1278
1279 // Can the widget be focused?
1280 bool m_focusable = true;
1281
1282 // Widgets that can be navigated to from this widgets with the arrow keys
1283 std::weak_ptr<Widget> m_navWidgetUp;
1284 std::weak_ptr<Widget> m_navWidgetDown;
1285 std::weak_ptr<Widget> m_navWidgetRight;
1286 std::weak_ptr<Widget> m_navWidgetLeft;
1287
1288 // Keep track of the elapsed time.
1289 Duration m_animationTimeElapsed;
1290
1291 // This is set to true for widgets that store other widgets inside them
1292 bool m_containerWidget = false;
1293
1294 // The tool tip connected to the widget
1295 Widget::Ptr m_toolTip = nullptr;
1296
1297 // Renderer of the widget
1298 CopiedPtr<WidgetRenderer> m_renderer = nullptr;
1299
1300 // Show animations
1301 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1302
1303 // Renderer properties that can be passed from containers to their children
1304 Font m_inheritedFont;
1305 float m_inheritedOpacity = 1;
1306
1307 Any m_userData;
1308 Cursor::Type m_mouseCursor = Cursor::Type::Arrow;
1309 AutoLayout m_autoLayout = AutoLayout::Manual;
1310 bool m_autoLayoutUpdateEnabled = true;
1311 bool m_ignoreMouseEvents = false;
1312
1313 // Cached renderer properties
1314 Font m_fontCached = Font::getGlobalFont();
1315 float m_opacityCached = 1;
1316 bool m_transparentTextureCached = false;
1317 unsigned int m_textSizeCached = 0;
1318
1319 const std::map<String, std::shared_ptr<Theme>>* m_loadRuntimeThemesByAlias = nullptr;
1320 const ThemeFallbackMap* m_loadThemeFallbacks = nullptr;
1321
1323
1324 friend class Container; // Container accesses save and load functions
1325 };
1326} // namespace tgui
1327
1328#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:45
Copyable smart pointer template.
Definition CopiedPtr.hpp:55
Type
List of available cursors.
Definition Cursor.hpp:48
@ Arrow
Arrow cursor (default).
Definition Cursor.hpp:49
Wrapper for durations.
Definition Duration.hpp:52
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:54
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:320
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:1017
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:907
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:68
The parent class for every widget.
Definition Widget.hpp:83
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:228
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:1236
void setHeight(Layout height)
Changes the height of the widget.
Definition Widget.hpp:254
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:1231
std::shared_ptr< WidgetType > cast()
Downcast widget.
Definition Widget.hpp:1127
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:1208
void setScale(float scaleFactor, Vector2f origin)
Sets the scaling to be applied to the widget.
Definition Widget.hpp:403
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.
void load(const std::unique_ptr< DataIO::Node > &node, const WidgetLoadResources &resources)
Loads the widget from a tree of nodes.
Vector2f getScale() const
Returns the scaling to be applied to the widget.
Definition Widget.hpp:413
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:325
Signal onMouseEnter
The mouse entered the widget.
Definition Widget.hpp:1209
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:1205
SignalAnimationType onAnimationFinish
An animation has finished.
Definition Widget.hpp:1220
DataType getUserData() const
Returns data stored in the widget.
Definition Widget.hpp:673
Signal onFocus
The widget was focused.
Definition Widget.hpp:1207
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:616
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:557
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:454
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:241
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:1259
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:86
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:85
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:579
Vector2f getOrigin() const
Returns the relative origin point on which the position, scale and rotation is based.
Definition Widget.hpp:345
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Vector2f getSize() const
Returns the size of the widget.
Definition Widget.hpp:264
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:626
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:1266
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:1210
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:387
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:682
void setUserData(Any userData)
Stores some data into the widget.
Definition Widget.hpp:662
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:1211
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:1118
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:196
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:1206
bool isFocused() const
Returns true when the widget is focused and false otherwise.
Definition Widget.hpp:599
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
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
std::map< String, std::map< String, std::shared_ptr< RendererData > > > ThemeFallbackMap
Fallback renderers from Theme.<Alias> sections in the form file.
Definition WidgetLoadResources.hpp:41
SignalTyped< Vector2f > SignalVector2f
Signal with one "Vector2f" as optional unbound parameter.
Definition Signal.hpp:414
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:182
KeyPressed event parameters.
Definition Event.hpp:166
MouseButton
Mouse buttons.
Definition Event.hpp:147
States used for drawing.
Definition RenderStates.hpp:38
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:47
Definition WidgetLoadResources.hpp:48