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;
647 m_userData = std::move(userData);
655 template <
typename DataType>
658 return AnyCast<DataType>(m_userData);
667 return m_userData.has_value();
936 virtual void setParent(
Container* parent);
942 virtual bool updateTime(
Duration elapsedTime);
948 void setAutoLayoutUpdateEnabled(
bool enabled);
968 virtual void leftMouseReleased(
Vector2f pos);
973 virtual void rightMousePressed(
Vector2f pos);
978 virtual void rightMouseReleased(
Vector2f pos);
988 virtual void mouseMoved(
Vector2f pos);
1009 virtual void textEntered(
char32_t key);
1025 virtual void mouseNoLongerOnWidget();
1030 virtual void leftMouseButtonNoLongerDown();
1035 virtual void rightMouseButtonNoLongerDown();
1049 TGUI_NODISCARD
const Layout2d& getPositionLayout()
const
1058 TGUI_NODISCARD
const Layout2d& getSizeLayout()
const
1067 void bindPositionLayout(Layout* layout);
1073 void unbindPositionLayout(Layout* layout);
1079 void bindSizeLayout(Layout* layout);
1085 void unbindSizeLayout(Layout* layout);
1100 template <
typename W
idgetType>
1101 TGUI_NODISCARD std::shared_ptr<const WidgetType>
cast()
const
1103 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1109 template <
typename W
idgetType>
1110 TGUI_NODISCARD std::shared_ptr<WidgetType>
cast()
1112 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1129 void rendererChangedCallback(
const String& property);
1135 virtual void updateTextSize();
1140 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>,
String>>;
1141 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1153 TGUI_NODISCARD
virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1158 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1214 unsigned int m_textSize = 0;
1217 Optional<Vector2f> m_rotationOrigin;
1218 Optional<Vector2f> m_scaleOrigin;
1220 float m_rotationDeg = 0;
1228 std::unordered_set<Layout*> m_boundPositionLayouts;
1229 std::unordered_set<Layout*> m_boundSizeLayouts;
1236 bool m_enabled =
true;
1243 bool m_visible =
true;
1250 bool m_mouseHover =
false;
1251 bool m_mouseDown =
false;
1254 bool m_focused =
false;
1257 bool m_focusable =
true;
1260 std::weak_ptr<Widget> m_navWidgetUp;
1261 std::weak_ptr<Widget> m_navWidgetDown;
1262 std::weak_ptr<Widget> m_navWidgetRight;
1263 std::weak_ptr<Widget> m_navWidgetLeft;
1269 bool m_containerWidget =
false;
1275 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1278 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1281 Font m_inheritedFont;
1282 float m_inheritedOpacity = 1;
1286 AutoLayout m_autoLayout = AutoLayout::Manual;
1287 bool m_autoLayoutUpdateEnabled =
true;
1288 bool m_ignoreMouseEvents =
false;
1291 Font m_fontCached = Font::getGlobalFont();
1292 float m_opacityCached = 1;
1293 bool m_transparentTextureCached =
false;
1294 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:313
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:101
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:61
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:884
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:84
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