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();
391 setScale({scaleFactor, scaleFactor});
407 setScale({scaleFactor, scaleFactor}, origin);
417 return m_scaleFactors;
458 return m_rotationDeg;
648 m_userData = std::move(userData);
656 template <
typename DataType>
659 return AnyCast<DataType>(m_userData);
668 return m_userData.has_value();
914 virtual void setParent(
Container* parent);
920 virtual bool updateTime(
Duration elapsedTime);
926 void setAutoLayoutUpdateEnabled(
bool enabled);
946 virtual void leftMouseReleased(
Vector2f pos);
951 virtual void rightMousePressed(
Vector2f pos);
956 virtual void rightMouseReleased(
Vector2f pos);
966 virtual void mouseMoved(
Vector2f pos);
987 virtual void textEntered(
char32_t key);
1003 virtual void mouseNoLongerOnWidget();
1008 virtual void leftMouseButtonNoLongerDown();
1013 virtual void rightMouseButtonNoLongerDown();
1027 TGUI_NODISCARD
const Layout2d& getPositionLayout()
const
1036 TGUI_NODISCARD
const Layout2d& getSizeLayout()
const
1045 void bindPositionLayout(Layout* layout);
1051 void unbindPositionLayout(Layout* layout);
1057 void bindSizeLayout(Layout* layout);
1063 void unbindSizeLayout(Layout* layout);
1078 template <
typename W
idgetType>
1079 TGUI_NODISCARD std::shared_ptr<const WidgetType>
cast()
const
1081 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1087 template <
typename W
idgetType>
1088 TGUI_NODISCARD std::shared_ptr<WidgetType>
cast()
1090 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1107 void rendererChangedCallback(
const String& property);
1113 virtual void updateTextSize();
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>>;
1131 TGUI_NODISCARD
virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1136 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1192 unsigned int m_textSize = 0;
1195 Optional<Vector2f> m_rotationOrigin;
1196 Optional<Vector2f> m_scaleOrigin;
1198 float m_rotationDeg = 0;
1206 std::unordered_set<Layout*> m_boundPositionLayouts;
1207 std::unordered_set<Layout*> m_boundSizeLayouts;
1214 bool m_enabled =
true;
1221 bool m_visible =
true;
1228 bool m_mouseHover =
false;
1229 bool m_mouseDown =
false;
1232 bool m_focused =
false;
1235 bool m_focusable =
true;
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;
1247 bool m_containerWidget =
false;
1253 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1256 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1259 Font m_inheritedFont;
1260 float m_inheritedOpacity = 1;
1264 AutoLayout m_autoLayout = AutoLayout::Manual;
1265 bool m_autoLayoutUpdateEnabled =
true;
1268 Font m_fontCached = Font::getGlobalFont();
1269 float m_opacityCached = 1;
1270 bool m_transparentTextureCached =
false;
1271 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