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/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>
47#include <TGUI/extlibs/Aurora/SmartPtr/CopiedPtr.hpp>
48#include <TGUI/extlibs/Aurora/Tools/Downcast.hpp>
50#include <unordered_set>
69 class TGUI_API
Widget :
public std::enable_shared_from_this<Widget>
73 typedef std::shared_ptr<Widget>
Ptr;
74 typedef std::shared_ptr<const Widget>
ConstPtr;
84 Widget(
const char* typeName,
bool initRenderer);
179 setPosition({std::move(x), std::move(y)});
190 return m_position.getValue();
224 setSize({std::move(width), std::move(height)});
238 setSize({std::move(width), m_size.y});
252 setSize({m_size.x, std::move(height)});
263 return m_size.getValue();
383 setScale({scaleFactor, scaleFactor});
402 setScale({scaleFactor, scaleFactor}, origin);
413 return m_scaleFactors;
458 return m_rotationDeg;
648 m_userData = std::move(userData);
656 template <
typename T>
659 return AnyCast<T>(m_userData);
836 virtual void setParent(
Container* parent);
843 virtual bool updateTime(
Duration elapsedTime);
855 virtual void leftMousePressed(
Vector2f pos);
860 virtual void leftMouseReleased(
Vector2f pos);
865 virtual void rightMousePressed(
Vector2f pos);
870 virtual void rightMouseReleased(
Vector2f pos);
885 virtual void mouseMoved(
Vector2f pos);
895 virtual void textEntered(
char32_t key);
901 virtual bool mouseWheelScrolled(
float delta,
Vector2f pos);
906 virtual void mouseNoLongerOnWidget();
911 virtual void leftMouseButtonNoLongerDown();
916 virtual void rightMouseButtonNoLongerDown();
932 const Layout2d& getPositionLayout()
const
942 const Layout2d& getSizeLayout()
const
952 void bindPositionLayout(Layout* layout);
959 void unbindPositionLayout(Layout* layout);
966 void bindSizeLayout(Layout* layout);
973 void unbindSizeLayout(Layout* layout);
990 template <
typename W
idgetType>
991 std::shared_ptr<const WidgetType>
cast()
const
993 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1000 template <
typename W
idgetType>
1003 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1021 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>,
String>>;
1022 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1036 virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1042 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1063 void rendererChangedCallback(
const String& property);
1075 TGUI_DEPRECATED(
"onAnimationFinish was renamed to onShowEffectFinish")
SignalShowEffect onAnimationFinish = {
"AnimationFinished"};
1087 unsigned int m_textSize = 0;
1090 Optional<Vector2f> m_rotationOrigin;
1091 Optional<Vector2f> m_scaleOrigin;
1093 float m_rotationDeg = 0;
1097 Vector2f m_prevPosition;
1098 Vector2f m_prevSize;
1101 std::unordered_set<Layout*> m_boundPositionLayouts;
1102 std::unordered_set<Layout*> m_boundSizeLayouts;
1105 bool m_enabled =
true;
1108 bool m_visible =
true;
1111 Container* m_parent =
nullptr;
1112 GuiBase* m_parentGui =
nullptr;
1115 bool m_mouseHover =
false;
1116 bool m_mouseDown =
false;
1119 bool m_focused =
false;
1122 bool m_focusable =
true;
1125 Duration m_animationTimeElapsed;
1128 bool m_draggableWidget =
false;
1131 bool m_containerWidget =
false;
1134 Widget::Ptr m_toolTip =
nullptr;
1137 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1140 std::vector<std::shared_ptr<priv::Animation>> m_showAnimations;
1143 Font m_inheritedFont;
1144 float m_inheritedOpacity = 1;
1147 Font m_fontCached = Font::getGlobalFont();
1148 float m_opacityCached = 1;
1149 bool m_transparentTextureCached =
false;
1152 Cursor::Type m_mouseCursor = Cursor::Type::Arrow;
1154 std::function<void(
const String& property)> m_rendererChangedCallback = [
this](
const String& property){ rendererChangedCallback(property); };
1159 friend class Container;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Container widget.
Definition Container.hpp:47
Type
List of available cursors.
Definition Cursor.hpp:48
Wrapper for durations.
Definition Duration.hpp:52
Base class for the Gui.
Definition GuiBase.hpp:45
Class to store the position or size of a widget.
Definition Layout.hpp:262
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:50
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:669
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:58
Wrapper class to store strings.
Definition String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
ShowEffectType
Type of animation to show/hide widget.
Definition Animation.hpp:44
KeyPressed event parameters.
Definition Event.hpp:167
MouseButton
Mouse buttons.
Definition Event.hpp:148
States used for drawing.
Definition RenderStates.hpp:39