25#ifndef TGUI_WIDGET_HPP
26#define TGUI_WIDGET_HPP
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/Cursor.hpp>
38#include <TGUI/Event.hpp>
39#include <TGUI/Any.hpp>
40#include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
41#include <TGUI/Loading/Theme.hpp>
42#include <TGUI/Loading/DataIO.hpp>
43#include <TGUI/Loading/Serializer.hpp>
44#include <TGUI/Loading/Deserializer.hpp>
45#include <TGUI/Renderers/WidgetRenderer.hpp>
47#if TGUI_USE_SYSTEM_AURORA
48 #include <Aurora/SmartPtr/CopiedPtr.hpp>
49 #include <Aurora/Tools/Downcast.hpp>
51 #include <TGUI/extlibs/Aurora/SmartPtr/CopiedPtr.hpp>
52 #include <TGUI/extlibs/Aurora/Tools/Downcast.hpp>
55#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
56 #include <unordered_set>
61TGUI_MODULE_EXPORT
namespace tgui
77TGUI_MODULE_EXPORT
namespace tgui
82 class TGUI_API
Widget :
public std::enable_shared_from_this<Widget>
86 using Ptr = std::shared_ptr<Widget>;
87 using ConstPtr = std::shared_ptr<const Widget>;
96 Widget(
const char* typeName,
bool initRenderer);
137 TGUI_NODISCARD virtual const
WidgetRenderer* getSharedRenderer() const;
171 virtual
void setPosition(const
Layout2d& position);
189 setPosition({std::move(x), std::move(y)});
199 return m_position.getValue();
231 setSize({std::move(width), std::move(height)});
244 setSize({std::move(width), m_size.y});
257 setSize({m_size.x, std::move(height)});
267 return m_size.getValue();
390 setScale({scaleFactor, scaleFactor});
406 setScale({scaleFactor, scaleFactor}, origin);
416 return m_scaleFactors;
457 return m_rotationDeg;
665 m_userData = std::move(userData);
673 template <
typename DataType>
676 return AnyCast<DataType>(m_userData);
685 return m_userData.has_value();
954 virtual void setParent(
Container* parent);
960 virtual bool updateTime(
Duration elapsedTime);
966 void setAutoLayoutUpdateEnabled(
bool enabled);
986 virtual void leftMouseReleased(
Vector2f pos);
991 virtual void rightMousePressed(
Vector2f pos);
996 virtual void rightMouseReleased(
Vector2f pos);
1006 virtual void mouseMoved(
Vector2f pos);
1027 virtual void textEntered(
char32_t key);
1043 virtual void mouseNoLongerOnWidget();
1048 virtual void leftMouseButtonNoLongerDown();
1053 virtual void rightMouseButtonNoLongerDown();
1067 TGUI_NODISCARD
const Layout2d& getPositionLayout()
const
1076 TGUI_NODISCARD
const Layout2d& getSizeLayout()
const
1085 void bindPositionLayout(Layout* layout);
1091 void unbindPositionLayout(Layout* layout);
1097 void bindSizeLayout(Layout* layout);
1103 void unbindSizeLayout(Layout* layout);
1118 template <
typename W
idgetType>
1119 TGUI_NODISCARD std::shared_ptr<const WidgetType>
cast()
const
1121 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1127 template <
typename W
idgetType>
1128 TGUI_NODISCARD std::shared_ptr<WidgetType>
cast()
1130 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1147 void rendererChangedCallback(
const String& property);
1153 virtual void updateTextSize();
1158 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>,
String>>;
1159 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1171 TGUI_NODISCARD
virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1176 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1232 unsigned int m_textSize = 0;
1235 Optional<Vector2f> m_rotationOrigin;
1236 Optional<Vector2f> m_scaleOrigin;
1238 float m_rotationDeg = 0;
1246 std::unordered_set<Layout*> m_boundPositionLayouts;
1247 std::unordered_set<Layout*> m_boundSizeLayouts;
1254 bool m_enabled =
true;
1261 bool m_visible =
true;
1268 bool m_mouseHover =
false;
1269 bool m_mouseDown =
false;
1272 bool m_focused =
false;
1275 bool m_focusable =
true;
1278 std::weak_ptr<Widget> m_navWidgetUp;
1279 std::weak_ptr<Widget> m_navWidgetDown;
1280 std::weak_ptr<Widget> m_navWidgetRight;
1281 std::weak_ptr<Widget> m_navWidgetLeft;
1287 bool m_containerWidget =
false;
1293 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1296 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1299 Font m_inheritedFont;
1300 float m_inheritedOpacity = 1;
1304 AutoLayout m_autoLayout = AutoLayout::Manual;
1305 bool m_autoLayoutUpdateEnabled =
true;
1306 bool m_ignoreMouseEvents =
false;
1309 Font m_fontCached = Font::getGlobalFont();
1310 float m_opacityCached = 1;
1311 bool m_transparentTextureCached =
false;
1312 unsigned int m_textSizeCached = 0;
Base class for the Gui.
Definition BackendGui.hpp:47
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Container widget.
Definition Container.hpp:48
Type
List of available cursors.
Definition Cursor.hpp:50
Wrapper for durations.
Definition Duration.hpp:55
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:58
Class to store the position or size of a widget.
Definition Layout.hpp:323
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:102
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:986
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:884
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
ShowEffectType
Type of effect to show/hide widget.
Definition Animation.hpp:46
AutoLayout
Alignments for how to position a widget in its parent.
Definition Layout.hpp:85
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:48