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/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>
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 using Ptr = std::shared_ptr<Widget>;
74 using ConstPtr = std::shared_ptr<const Widget>;
84 Widget(
const char* typeName,
bool initRenderer);
161 virtual
void setPosition(const
Layout2d& position);
178 setPosition({std::move(x), std::move(y)});
189 return m_position.getValue();
223 setSize({std::move(width), std::move(height)});
237 setSize({std::move(width), m_size.y});
251 setSize({m_size.x, std::move(height)});
262 return m_size.getValue();
382 setScale({scaleFactor, scaleFactor});
401 setScale({scaleFactor, scaleFactor}, origin);
412 return m_scaleFactors;
457 return m_rotationDeg;
665 m_userData = std::move(userData);
673 template <
typename T>
676 return AnyCast<T>(m_userData);
686 return m_userData.has_value();
874 virtual void setParent(
Container* parent);
881 virtual bool updateTime(
Duration elapsedTime);
893 virtual void leftMousePressed(
Vector2f pos);
898 virtual void leftMouseReleased(
Vector2f pos);
903 virtual void rightMousePressed(
Vector2f pos);
908 virtual void rightMouseReleased(
Vector2f pos);
923 virtual void mouseMoved(
Vector2f pos);
933 virtual void textEntered(
char32_t key);
939 virtual bool mouseWheelScrolled(
float delta,
Vector2f pos);
944 virtual void mouseNoLongerOnWidget();
949 virtual void leftMouseButtonNoLongerDown();
954 virtual void rightMouseButtonNoLongerDown();
970 const Layout2d& getPositionLayout()
const
980 const Layout2d& getSizeLayout()
const
990 void bindPositionLayout(Layout* layout);
997 void unbindPositionLayout(Layout* layout);
1004 void bindSizeLayout(Layout* layout);
1011 void unbindSizeLayout(Layout* layout);
1028 template <
typename W
idgetType>
1029 std::shared_ptr<const WidgetType>
cast()
const
1031 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1038 template <
typename W
idgetType>
1041 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1060 void rendererChangedCallback(
const String& property);
1067 virtual void updateTextSize();
1073 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>,
String>>;
1074 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1088 virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1094 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1144 unsigned int m_textSize = 0;
1147 Optional<Vector2f> m_rotationOrigin;
1148 Optional<Vector2f> m_scaleOrigin;
1150 float m_rotationDeg = 0;
1158 std::unordered_set<Layout*> m_boundPositionLayouts;
1159 std::unordered_set<Layout*> m_boundSizeLayouts;
1167 bool m_enabled =
true;
1174 bool m_visible =
true;
1181 bool m_mouseHover =
false;
1182 bool m_mouseDown =
false;
1185 bool m_focused =
false;
1188 bool m_focusable =
true;
1194 bool m_draggableWidget =
false;
1197 bool m_containerWidget =
false;
1203 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1206 std::vector<std::unique_ptr<priv::Animation>> m_showAnimations;
1209 Font m_inheritedFont;
1210 float m_inheritedOpacity = 1;
1213 Font m_fontCached = Font::getGlobalFont();
1214 float m_opacityCached = 1;
1215 bool m_transparentTextureCached =
false;
1216 unsigned int m_textSizeCached = 0;
Base class for the Gui.
Definition: BackendGui.hpp:45
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
Class to store the position or size of a widget.
Definition: Layout.hpp:284
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:880
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:770
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 effect 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
Shared data used in renderer classes.
Definition: WidgetRenderer.hpp:47