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/CopiedPtr.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#include <unordered_set>
57 using tgui::CopiedPtr;
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);
117 Widget& operator=(const Widget&);
122 Widget& operator=(Widget&&) noexcept;
232 setSize({std::move(width), std::move(height)});
376 void setScale(Vector2f scaleFactors, Vector2f origin);
391 setScale({scaleFactor, scaleFactor});
407 setScale({scaleFactor, scaleFactor}, origin);
417 return m_scaleFactors;
458 return m_rotationDeg;
666 m_userData = std::move(userData);
674 template <
typename DataType>
677 return AnyCast<DataType>(m_userData);
686 return m_userData.has_value();
955 virtual void setParent(Container* parent);
961 virtual bool updateTime(
Duration elapsedTime);
967 void setAutoLayoutUpdateEnabled(
bool enabled);
987 virtual void leftMouseReleased(Vector2f pos);
992 virtual void rightMousePressed(Vector2f pos);
997 virtual void rightMouseReleased(Vector2f pos);
1007 virtual void mouseMoved(Vector2f pos);
1028 virtual void textEntered(
char32_t key);
1039 virtual bool scrolled(
float delta, Vector2f pos,
bool touch);
1044 virtual void mouseNoLongerOnWidget();
1049 virtual void leftMouseButtonNoLongerDown();
1054 virtual void rightMouseButtonNoLongerDown();
1062 TGUI_NODISCARD
virtual Widget::Ptr askToolTip(Vector2f mousePos);
1068 TGUI_NODISCARD
const Layout2d& getPositionLayout()
const
1077 TGUI_NODISCARD
const Layout2d& getSizeLayout()
const
1086 void bindPositionLayout(Layout* layout);
1092 void unbindPositionLayout(Layout* layout);
1098 void bindSizeLayout(Layout* layout);
1104 void unbindSizeLayout(Layout* layout);
1119 template <
typename W
idgetType>
1120 TGUI_NODISCARD std::shared_ptr<const WidgetType>
cast()
const
1122 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1128 template <
typename W
idgetType>
1129 TGUI_NODISCARD std::shared_ptr<WidgetType>
cast()
1131 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1148 void rendererChangedCallback(
const String& property);
1154 virtual void updateTextSize();
1159 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>,
String>>;
1160 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1172 TGUI_NODISCARD
virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1177 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1233 unsigned int m_textSize = 0;
1236 Optional<Vector2f> m_rotationOrigin;
1237 Optional<Vector2f> m_scaleOrigin;
1238 Vector2f m_scaleFactors = {1, 1};
1239 float m_rotationDeg = 0;
1243 Vector2f m_prevPosition;
1244 Vector2f m_prevSize;
1247 std::unordered_set<Layout*> m_boundPositionLayouts;
1248 std::unordered_set<Layout*> m_boundSizeLayouts;
1265 Container* m_parent =
nullptr;
1269 bool m_mouseHover =
false;
1270 bool m_mouseDown =
false;
1273 bool m_focused =
false;
1276 bool m_focusable =
true;
1279 std::weak_ptr<Widget> m_navWidgetUp;
1280 std::weak_ptr<Widget> m_navWidgetDown;
1281 std::weak_ptr<Widget> m_navWidgetRight;
1282 std::weak_ptr<Widget> m_navWidgetLeft;
1288 bool m_containerWidget =
false;
1297 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1300 Font m_inheritedFont;
1301 float m_inheritedOpacity = 1;
1306 bool m_autoLayoutUpdateEnabled =
true;
1307 bool m_ignoreMouseEvents =
false;
1311 float m_opacityCached = 1;
1312 bool m_transparentTextureCached =
false;
1313 unsigned int m_textSizeCached = 0;
1317 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:46
Copyable smart pointer template.
Definition CopiedPtr.hpp:52
Type
List of available cursors.
Definition Cursor.hpp:48
@ Arrow
Arrow cursor (default)
Definition Cursor.hpp:49
Wrapper for durations.
Definition Duration.hpp:53
Wrapper around the backend-specific font. All copies of the font will share the same internal font re...
Definition Font.hpp:56
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:321
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:984
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:882
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:36
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
SignalTyped< Vector2f > SignalVector2f
Signal with one "Vector2f" as optional unbound parameter.
Definition Signal.hpp:427
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:166
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:46