25#ifndef TGUI_WIDGET_HPP
26#define TGUI_WIDGET_HPP
30#include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
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>
50#include <unordered_set>
59 using tgui::CopiedPtr;
82 class TGUI_API Widget :
public std::enable_shared_from_this<Widget>
85 using Ptr = std::shared_ptr<Widget>;
86 using ConstPtr = std::shared_ptr<const Widget>;
95 Widget(
const char* typeName,
bool initRenderer);
115 Widget& operator=(const Widget&);
120 Widget& operator=(Widget&&) noexcept;
230 setSize({std::move(width), std::move(height)});
374 void setScale(Vector2f scaleFactors, Vector2f origin);
389 setScale({scaleFactor, scaleFactor});
405 setScale({scaleFactor, scaleFactor}, origin);
415 return m_scaleFactors;
456 return m_rotationDeg;
664 m_userData = std::move(userData);
672 template <
typename DataType>
675 return std::any_cast<DataType>(m_userData);
684 return m_userData.has_value();
953 virtual void setParent(Container* parent);
959 virtual bool updateTime(
Duration elapsedTime);
965 void setAutoLayoutUpdateEnabled(
bool enabled);
985 virtual void leftMouseReleased(Vector2f pos);
990 virtual void rightMousePressed(Vector2f pos);
995 virtual void rightMouseReleased(Vector2f pos);
1005 virtual void mouseMoved(Vector2f pos);
1026 virtual void textEntered(
char32_t key);
1037 virtual bool scrolled(
float delta, Vector2f pos,
bool touch);
1042 virtual void mouseNoLongerOnWidget();
1047 virtual void leftMouseButtonNoLongerDown();
1052 virtual void rightMouseButtonNoLongerDown();
1060 [[nodiscard]]
virtual Widget::Ptr askToolTip(Vector2f mousePos);
1066 [[nodiscard]]
const Layout2d& getPositionLayout()
const
1075 [[nodiscard]]
const Layout2d& getSizeLayout()
const
1084 void bindPositionLayout(Layout* layout);
1090 void unbindPositionLayout(Layout* layout);
1096 void bindSizeLayout(Layout* layout);
1102 void unbindSizeLayout(Layout* layout);
1117 template <
typename W
idgetType>
1118 [[nodiscard]] std::shared_ptr<const WidgetType>
cast()
const
1120 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1126 template <
typename W
idgetType>
1127 [[nodiscard]] std::shared_ptr<WidgetType>
cast()
1129 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1146 void rendererChangedCallback(
const String& property);
1152 virtual void updateTextSize();
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>>;
1170 [[nodiscard]]
virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1175 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1212 "ShowEffectFinished"};
1237 unsigned int m_textSize = 0;
1240 Optional<Vector2f> m_rotationOrigin;
1241 Optional<Vector2f> m_scaleOrigin;
1242 Vector2f m_scaleFactors = {1, 1};
1243 float m_rotationDeg = 0;
1247 Vector2f m_prevPosition;
1248 Vector2f m_prevSize;
1251 std::unordered_set<Layout*> m_boundPositionLayouts;
1252 std::unordered_set<Layout*> m_boundSizeLayouts;
1269 Container* m_parent =
nullptr;
1273 bool m_mouseHover =
false;
1274 bool m_mouseDown =
false;
1277 bool m_focused =
false;
1280 bool m_focusable =
true;
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;
1292 bool m_containerWidget =
false;
1301 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1304 Font m_inheritedFont;
1305 float m_inheritedOpacity = 1;
1310 bool m_autoLayoutUpdateEnabled =
true;
1311 bool m_ignoreMouseEvents =
false;
1315 float m_opacityCached = 1;
1316 bool m_transparentTextureCached =
false;
1317 unsigned int m_textSizeCached = 0;
1319 const std::map<String, std::shared_ptr<Theme>>* m_loadRuntimeThemesByAlias =
nullptr;
1324 friend class Container;
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
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