26#ifndef TGUI_WIDGET_HPP
27#define TGUI_WIDGET_HPP
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>
48#if TGUI_USE_SYSTEM_AURORA
49 #include <Aurora/SmartPtr/CopiedPtr.hpp>
50 #include <Aurora/Tools/Downcast.hpp>
52 #include <TGUI/extlibs/Aurora/SmartPtr/CopiedPtr.hpp>
53 #include <TGUI/extlibs/Aurora/Tools/Downcast.hpp>
56#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
57 #include <unordered_set>
62TGUI_MODULE_EXPORT
namespace tgui
78TGUI_MODULE_EXPORT
namespace tgui
83 class TGUI_API
Widget :
public std::enable_shared_from_this<Widget>
87 using Ptr = std::shared_ptr<Widget>;
88 using ConstPtr = std::shared_ptr<const Widget>;
97 Widget(
const char* typeName,
bool initRenderer);
138 TGUI_NODISCARD virtual const
WidgetRenderer* getSharedRenderer() const;
172 virtual
void setPosition(const
Layout2d& position);
190 setPosition({std::move(x), std::move(y)});
200 return m_position.getValue();
232 setSize({std::move(width), std::move(height)});
245 setSize({std::move(width), m_size.y});
258 setSize({m_size.x, std::move(height)});
268 return m_size.getValue();
397 setScale({scaleFactor, scaleFactor});
415 setScale({scaleFactor, scaleFactor}, origin);
425 return m_scaleFactors;
466 return m_rotationDeg;
656 m_userData = std::move(userData);
664 template <
typename DataType>
667 return AnyCast<DataType>(m_userData);
676 return m_userData.has_value();
928 virtual void setParent(
Container* parent);
934 virtual bool updateTime(
Duration elapsedTime);
940 void setAutoLayoutUpdateEnabled(
bool enabled);
960 virtual void leftMouseReleased(
Vector2f pos);
965 virtual void rightMousePressed(
Vector2f pos);
970 virtual void rightMouseReleased(
Vector2f pos);
980 virtual void mouseMoved(
Vector2f pos);
1001 virtual void textEntered(
char32_t key);
1017 virtual void mouseNoLongerOnWidget();
1022 virtual void leftMouseButtonNoLongerDown();
1027 virtual void rightMouseButtonNoLongerDown();
1041 TGUI_NODISCARD
const Layout2d& getPositionLayout()
const
1050 TGUI_NODISCARD
const Layout2d& getSizeLayout()
const
1059 void bindPositionLayout(Layout* layout);
1065 void unbindPositionLayout(Layout* layout);
1071 void bindSizeLayout(Layout* layout);
1077 void unbindSizeLayout(Layout* layout);
1092 template <
typename W
idgetType>
1093 TGUI_NODISCARD std::shared_ptr<const WidgetType>
cast()
const
1095 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1101 template <
typename W
idgetType>
1102 TGUI_NODISCARD std::shared_ptr<WidgetType>
cast()
1104 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1121 void rendererChangedCallback(
const String& property);
1127 virtual void updateTextSize();
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>>;
1145 TGUI_NODISCARD
virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1150 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1206 unsigned int m_textSize = 0;
1209 Optional<Vector2f> m_rotationOrigin;
1210 Optional<Vector2f> m_scaleOrigin;
1212 float m_rotationDeg = 0;
1220 std::unordered_set<Layout*> m_boundPositionLayouts;
1221 std::unordered_set<Layout*> m_boundSizeLayouts;
1228 bool m_enabled =
true;
1235 bool m_visible =
true;
1242 bool m_mouseHover =
false;
1243 bool m_mouseDown =
false;
1246 bool m_focused =
false;
1249 bool m_focusable =
true;
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;
1261 bool m_containerWidget =
false;
1267 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1270 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1273 Font m_inheritedFont;
1274 float m_inheritedOpacity = 1;
1278 AutoLayout m_autoLayout = AutoLayout::Manual;
1279 bool m_autoLayoutUpdateEnabled =
true;
1282 Font m_fontCached = Font::getGlobalFont();
1283 float m_opacityCached = 1;
1284 bool m_transparentTextureCached =
false;
1285 unsigned int m_textSizeCached = 0;
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
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